diff --git a/.circleci/config.yml b/.circleci/config.yml index 2b51fb518..3b4acc64d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,7 @@ version: 2.1 jobs: build: docker: - - image: cimg/ruby:3.2.8-node # Matches deployed Ruby version in CF + - image: cimg/ruby:3.2.10-node steps: - run: @@ -73,9 +73,12 @@ jobs: - run: name: Install gems + # Limit bundler to 2 parallel jobs to avoid CPU exhaustion on CircleCI Docker medium container + # Limit make tool for compiling native extensions to 2 jobs as well command: | bundle config set deployment true - bundle install + bundle config set jobs 2 + MAKE="make -j2" bundle install - save_cache: paths: @@ -96,7 +99,7 @@ jobs: test: docker: - - image: cimg/ruby:3.2.8-browsers # Matches deployed Ruby version in CF + - image: cimg/ruby:3.2.10-browsers environment: RAILS_ENV: test PGHOST: 127.0.0.1 diff --git a/.ruby-version b/.ruby-version index f092941a7..f15386a5d 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.8 +3.2.10 diff --git a/Gemfile b/Gemfile index c764d3cf0..0f2e37065 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '3.2.8' +ruby '3.2.10' # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem 'rails', '~> 8.0' diff --git a/Gemfile.lock b/Gemfile.lock index 93a3b557d..ea566967d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -228,14 +228,14 @@ GEM railties (>= 6.1.0) faker (3.5.2) i18n (>= 1.8.11, < 2) - faraday (2.13.4) + faraday (2.14.1) faraday-net_http (>= 2.0, < 3.5) json logger faraday-follow_redirects (0.3.0) faraday (>= 1, < 3) - faraday-net_http (3.4.1) - net-http (>= 0.5.0) + faraday-net_http (3.4.2) + net-http (~> 0.5) ffi (1.17.2-aarch64-linux-gnu) ffi (1.17.2-aarch64-linux-musl) ffi (1.17.2-arm-linux-gnu) @@ -289,7 +289,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.13.2) + json (2.18.1) json-jwt (1.17.0) activesupport (>= 4.2) aes_key_wrap @@ -345,8 +345,8 @@ GEM multi_json (1.17.0) multi_xml (0.8.1) bigdecimal (>= 3.1, < 5) - net-http (0.6.0) - uri + net-http (0.9.1) + uri (>= 0.11.1) net-imap (0.5.10) date net-protocol @@ -358,21 +358,21 @@ GEM net-protocol newrelic_rpm (9.21.0) nio4r (2.7.4) - nokogiri (1.18.9-aarch64-linux-gnu) + nokogiri (1.19.1-aarch64-linux-gnu) racc (~> 1.4) - nokogiri (1.18.9-aarch64-linux-musl) + nokogiri (1.19.1-aarch64-linux-musl) racc (~> 1.4) - nokogiri (1.18.9-arm-linux-gnu) + nokogiri (1.19.1-arm-linux-gnu) racc (~> 1.4) - nokogiri (1.18.9-arm-linux-musl) + nokogiri (1.19.1-arm-linux-musl) racc (~> 1.4) - nokogiri (1.18.9-arm64-darwin) + nokogiri (1.19.1-arm64-darwin) racc (~> 1.4) - nokogiri (1.18.9-x86_64-darwin) + nokogiri (1.19.1-x86_64-darwin) racc (~> 1.4) - nokogiri (1.18.9-x86_64-linux-gnu) + nokogiri (1.19.1-x86_64-linux-gnu) racc (~> 1.4) - nokogiri (1.18.9-x86_64-linux-musl) + nokogiri (1.19.1-x86_64-linux-musl) racc (~> 1.4) oauth2 (2.0.14) faraday (>= 0.17.3, < 4.0) @@ -425,7 +425,7 @@ GEM puma (6.6.1) nio4r (~> 2.0) racc (1.8.1) - rack (3.2.3) + rack (3.2.5) rack-attack (6.7.0) rack (>= 1.0, < 4) rack-cors (3.0.0) @@ -615,7 +615,7 @@ GEM unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) uniform_notifier (1.18.0) - uri (1.0.4) + uri (1.1.1) useragent (0.16.11) version_gem (1.1.9) virtus (2.0.0) @@ -718,7 +718,7 @@ DEPENDENCIES widget_renderer! RUBY VERSION - ruby 3.2.8 + ruby 3.2.10p266 BUNDLED WITH 2.7.1 diff --git a/app/controllers/admin/forms_controller.rb b/app/controllers/admin/forms_controller.rb index 2ea10a59f..472e8e5e2 100644 --- a/app/controllers/admin/forms_controller.rb +++ b/app/controllers/admin/forms_controller.rb @@ -51,7 +51,13 @@ def index params[:aasm_state] = @status # set the filter and dropdown by default end - @forms = Form.filtered_forms(@current_user, @status) + @forms = Form.my_forms(@current_user, @status) + @tags = @forms.collect(&:tag_list).flatten.uniq.sort + end + + def all + ensure_admin + @forms = Form.all.non_templates @tags = @forms.collect(&:tag_list).flatten.uniq.sort end diff --git a/app/models/form.rb b/app/models/form.rb index 52d59d001..7ee3328ab 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -40,10 +40,8 @@ class Form < ApplicationRecord mount_uploader :logo, LogoUploader - def self.filtered_forms(user, aasm_state) - if user.admin? - items = all - elsif user.organizational_form_approver? + def self.my_forms(user, aasm_state) + if user.organizational_form_approver? items = user.organization.forms else items = user.forms.order('organization_id ASC').order('name ASC') diff --git a/app/views/admin/forms/all.html.erb b/app/views/admin/forms/all.html.erb new file mode 100644 index 000000000..58ec7478c --- /dev/null +++ b/app/views/admin/forms/all.html.erb @@ -0,0 +1,106 @@ +<% content_for :navigation_title do %> + All Forms +<% end %> + + + + + + + + + + + + + + + + + <% @forms.each_with_index do |form, index| %> + + + + + + + + + + + + <% end %> + +
# + Organization name + + Name + + Questions + + Responses + + Form type + + Created at + + Status + Actions
+ <%= index + 1 %> + + <%= render "admin/organizations/badge", organization: form.organization %> + + <%= link_to form.name, admin_form_path(form) %> + + <%= form.questions_count %> + + <%= number_with_delimiter(form.response_count) %> + + <%= form.kind %> + + <%= form.created_at.to_date %> + + <%- if form.created? %> + + <%= form.aasm_state %> + + <%- elsif form.published? %> + + <%= form.aasm_state %> + + <% else %> + + <%= form.aasm_state %> + + <% end %> + +
    +
  • + + +
  • +
+
diff --git a/app/views/admin/forms/index.html.erb b/app/views/admin/forms/index.html.erb index fbf04f2de..7a5b291dc 100644 --- a/app/views/admin/forms/index.html.erb +++ b/app/views/admin/forms/index.html.erb @@ -22,12 +22,6 @@ # - <%- if admin_permissions? %> - - Organization name - - <% end %> Name @@ -57,11 +51,6 @@ <%= index + 1 %> - <%- if admin_permissions? %> - - <%= render "admin/organizations/badge", organization: form.organization %> - - <% end %> <%= link_to form.name, admin_form_path(form) %> diff --git a/app/views/admin/site/index.html.erb b/app/views/admin/site/index.html.erb index b5b50fb9c..83d78a719 100644 --- a/app/views/admin/site/index.html.erb +++ b/app/views/admin/site/index.html.erb @@ -38,6 +38,11 @@ Users +
  • + <%= link_to all_admin_forms_path do %> + All Forms + <% end %> +
  • Client Management @@ -53,11 +58,6 @@ Manage Sidekiq
  • -
  • - <%= link_to admin_record_retention_path do %> - Record Retention - <% end %> -
  • @@ -127,6 +127,11 @@ Integrations <% end %> +
  • + <%= link_to admin_record_retention_path do %> + Record Retention + <% end %> +
  • diff --git a/config/environments/development.rb b/config/environments/development.rb index f4e9d6d0d..f132b9fbd 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -3,7 +3,7 @@ Rails.application.configure do config.after_initialize do Bullet.enable = true - Bullet.alert = true + Bullet.alert = false Bullet.bullet_logger = true Bullet.console = true Bullet.rails_logger = true diff --git a/config/routes.rb b/config/routes.rb index 3e28f1e55..2fb61313e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -305,6 +305,7 @@ get 'events', to: 'forms#events', as: :events end collection do + get 'all', to: 'forms#all' post 'copy', to: 'forms#copy', as: :copy_id end resources :form_sections, except: %i[index show edit] do diff --git a/package-lock.json b/package-lock.json index f2f085460..c8c2797af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6314,9 +6314,9 @@ "license": "MIT" }, "node_modules/qs": { - "version": "6.14.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.1.tgz", - "integrity": "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==", + "version": "6.14.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.2.tgz", + "integrity": "sha512-V/yCWTTF7VJ9hIh18Ugr2zhJMP01MY7c5kh4J870L7imm6/DIzBsNLTXzMwUA3yZ5b/KBqLx8Kp3uRvd7xSe3Q==", "dev": true, "license": "BSD-3-Clause", "dependencies": { diff --git a/spec/features/admin/forms_spec.rb b/spec/features/admin/forms_spec.rb index c4d22280c..422c35792 100644 --- a/spec/features/admin/forms_spec.rb +++ b/spec/features/admin/forms_spec.rb @@ -7,42 +7,58 @@ 3.days.from_now end let(:organization) { FactoryBot.create(:organization) } + let(:another_organization) { FactoryBot.create(:organization, :another) } let(:admin) { FactoryBot.create(:user, :admin, organization:) } let(:user) { FactoryBot.create(:user, organization:) } context 'as Admin' do + let!(:user_forms) do + FactoryBot.create_list(:form, 3, organization:) do |form, i| + FactoryBot.create(:user_role, :form_manager, user: admin, form:) + if i == 0 + form.update(aasm_state: :archived) + end + end + end + let!(:form_in_my_org) { FactoryBot.create(:form, organization:) } + let!(:form_in_other_org) { FactoryBot.create(:form, organization: another_organization) } + before do login_as(admin) end describe '/admin/forms' do - let!(:form) { FactoryBot.create(:form, organization:) } - let!(:form2) { FactoryBot.create(:form, organization:) } - let!(:form3) { FactoryBot.create(:form, organization:) } - let!(:form4) { FactoryBot.create(:form, organization:, aasm_state: :submitted) } - let!(:form5) { FactoryBot.create(:form, organization:, aasm_state: :archived) } - before do visit admin_forms_path end - it 'displays 3 published forms' do + it 'displays 2 published form owned by the admin user' do + expect(find_all('.usa-table tbody tr').size).to eq(2) expect(page).to have_content('PUBLISHED') expect(page).to_not have_content('ARCHIVED') - expect(find_all('.usa-table tbody tr').size).to eq(3) end context 'use the visible buttons to filter for archived forms' do - it 'displays 1 archived form' do + it 'displays 1 archived form owned by the admin user' do within('.form-filter-buttons') do click_on('Archived') end + expect(find_all('.usa-table tbody tr').size).to eq(1) expect(page).to have_content('ARCHIVED') expect(page).to_not have_content('PUBLISHED') - expect(find_all('.usa-table tbody tr').size).to eq(1) end end end + + describe '/admin/forms/all' do + before do + visit all_admin_forms_path + end + + it 'displays all 5 forms' do + expect(find_all('.usa-table tbody tr').size).to eq(5) + end + end end context 'as Admin' do @@ -1432,6 +1448,18 @@ end end + context 'as non-admin user' do + before do + login_as(user) + end + + it 'cannot access All Forms page' do + visit all_admin_forms_path + expect(page.current_path).to eq(admin_root_path) + expect(page).to have_content('Authorization is Required') + end + end + context 'Form owner with Form Manager permissions Delete Action' do let!(:form) { FactoryBot.create(:form, :single_question, organization:) } let!(:user_role) { FactoryBot.create(:user_role, :form_manager, user: admin, form:) }