From 76ac52317a173d956a84d05cb75bc56b322822d7 Mon Sep 17 00:00:00 2001 From: phil-l-brockwell Date: Tue, 26 Nov 2024 15:42:50 +0000 Subject: [PATCH] Remove Add Collaborators form from Admin::FormAnswers::CompanyDetails --- .../form_answers/collaborators_controller.rb | 51 ------------ app/policies/form_answer_policy.rb | 4 - .../collaborators/_form.html.slim | 27 ------- .../collaborators/_search_results.html.slim | 13 --- .../form_answers/collaborators/create.js.slim | 6 -- .../form_answers/collaborators/search.js.slim | 6 -- .../company_details/_user_accounts.html.slim | 4 - app/views/admin/users/_form.html.slim | 10 --- config/routes.rb | 3 - .../admin/form_answers/collaborators_spec.rb | 81 ------------------- .../company_details_fulfilling_spec.rb | 2 +- 11 files changed, 1 insertion(+), 206 deletions(-) delete mode 100644 app/controllers/admin/form_answers/collaborators_controller.rb delete mode 100644 app/views/admin/form_answers/collaborators/_form.html.slim delete mode 100644 app/views/admin/form_answers/collaborators/_search_results.html.slim delete mode 100644 app/views/admin/form_answers/collaborators/create.js.slim delete mode 100644 app/views/admin/form_answers/collaborators/search.js.slim delete mode 100644 spec/features/admin/form_answers/collaborators_spec.rb diff --git a/app/controllers/admin/form_answers/collaborators_controller.rb b/app/controllers/admin/form_answers/collaborators_controller.rb deleted file mode 100644 index e78bf2536a..0000000000 --- a/app/controllers/admin/form_answers/collaborators_controller.rb +++ /dev/null @@ -1,51 +0,0 @@ -class Admin::FormAnswers::CollaboratorsController < Admin::BaseController - expose(:form_answer) do - FormAnswer.find(params[:form_answer_id]) - end - - expose(:user) do - User.find(params[:user_id]) - end - - expose(:search_users) do - AdminActions::SearchCollaboratorCandidates.new( - form_answer, - search_params, - ) - end - - expose(:add_collaborator_interactor) do - AdminActions::AddCollaborator.new( - form_answer, - user, - ) - end - - expose(:candidates) do - search_users.candidates - end - - def search - authorize form_answer, :can_add_collaborators_to_application? - - if search_users.valid? - search_users.run - end - end - - def create - authorize form_answer, :can_add_collaborators_to_application? - - add_collaborator_interactor.run - end - - private - - def search_params - if params[:search].present? - params.require(:search).permit( - :query, - ) - end - end -end diff --git a/app/policies/form_answer_policy.rb b/app/policies/form_answer_policy.rb index d64ea16eaf..4786e0e8f3 100644 --- a/app/policies/form_answer_policy.rb +++ b/app/policies/form_answer_policy.rb @@ -135,10 +135,6 @@ def can_download_original_pdf_of_application_before_deadline? record.pdf_version.present? end - def can_add_collaborators_to_application? - admin? - end - private def audit_certificate_available? diff --git a/app/views/admin/form_answers/collaborators/_form.html.slim b/app/views/admin/form_answers/collaborators/_form.html.slim deleted file mode 100644 index 3d9bd87279..0000000000 --- a/app/views/admin/form_answers/collaborators/_form.html.slim +++ /dev/null @@ -1,27 +0,0 @@ -= simple_form_for :search, - url: search_admin_form_answer_collaborators_url(resource), - remote: true, - method: :get, - as: nil, - html: { class: "admin-search-collaborators-form" } do |f| - - .form-container - label.form-label for="admin-search-collaborators-query" Add collaborator - - .alert.alert-danger.hidden.js-admin-search-collaborators-error-box role="alert" - - ul.list-unstyled.list-actions.hidden.js-admin-search-collaborators-results-box - - .form-block - .row - .col-md-12 - = f.input :query, - as: :string, - label: false, - input_html: { class: "form-control", id: "admin-search-collaborators-query" }, - wrapper_html: { class: 'pull-left col-md-10 admin-search-collaborators-query' }, - placeholder: "Type part of email, first name or last name" - - .text-right - = f.submit "Search", class: "btn btn-primary pull-right" - .clear diff --git a/app/views/admin/form_answers/collaborators/_search_results.html.slim b/app/views/admin/form_answers/collaborators/_search_results.html.slim deleted file mode 100644 index f3e35fdf55..0000000000 --- a/app/views/admin/form_answers/collaborators/_search_results.html.slim +++ /dev/null @@ -1,13 +0,0 @@ -- if candidates.present? - - candidates.each do |user| - li id="collaborator_candidate_#{user.id}" - = link_to "#{user.full_name} (#{user.email})", edit_admin_user_path(user) - - if user.can_be_added_to_collaborators_to_another_account? - = link_to "Add", admin_form_answer_collaborators_url(form_answer_id: form_answer.id, user_id: user), - remote: true, - method: :post, - class: "pull-right btn btn-default" - - else - br - i.cant_add_to_collaborators_message - | can not be added as linked with another account! diff --git a/app/views/admin/form_answers/collaborators/create.js.slim b/app/views/admin/form_answers/collaborators/create.js.slim deleted file mode 100644 index e236acd38f..0000000000 --- a/app/views/admin/form_answers/collaborators/create.js.slim +++ /dev/null @@ -1,6 +0,0 @@ -- if add_collaborator_interactor.success? - | $('.js-collaborators-list').replaceWith("#{j render('list', resource: form_answer)}"); - | $(".js-admin-search-collaborators-error-box").addClass("hidden"); - | $("#collaborator_candidate_#{user.id}").remove(); -- else - | $(".js-admin-search-collaborators-error-box").text("#{add_collaborator_interactor.errors}").removeClass("hidden"); diff --git a/app/views/admin/form_answers/collaborators/search.js.slim b/app/views/admin/form_answers/collaborators/search.js.slim deleted file mode 100644 index 267e91b09c..0000000000 --- a/app/views/admin/form_answers/collaborators/search.js.slim +++ /dev/null @@ -1,6 +0,0 @@ -- if search_users.valid? - | $('.js-admin-search-collaborators-results-box').html("#{j render("search_results")}").removeClass("hidden"); - | $(".js-admin-search-collaborators-error-box").addClass("hidden"); -- else - | $('.js-admin-search-collaborators-results-box').addClass("hidden"); - | $(".js-admin-search-collaborators-error-box").text("#{search_users.error.html_safe}").removeClass("hidden"); diff --git a/app/views/admin/form_answers/company_details/_user_accounts.html.slim b/app/views/admin/form_answers/company_details/_user_accounts.html.slim index bfd565ab09..84a4de18ca 100644 --- a/app/views/admin/form_answers/company_details/_user_accounts.html.slim +++ b/app/views/admin/form_answers/company_details/_user_accounts.html.slim @@ -1,8 +1,4 @@ .form-group .form-container label.form-label User accounts - = render "admin/form_answers/collaborators/list" - - - if policy(resource).can_add_collaborators_to_application? - = render "admin/form_answers/collaborators/form" diff --git a/app/views/admin/users/_form.html.slim b/app/views/admin/users/_form.html.slim index d527262e36..78d3ec1dcd 100644 --- a/app/views/admin/users/_form.html.slim +++ b/app/views/admin/users/_form.html.slim @@ -28,16 +28,6 @@ .panel-body = render "fields_contact_preferences", f: f - - unless action_name == "new" - .panel.panel-default[data-controller="element-focus"] - .panel-heading id="section-collaborators-header" - h2.panel-title - a.collapsed data-toggle="collapse" data-parent="#user-form-panel" href="#section-collaborators" aria-expanded="false" aria-controls="section-collaborators" data-element-focus-target="reveal" - ' Collaborators - #section-collaborators.section-collaborators.panel-collapse.collapse[aria-labelledby="section-collaborators-header" data-element-scroll-target="accordion"] - .panel-body - = render "fields_collaborators", f: f, resource: resource - br .clearfix .pull-right diff --git a/config/routes.rb b/config/routes.rb index dee13d7daf..644fbbbf6b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -351,9 +351,6 @@ resources :case_summaries, only: [:index] resources :draft_notes, only: [:create, :update] resources :review_corp_responsibility, only: [:create] - resources :collaborators, only: [:create], module: "form_answers" do - get :search, on: :collection - end end resource :settings, only: [:show] do diff --git a/spec/features/admin/form_answers/collaborators_spec.rb b/spec/features/admin/form_answers/collaborators_spec.rb deleted file mode 100644 index e4a2e59521..0000000000 --- a/spec/features/admin/form_answers/collaborators_spec.rb +++ /dev/null @@ -1,81 +0,0 @@ -require "rails_helper" - -describe "Collaborators", ' -As a an Admin -I want to be able to add collaborators to any account -So that they can collaborate applications -' do - include ActiveJob::TestHelper - - let!(:admin) { create(:admin) } - - let!(:form_answer) do - create :form_answer, - :innovation, - :submitted - end - - let!(:account) do - form_answer.account - end - - before do - login_admin admin - visit admin_form_answer_path(form_answer) - end - - describe "Add new Collaborator" do - describe "Invalid Attempts", js: true do - describe "Attempt to add person, which is already associated with another account which has application" do - let!(:user_associated_with_another_account) do - create :user, - :completed_profile, - first_name: "Applicant with account", - role: "account_admin" - end - - let!(:another_form_answer) do - create :form_answer, - :innovation, - :submitted, - user: user_associated_with_another_account - end - - it "can't add" do - find("a[aria-controls='section-company-details']").click - - within(".admin-search-collaborators-form") do - fill_in "search[query]", with: "plicant with acc" - first("input[type='submit']").click - - within(".js-admin-search-collaborators-results-box") do - expect_to_see(user_associated_with_another_account.first_name) - expect_to_see("can not be added as linked with another account!") - expect(page).to have_no_link("Add") - end - end - end - end - end - - describe "Success Add to Collaborators", js: true do - let(:email) { generate(:email) } - let!(:user) { create(:user, email: email) } - - it "should add user to collaborators with regular role" do - find("a[aria-controls='section-company-details']").click - - within(".admin-search-collaborators-form") do - fill_in "search[query]", with: email.to_s[2..-2] - first("input[type='submit']").click - - within(".js-admin-search-collaborators-results-box") do - expect_to_see(user.email) - expect_to_see_no("can not be added as linked with another account!") - expect(page).to have_link("Add") - end - end - end - end - end -end diff --git a/spec/features/admin/form_answers/company_details_fulfilling_spec.rb b/spec/features/admin/form_answers/company_details_fulfilling_spec.rb index 42de7cfff3..0b5027257e 100644 --- a/spec/features/admin/form_answers/company_details_fulfilling_spec.rb +++ b/spec/features/admin/form_answers/company_details_fulfilling_spec.rb @@ -32,7 +32,7 @@ it "can see the edit buttons" do within ".company-details-forms" do - expect(page).to have_selector("input[type='submit']", count: 13) + expect(page).to have_selector("input[type='submit']", count: 12) end end end