Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-pagination-to-proprietor-account-show-tables #1798

Merged
merged 3 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/proprietor/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def show
add_breadcrumb t(:'hyrax.controls.home'), root_path
add_breadcrumb t(:'hyrax.admin.sidebar.accounts'), proprietor_accounts_path
add_breadcrumb @account.tenant, edit_proprietor_account_path(@account)

admin_page = params[:user_superadmin_page]
@current_superusers = User.where(email: @account.admin_emails).page(admin_page).per(5) if @account.admin_emails
@current_nonadmin_users = User.order('email').page(params[:user_page]).per(5)
end

# GET /accounts/new
Expand Down
17 changes: 14 additions & 3 deletions app/views/proprietor/accounts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<div class="panel-body">
<div class="tab-content clearfix">
<div class="tab-pane active" id="current-admins-tab">
<% if @current_superusers.present? %>
<table class="table table-striped">
<thead>
<th><%= t('.current_admins.email') %></th>
Expand All @@ -70,7 +71,7 @@
<td></td>
</tr>
<% else %>
<% @account.admin_emails.each do |email| %>
<% @current_superusers.each do |email| %>
<tr>
<td><%= email %></td>
<td>
Expand All @@ -92,15 +93,21 @@
<% end %>
</tbody>
</table>
<%= page_entries_info(@current_superusers) %><br />
<%= paginate(@current_superusers, param_name: :user_superadmin_page, params: {anchor: 'current-admins-tab'}) %>
<% else %>
<p>There are currently no admins assigned to this tenant. Please add some.</p>
<% end %>
</div>
<div class="tab-pane" id="all-users-tab">
<% if @current_nonadmin_users.present? %>
<table class="table table-striped">
<thead>
<th><%= t('.current_admins.email') %></th>
<th><%= t('.current_admins.actions') %></th>
</thead>
<tbody>
<% User.all.each do |user| %>
<% @current_nonadmin_users.each do |user| %>
<tr>
<td><%= user.email %></td>
<td>
Expand All @@ -118,7 +125,11 @@
<% end %>
</tbody>
</table>

<%= page_entries_info(@current_nonadmin_users) %><br />
<%= paginate(@current_nonadmin_users, param_name: :user_page, params: {anchor: 'all-users-tab'}) %>
<% else %>
<p>There are currently no users added to this tenant. Please add some.</p>
<% end %>
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/proprietor/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

describe "GET #show" do
it "assigns the requested account as @account" do
allow_any_instance_of(Account).to receive(:admin_emails).and_return([user.email])
get :show, params: { id: account.to_param }
expect(assigns(:account)).to eq(account)
end
Expand Down Expand Up @@ -158,6 +159,7 @@

describe "GET #show" do
it "assigns the requested account as @account" do
allow_any_instance_of(Account).to receive(:admin_emails).and_return([user.email])
get :show, params: { id: account.to_param }
expect(assigns(:account)).to eq(account)
end
Expand Down
17 changes: 8 additions & 9 deletions spec/views/proprietor/accounts/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

RSpec.describe "proprietor/accounts/show", type: :view do
let(:account) { FactoryBot.create(:account) }
let(:admin1) { build(:user) }
let(:admin2) { build(:user) }
let(:superadmin1) { FactoryBot.create(:superadmin, email: '[email protected]') }
let(:superadmin2) { FactoryBot.create(:superadmin, email: '[email protected]') }

before do
allow(Apartment::Tenant).to receive(:switch).with(account.tenant) do |&block|
Expand All @@ -30,21 +30,20 @@
render
end

it 'displays "No administrators exist"' do
expect(rendered).to have_content('No administrators exist')
it 'displays "No administrators message"' do
expect(rendered).to have_content('There are currently no admins assigned to this tenant. Please add some.')
end
end

context 'with admin users' do
before do
allow(account).to receive(:admin_emails).and_return([admin1.email, admin2.email])
allow(account).to receive(:admin_emails).and_return([superadmin1.email, superadmin2.email])
render
end

it 'displays each user email and a remove button' do
expect(rendered).to have_content(admin1.email)
expect(rendered).to have_content(admin2.email)
expect(rendered).to have_css("input[class='btn btn-danger'][value='Remove']")
it 'displays each admin email' do
expect(rendered).to match(/[email protected]/)
expect(rendered).to match(/[email protected]/)
end
end
end