Skip to content

Commit 032395d

Browse files
authored
Add route /admin/forms/all (#1983)
1 parent 6039f10 commit 032395d

7 files changed

Lines changed: 164 additions & 31 deletions

File tree

app/controllers/admin/forms_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ def index
5151
params[:aasm_state] = @status # set the filter and dropdown by default
5252
end
5353

54-
@forms = Form.filtered_forms(@current_user, @status)
54+
@forms = Form.my_forms(@current_user, @status)
55+
@tags = @forms.collect(&:tag_list).flatten.uniq.sort
56+
end
57+
58+
def all
59+
ensure_admin
60+
@forms = Form.all.non_templates
5561
@tags = @forms.collect(&:tag_list).flatten.uniq.sort
5662
end
5763

app/models/form.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ class Form < ApplicationRecord
4040

4141
mount_uploader :logo, LogoUploader
4242

43-
def self.filtered_forms(user, aasm_state)
44-
if user.admin?
45-
items = all
46-
elsif user.organizational_form_approver?
43+
def self.my_forms(user, aasm_state)
44+
if user.organizational_form_approver?
4745
items = user.organization.forms
4846
else
4947
items = user.forms.order('organization_id ASC').order('name ASC')

app/views/admin/forms/all.html.erb

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<% content_for :navigation_title do %>
2+
All Forms
3+
<% end %>
4+
5+
<table class="usa-table usa-table--sticky-header width-full font-sans-2xs">
6+
<thead class="font-sans-3xs z-top">
7+
<tr>
8+
<th>#</th>
9+
<th data-sortable scope="col"
10+
data-type="organization-name">
11+
Organization name
12+
</th>
13+
<th data-sortable scope="col"
14+
data-type="name">
15+
Name
16+
</th>
17+
<th data-sortable scope="col">
18+
Questions
19+
</th>
20+
<th data-sortable scope="col">
21+
Responses
22+
</th>
23+
<th data-sortable scope="col">
24+
Form type
25+
</th>
26+
<th data-sortable scope="col">
27+
Created at
28+
</th>
29+
<th data-sortable scope="col"
30+
data-type="status">
31+
Status
32+
</th>
33+
<th>Actions</th>
34+
</tr>
35+
</thead>
36+
<tbody>
37+
<% @forms.each_with_index do |form, index| %>
38+
<tr>
39+
<td class="text-center">
40+
<%= index + 1 %>
41+
</td>
42+
<td>
43+
<%= render "admin/organizations/badge", organization: form.organization %>
44+
</td>
45+
<td>
46+
<%= link_to form.name, admin_form_path(form) %>
47+
</td>
48+
<td>
49+
<%= form.questions_count %>
50+
</td>
51+
<td data-sort-value="<%= form.response_count %>">
52+
<%= number_with_delimiter(form.response_count) %>
53+
</td>
54+
<td>
55+
<%= form.kind %>
56+
</td>
57+
<td data-sort-value="<%= form.created_at.to_i %>">
58+
<%= form.created_at.to_date %>
59+
</td>
60+
<td>
61+
<%- if form.created? %>
62+
<span class="usa-tag bg-cyan">
63+
<%= form.aasm_state %>
64+
</span>
65+
<%- elsif form.published? %>
66+
<span class="usa-tag bg-green">
67+
<%= form.aasm_state %>
68+
</span>
69+
<% else %>
70+
<span class="usa-tag">
71+
<%= form.aasm_state %>
72+
</span>
73+
<% end %>
74+
</td>
75+
<td>
76+
<ul class="usa-nav__primary float-menu usa-accordion">
77+
<li class="usa-nav__primary-item">
78+
<button
79+
class="usa-accordion__button usa-nav__link usa-current"
80+
aria-expanded="false"
81+
aria-controls="extended-nav-section-one-<%= form.short_uuid %>"
82+
aria-label="Show actions for <%= form.name %>">
83+
<span class="usa-sr-only">Show actions for <%= form.name %></span>
84+
</button>
85+
<ul id="extended-nav-section-one-<%= form.short_uuid %>" class="usa-nav__submenu" hidden="">
86+
<li class="usa-nav__submenu-item">
87+
<%= link_to edit_admin_form_path(form) do %>
88+
Edit
89+
<% end %>
90+
</li>
91+
<li class="usa-nav__submenu-item">
92+
<%= link_to 'Preview', example_admin_form_path(form), target: "_blank", rel: "noopener" %>
93+
</li>
94+
<li class="usa-nav__submenu-item">
95+
<%= link_to copy_admin_form_path(form), method: :post, data: { confirm: 'Are you sure?' } do %>
96+
Copy
97+
<% end %>
98+
</li>
99+
</ul>
100+
</li>
101+
</ul>
102+
</td>
103+
</tr>
104+
<% end %>
105+
</tbody>
106+
</table>

app/views/admin/forms/index.html.erb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
<thead class="font-sans-3xs z-top">
2323
<tr>
2424
<th>#</th>
25-
<%- if admin_permissions? %>
26-
<th data-sortable scope="col"
27-
data-type="organization-name">
28-
Organization name
29-
</th>
30-
<% end %>
3125
<th data-sortable scope="col"
3226
data-type="name">
3327
Name
@@ -57,11 +51,6 @@
5751
<td class="text-center">
5852
<%= index + 1 %>
5953
</td>
60-
<%- if admin_permissions? %>
61-
<td>
62-
<%= render "admin/organizations/badge", organization: form.organization %>
63-
</td>
64-
<% end %>
6554
<td>
6655
<%= link_to form.name, admin_form_path(form) %>
6756
</td>

app/views/admin/site/index.html.erb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
<span>Users</span>
3939
</a>
4040
</li>
41+
<li>
42+
<%= link_to all_admin_forms_path do %>
43+
All Forms
44+
<% end %>
45+
</li>
4146
<li>
4247
<a href="/admin/management">
4348
<span>Client Management</span>
@@ -53,11 +58,6 @@
5358
<span>Manage Sidekiq</span>
5459
</a>
5560
</li>
56-
<li>
57-
<%= link_to admin_record_retention_path do %>
58-
Record Retention
59-
<% end %>
60-
</li>
6161
</ul>
6262
</div>
6363
<div class="grid-col-3">
@@ -127,6 +127,11 @@
127127
Integrations
128128
<% end %>
129129
</li>
130+
<li>
131+
<%= link_to admin_record_retention_path do %>
132+
Record Retention
133+
<% end %>
134+
</li>
130135
</ul>
131136
</div>
132137
</div>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
get 'events', to: 'forms#events', as: :events
306306
end
307307
collection do
308+
get 'all', to: 'forms#all'
308309
post 'copy', to: 'forms#copy', as: :copy_id
309310
end
310311
resources :form_sections, except: %i[index show edit] do

spec/features/admin/forms_spec.rb

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,58 @@
77
3.days.from_now
88
end
99
let(:organization) { FactoryBot.create(:organization) }
10+
let(:another_organization) { FactoryBot.create(:organization, :another) }
1011
let(:admin) { FactoryBot.create(:user, :admin, organization:) }
1112
let(:user) { FactoryBot.create(:user, organization:) }
1213

1314
context 'as Admin' do
15+
let!(:user_forms) do
16+
FactoryBot.create_list(:form, 3, organization:) do |form, i|
17+
FactoryBot.create(:user_role, :form_manager, user: admin, form:)
18+
if i == 0
19+
form.update(aasm_state: :archived)
20+
end
21+
end
22+
end
23+
let!(:form_in_my_org) { FactoryBot.create(:form, organization:) }
24+
let!(:form_in_other_org) { FactoryBot.create(:form, organization: another_organization) }
25+
1426
before do
1527
login_as(admin)
1628
end
1729

1830
describe '/admin/forms' do
19-
let!(:form) { FactoryBot.create(:form, organization:) }
20-
let!(:form2) { FactoryBot.create(:form, organization:) }
21-
let!(:form3) { FactoryBot.create(:form, organization:) }
22-
let!(:form4) { FactoryBot.create(:form, organization:, aasm_state: :submitted) }
23-
let!(:form5) { FactoryBot.create(:form, organization:, aasm_state: :archived) }
24-
2531
before do
2632
visit admin_forms_path
2733
end
2834

29-
it 'displays 3 published forms' do
35+
it 'displays 2 published form owned by the admin user' do
36+
expect(find_all('.usa-table tbody tr').size).to eq(2)
3037
expect(page).to have_content('PUBLISHED')
3138
expect(page).to_not have_content('ARCHIVED')
32-
expect(find_all('.usa-table tbody tr').size).to eq(3)
3339
end
3440

3541
context 'use the visible buttons to filter for archived forms' do
36-
it 'displays 1 archived form' do
42+
it 'displays 1 archived form owned by the admin user' do
3743
within('.form-filter-buttons') do
3844
click_on('Archived')
3945
end
46+
expect(find_all('.usa-table tbody tr').size).to eq(1)
4047
expect(page).to have_content('ARCHIVED')
4148
expect(page).to_not have_content('PUBLISHED')
42-
expect(find_all('.usa-table tbody tr').size).to eq(1)
4349
end
4450
end
4551
end
52+
53+
describe '/admin/forms/all' do
54+
before do
55+
visit all_admin_forms_path
56+
end
57+
58+
it 'displays all 5 forms' do
59+
expect(find_all('.usa-table tbody tr').size).to eq(5)
60+
end
61+
end
4662
end
4763

4864
context 'as Admin' do
@@ -1432,6 +1448,18 @@
14321448
end
14331449
end
14341450

1451+
context 'as non-admin user' do
1452+
before do
1453+
login_as(user)
1454+
end
1455+
1456+
it 'cannot access All Forms page' do
1457+
visit all_admin_forms_path
1458+
expect(page.current_path).to eq(admin_root_path)
1459+
expect(page).to have_content('Authorization is Required')
1460+
end
1461+
end
1462+
14351463
context 'Form owner with Form Manager permissions Delete Action' do
14361464
let!(:form) { FactoryBot.create(:form, :single_question, organization:) }
14371465
let!(:user_role) { FactoryBot.create(:user_role, :form_manager, user: admin, form:) }

0 commit comments

Comments
 (0)