Skip to content

Commit 0bc5113

Browse files
authored
Merge pull request #2434 from DMPRoadmap/issue_2346
Issue 2346 - Create a super admin view of the Plans report
2 parents 47ab448 + e49e27e commit 0bc5113

6 files changed

Lines changed: 41 additions & 9 deletions

File tree

app/controllers/org_admin/plans_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def index
1414
.where('users.org_id = ? AND plans.feedback_requested is TRUE AND roles.active is TRUE',
1515
current_user.org_id).pluck(:plan_id)
1616
@feedback_plans = Plan.where(id: feedback_ids).reject{|p| p.nil?}
17-
@plans = current_user.org.plans.page(1)
17+
@super_admin = current_user.can_super_admin?
18+
@plans = @super_admin ? Plan.all.page(1) : current_user.org.plans.page(1)
1819
end
1920

2021
# GET org_admin/plans/:id/feedback_complete

app/controllers/paginable/plans_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ def org_admin
4242
unless current_user.present? && current_user.can_org_admin?
4343
raise Pundit::NotAuthorizedError
4444
end
45+
#check if current user if super_admin
46+
@super_admin = current_user.can_super_admin?
47+
plans = @super_admin ? Plan.all : current_user.org.plans
48+
plans = plans.joins(:template, roles: [user: :org]).where(Role.creator_condition)
49+
4550
paginable_renderise(
4651
partial: "org_admin",
47-
scope: current_user.org.plans,
52+
scope: plans,
53+
view_all: !current_user.can_super_admin?,
4854
query_params: { sort_field: 'plans.updated_at', sort_direction: :desc }
4955
)
5056
end

app/models/plan.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,11 @@ class Plan < ActiveRecord::Base
164164

165165
scope :search, lambda { |term|
166166
search_pattern = "%#{term}%"
167-
joins(:template)
167+
joins(:template, roles: [user: :org])
168+
.where(Role.creator_condition)
168169
.where("lower(plans.title) LIKE lower(:search_pattern)
170+
OR lower(orgs.name) LIKE lower (:search_pattern)
171+
OR lower(orgs.abbreviation) LIKE lower (:search_pattern)
169172
OR lower(templates.title) LIKE lower(:search_pattern)
170173
OR lower(plans.principal_investigator) LIKE lower(:search_pattern)
171174
OR lower(plans.principal_investigator_identifier) LIKE lower(:search_pattern)",

app/views/org_admin/plans/index.html.erb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@
3434
</div>
3535
</div>
3636
<% end %>
37-
<% if @plans.length > 0 %>
38-
<%= link_to sanitize(_('Download plans <em class="sr-only">(new window)</em><span class="new-window-popup-info">%{open_in_new_window_text}</span>') %
37+
<% if @plans.length > 0 %>
38+
<% unless @super_admin %>
39+
<%= link_to sanitize(_('Download plans <em class="sr-only">(new window)</em><span class="new-window-popup-info">%{open_in_new_window_text}</span>') %
3940
{ open_in_new_window_text: _('Opens in new window') },
4041
tags: %w{ span em }),
4142
org_admin_download_plans_path(format: :csv),
4243
target: '_blank',
4344
class: 'btn btn-default pull-right has-new-window-popup-info' %>
45+
<% end %>
4446
<%= paginable_renderise(
4547
partial: '/paginable/plans/org_admin',
4648
controller: 'paginable/plans',
4749
action: 'org_admin',
4850
scope: @plans,
51+
view_all: !current_user.can_super_admin?,
4952
query_params: { sort_field: 'plans.updated_at', sort_direction: :desc }) %>
5053
<% end %>
5154
</div>

app/views/paginable/plans/_org_admin.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<tr>
55
<th scope="col"><%= _('Project Title') %>&nbsp;<%= paginable_sort_link('plans.title') %></th>
66
<th scope="col"><%= _('Template') %>&nbsp;<%= paginable_sort_link('templates.title') %></th>
7-
<th scope="col"><%= _('Organisation') %></th>
7+
<th scope="col"><%= _('Organisation') %>&nbsp;<%= paginable_sort_link('orgs.name') %></th>
88
<th scope="col"><%= _('Owner') %></th>
99
<th scope="col" class="date-column"><%= _('Updated') %>&nbsp;<%= paginable_sort_link('plans.updated_at') %></th>
1010
<th scope="col"><%= _('Visibility') %></th>

spec/models/plan_spec.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@
457457

458458
context "when Plan title matches term" do
459459

460-
let!(:plan) { create(:plan, title: "foolike title") }
460+
let!(:plan) { create(:plan, :creator, title: "foolike title") }
461461

462462
it { is_expected.to include(plan) }
463463

@@ -467,20 +467,39 @@
467467

468468
let!(:template) { create(:template, title: "foolike title") }
469469

470-
let!(:plan) { create(:plan, template: template) }
470+
let!(:plan) { create(:plan, :creator, template: template) }
471471

472472
it { is_expected.to include(plan) }
473473

474474
end
475475

476+
context "when Organisation name matches term" do
477+
478+
let!(:plan) { create(:plan, :creator, description: "foolike desc") }
479+
480+
let!(:org) { create(:org, name: 'foolike name') }
481+
482+
before do
483+
user = plan.owner
484+
user.org = org
485+
user.save
486+
end
487+
488+
it "returns organisation name" do
489+
expect(subject).to include(plan)
490+
end
491+
492+
end
493+
476494
context "when neither title matches term" do
477495

478-
let!(:plan) { create(:plan, description: "foolike desc") }
496+
let!(:plan) { create(:plan, :creator, description: "foolike desc") }
479497

480498
it { is_expected.not_to include(plan) }
481499

482500
end
483501

502+
484503
end
485504

486505
describe "#answer" do

0 commit comments

Comments
 (0)