From 15dafa15fa7aa77b92756ff40195efe1ea25abcc Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 11 Dec 2024 10:21:18 -0800 Subject: [PATCH 01/21] remove broadcast as it throws redis missing error in production; add dependent destroy on org --- app/models/adopter_application.rb | 4 +--- app/models/organization.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/models/adopter_application.rb b/app/models/adopter_application.rb index 29b1a5a2c..d25a37cbb 100644 --- a/app/models/adopter_application.rb +++ b/app/models/adopter_application.rb @@ -32,9 +32,7 @@ class AdopterApplication < ApplicationRecord has_one :person, through: :form_submission validates :pet_id, uniqueness: {scope: :form_submission_id} - - broadcasts_refreshes - + enum :status, [:awaiting_review, :under_review, :adoption_pending, diff --git a/app/models/organization.rb b/app/models/organization.rb index 5b2cb270e..4511f3b90 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -25,18 +25,18 @@ class Organization < ApplicationRecord # Rolify resource resourcify - has_many :users - has_many :pets - has_many :default_pet_tasks + has_many :users, dependent: :destroy + has_many :pets, dependent: :destroy + has_many :default_pet_tasks, dependent: :destroy has_many :forms, class_name: "CustomForm::Form", dependent: :destroy - has_many :faqs + has_many :faqs, dependent: :destroy has_many :form_answers, dependent: :destroy - has_many :people + has_many :people, dependent: :destroy has_one :form_submission, dependent: :destroy has_one :custom_page, dependent: :destroy - has_many :locations, as: :locatable + has_many :locations, as: :locatable, dependent: :destroy accepts_nested_attributes_for :locations validates :phone_number, phone: {possible: true, allow_blank: true} From 2c8d684c6cd9efdc94a91e8b7b9b99e966654dc6 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 11 Dec 2024 10:31:34 -0800 Subject: [PATCH 02/21] Update associations and add migration to move adopter applications to belong to person --- app/models/adopter_application.rb | 31 +++++++++---------- app/models/form_submission.rb | 1 - app/models/person.rb | 4 +-- ...dopter_applications_to_belong_to_person.rb | 12 +++++++ db/schema.rb | 9 +++--- 5 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 db/migrate/20241211182208_update_adopter_applications_to_belong_to_person.rb diff --git a/app/models/adopter_application.rb b/app/models/adopter_application.rb index d25a37cbb..b9ac458d6 100644 --- a/app/models/adopter_application.rb +++ b/app/models/adopter_application.rb @@ -2,34 +2,31 @@ # # Table name: adopter_applications # -# id :bigint not null, primary key -# notes :text -# profile_show :boolean default(TRUE) -# status :integer default("awaiting_review") -# created_at :datetime not null -# updated_at :datetime not null -# form_submission_id :bigint not null -# organization_id :bigint not null -# pet_id :bigint not null +# id :bigint not null, primary key +# notes :text +# profile_show :boolean default(TRUE) +# status :integer default("awaiting_review") +# created_at :datetime not null +# updated_at :datetime not null +# organization_id :bigint not null +# person_id :bigint not null +# pet_id :bigint not null # # Indexes # -# index_adopter_applications_on_form_submission_id (form_submission_id) -# index_adopter_applications_on_organization_id (organization_id) -# index_adopter_applications_on_pet_id (pet_id) -# index_adopter_applications_on_pet_id_and_form_submission_id (pet_id,form_submission_id) UNIQUE +# index_adopter_applications_on_organization_id (organization_id) +# index_adopter_applications_on_person_id (person_id) +# index_adopter_applications_on_pet_id (pet_id) # # Foreign Keys # -# fk_rails_... (form_submission_id => form_submissions.id) +# fk_rails_... (person_id => people.id) # fk_rails_... (pet_id => pets.id) # class AdopterApplication < ApplicationRecord acts_as_tenant(:organization) belongs_to :pet, touch: true - belongs_to :form_submission - - has_one :person, through: :form_submission + belongs_to :person validates :pet_id, uniqueness: {scope: :form_submission_id} diff --git a/app/models/form_submission.rb b/app/models/form_submission.rb index 3c0db0f6a..b141ec681 100644 --- a/app/models/form_submission.rb +++ b/app/models/form_submission.rb @@ -30,7 +30,6 @@ class FormSubmission < ApplicationRecord acts_as_tenant(:organization) belongs_to :person - has_many :adopter_applications has_many :form_answers, dependent: :destroy delegate :user, to: :person diff --git a/app/models/person.rb b/app/models/person.rb index 49feb4742..841eb854c 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -29,10 +29,10 @@ class Person < ApplicationRecord has_one :latest_form_submission, -> { order(created_at: :desc) }, class_name: "FormSubmission" has_many :form_submissions, dependent: :destroy has_many :form_answers, through: :form_submissions - has_many :adopter_applications, through: :form_submissions + has_many :adopter_applications, dependent: :destroy has_many :likes, dependent: :destroy has_many :liked_pets, through: :likes, source: :pet - has_one :location, as: :locatable + has_one :location, as: :locatable, dependent: :destroy accepts_nested_attributes_for :location, reject_if: ->(attributes) { attributes["city_town"].blank? } has_many :matches # , dependent: :destroy diff --git a/db/migrate/20241211182208_update_adopter_applications_to_belong_to_person.rb b/db/migrate/20241211182208_update_adopter_applications_to_belong_to_person.rb new file mode 100644 index 000000000..8238bf032 --- /dev/null +++ b/db/migrate/20241211182208_update_adopter_applications_to_belong_to_person.rb @@ -0,0 +1,12 @@ +class UpdateAdopterApplicationsToBelongToPerson < ActiveRecord::Migration[7.2] + def change + safety_assured do + remove_foreign_key :adopter_applications, :form_submissions + remove_index :adopter_applications, column: :form_submission_id + remove_index :adopter_applications, name: "index_adopter_applications_on_pet_id_and_form_submission_id" + remove_column :adopter_applications, :form_submission_id, :bigint + + add_reference :adopter_applications, :person, null: false, foreign_key: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6122777e9..e99dad621 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_11_27_052542) do +ActiveRecord::Schema[7.2].define(version: 2024_12_11_182208) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -50,10 +50,9 @@ t.text "notes" t.boolean "profile_show", default: true t.bigint "organization_id", null: false - t.bigint "form_submission_id", null: false - t.index ["form_submission_id"], name: "index_adopter_applications_on_form_submission_id" + t.bigint "person_id", null: false t.index ["organization_id"], name: "index_adopter_applications_on_organization_id" - t.index ["pet_id", "form_submission_id"], name: "index_adopter_applications_on_pet_id_and_form_submission_id", unique: true + t.index ["person_id"], name: "index_adopter_applications_on_person_id" t.index ["pet_id"], name: "index_adopter_applications_on_pet_id" end @@ -300,7 +299,7 @@ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" - add_foreign_key "adopter_applications", "form_submissions" + add_foreign_key "adopter_applications", "people" add_foreign_key "adopter_applications", "pets" add_foreign_key "custom_pages", "organizations" add_foreign_key "default_pet_tasks", "organizations" From 08d5ca11387e597517627b6ea635f18f7e45159f Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 11 Dec 2024 14:13:31 -0800 Subject: [PATCH 03/21] Update AdopterApplication to use Person; update seeds for new associations --- app/models/adopter_application.rb | 4 ++-- db/seeds/01_alta.rb | 11 ++++++++--- db/seeds/02_baja.rb | 11 ++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/models/adopter_application.rb b/app/models/adopter_application.rb index b9ac458d6..d0693ba1d 100644 --- a/app/models/adopter_application.rb +++ b/app/models/adopter_application.rb @@ -28,7 +28,7 @@ class AdopterApplication < ApplicationRecord belongs_to :pet, touch: true belongs_to :person - validates :pet_id, uniqueness: {scope: :form_submission_id} + validates :pet_id, uniqueness: {scope: :person_id} enum :status, [:awaiting_review, :under_review, @@ -54,7 +54,7 @@ def self.retire_applications(pet_id:) end def applicant_name - form_submission.person.full_name.to_s + person.full_name.to_s end def withdraw diff --git a/db/seeds/01_alta.rb b/db/seeds/01_alta.rb index 4af9cd248..4006dbd22 100644 --- a/db/seeds/01_alta.rb +++ b/db/seeds/01_alta.rb @@ -229,6 +229,11 @@ end end + FormSubmission.create( + person: @adopter_one, + organization: @organization + ) + FormSubmission.all.each do |submission| 5.times do FormAnswer.create!( @@ -244,7 +249,7 @@ match_application = AdopterApplication.create!( pet_id: Pet.first.id, - form_submission_id: @adopter_one.form_submissions.first.id, + person_id: @adopter_one.id, status: :successful_applicant ) @@ -312,13 +317,13 @@ profile_show: true, status: rand(0..4), pet: Pet.all.sample, - form_submission: FormSubmission.all.sample + person: [@adopter_one, @adopter_two, @adopter_three].sample ) # Prevent duplicate adopter applications. redo if AdopterApplication.where( pet_id: adopter_application.pet_id, - form_submission_id: adopter_application.form_submission_id + person_id: adopter_application.person_id ).exists? if adopter_application.valid? diff --git a/db/seeds/02_baja.rb b/db/seeds/02_baja.rb index 2eb3c449f..fe4f8c97e 100644 --- a/db/seeds/02_baja.rb +++ b/db/seeds/02_baja.rb @@ -181,6 +181,11 @@ end end + FormSubmission.create( + person: @adopter_one, + organization: @organization + ) + FormSubmission.all.each do |submission| 5.times do FormAnswer.create!( @@ -196,7 +201,7 @@ match_application = AdopterApplication.create!( pet_id: Pet.first.id, - form_submission_id: @adopter_one.form_submissions.first.id, + person: @adopter_one, status: :successful_applicant ) @@ -263,13 +268,13 @@ profile_show: true, status: rand(0..4), pet: Pet.all.sample, - form_submission: FormSubmission.all.sample + person: [@adopter_one, @adopter_two, @adopter_three].sample ) # Prevent duplicate adopter applications. redo if AdopterApplication.where( pet_id: adopter_application.pet_id, - form_submission_id: adopter_application.form_submission_id + person_id: adopter_application.person_id ).exists? if adopter_application.valid? From b5bc2ddcb9b68321b7615552dcc2143d754e8561 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 11 Dec 2024 15:54:54 -0800 Subject: [PATCH 04/21] refactor models, controllers, views, tests to handle new associations --- .../adoptable_pets_controller.rb | 6 +- ...adoption_application_reviews_controller.rb | 2 +- app/models/match.rb | 2 +- app/policies/adopter_application_policy.rb | 10 +-- .../adoptable_pets/show.html.erb | 4 +- .../_application_cards.html.erb | 2 - .../_applications_table.html.erb | 5 +- .../adopter_applications/index.html.erb | 6 +- .../_application_create_button.html.erb | 2 +- .../adopter_applications_controller_test.rb | 8 +-- ...ion_application_reviews_controller_test.rb | 28 ++++---- test/factories/adopter_applications.rb | 5 +- .../adoption_application_reviews_test.rb | 17 +++-- test/models/adopter_application_test.rb | 13 ++-- test/models/form_submission_test.rb | 1 - .../adopter_application_policy_test.rb | 68 +++---------------- .../adopter_application_policy_test.rb | 10 +-- test/system/adoption_creation_test.rb | 3 +- test/system/adoption_fosterer_test.rb | 2 +- 19 files changed, 65 insertions(+), 129 deletions(-) diff --git a/app/controllers/organizations/adoptable_pets_controller.rb b/app/controllers/organizations/adoptable_pets_controller.rb index 734f54810..3e9530726 100644 --- a/app/controllers/organizations/adoptable_pets_controller.rb +++ b/app/controllers/organizations/adoptable_pets_controller.rb @@ -30,14 +30,14 @@ def index def show @adoptable_pet_info = CustomPage.first&.adoptable_pet_info - if current_user&.latest_form_submission + if current_user @adoption_application = AdopterApplication.find_by( pet_id: @pet.id, - form_submission_id: current_user.latest_form_submission.id + person_id: current_user.person.id ) || @pet.adopter_applications.build( - form_submission: current_user.latest_form_submission + person: current_user.person ) end end diff --git a/app/controllers/organizations/staff/adoption_application_reviews_controller.rb b/app/controllers/organizations/staff/adoption_application_reviews_controller.rb index 9344d54da..3fde30dee 100644 --- a/app/controllers/organizations/staff/adoption_application_reviews_controller.rb +++ b/app/controllers/organizations/staff/adoption_application_reviews_controller.rb @@ -10,7 +10,7 @@ def index context: {organization: Current.organization} @q = authorized_scope( - Pet.includes(adopter_applications: [form_submission: [:person]]) + Pet.includes(adopter_applications: [:person]) .where.not(adopter_applications: {id: nil}).references(:person) ).ransack(params[:q]) @pets_with_applications = @q.result.includes(:adopter_applications) diff --git a/app/models/match.rb b/app/models/match.rb index b36894d0a..45625b345 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -115,7 +115,7 @@ def belongs_to_same_organization_as_pet end def adopter_application - AdopterApplication.includes(:form_submission).find_by(pet:, form_submission: {person:}) + AdopterApplication.find_by(pet: pet, person: person) end ransacker :status do diff --git a/app/policies/adopter_application_policy.rb b/app/policies/adopter_application_policy.rb index 9d911d504..1fdfa8547 100644 --- a/app/policies/adopter_application_policy.rb +++ b/app/policies/adopter_application_policy.rb @@ -1,13 +1,9 @@ class AdopterApplicationPolicy < ApplicationPolicy authorize :pet, optional: true - - pre_check :verify_form_submission!, except: %i[index?] pre_check :verify_pet_appliable!, only: %i[create?] relation_scope do |relation| - return relation.none unless user.latest_form_submission - - relation.where(form_submission_id: user.latest_form_submission.id) + relation.where(person_id: user.person.id) end def update? @@ -34,10 +30,6 @@ def already_applied? end end - def verify_form_submission! - deny! unless user.latest_form_submission.present? - end - def verify_pet_appliable! deny! if pet.application_paused deny! if already_applied? diff --git a/app/views/organizations/adoptable_pets/show.html.erb b/app/views/organizations/adoptable_pets/show.html.erb index 1a36db36e..be807cd85 100644 --- a/app/views/organizations/adoptable_pets/show.html.erb +++ b/app/views/organizations/adoptable_pets/show.html.erb @@ -137,13 +137,13 @@

<%= t('.in_love') %>

<%= form_with model: [:adopter_fosterer, @adoption_application] do |form| %> <%= form.hidden_field :pet_id, value: @adoption_application.pet_id %> - <%= form.hidden_field :form_submission_id, value: @adoption_application.form_submission_id %> + <%= form.hidden_field :person_id, value: @adoption_application.person_id %> <%= form.submit t(".apply_to_adopt"), class: "btn btn-primary", data: {turbo: false} %> <% end %> - <% elsif AdopterApplication.exists?(form_submission: current_user.latest_form_submission, pet: @pet) %> + <% elsif AdopterApplication.exists?(person: current_user.person, pet: @pet) %>

<%= "#{t('organizations.adoptable_pets.show.application_status')} #{@adoption_application.human_enum_name(:status) || t('.status.default')}" %> diff --git a/app/views/organizations/adopter_fosterer/adopter_applications/_application_cards.html.erb b/app/views/organizations/adopter_fosterer/adopter_applications/_application_cards.html.erb index f542d0a58..35df4cc50 100644 --- a/app/views/organizations/adopter_fosterer/adopter_applications/_application_cards.html.erb +++ b/app/views/organizations/adopter_fosterer/adopter_applications/_application_cards.html.erb @@ -1,5 +1,3 @@ -<%= turbo_refreshes_with method: :morph, scroll: :preserve %> - <% pet = application.pet %>
<%= link_to image_tag(pet.images.attached? ? pet.images.first : 'coming_soon.jpg', class: 'card-img-top pet-card'), adoptable_pet_path(pet) %> diff --git a/app/views/organizations/adopter_fosterer/adopter_applications/_applications_table.html.erb b/app/views/organizations/adopter_fosterer/adopter_applications/_applications_table.html.erb index ec86d4b90..09846d66a 100644 --- a/app/views/organizations/adopter_fosterer/adopter_applications/_applications_table.html.erb +++ b/app/views/organizations/adopter_fosterer/adopter_applications/_applications_table.html.erb @@ -1,5 +1,3 @@ -<%= turbo_refreshes_with method: :morph, scroll: :preserve %> -
@@ -15,7 +13,6 @@ <% if applications.present? %> <% applications.each do |app| %> - <%= turbo_stream_from app %> <% pet = app.pet %> - <%end%> + <% end %>
@@ -57,7 +54,7 @@ <%= t("dashboard.applications.no_applications")%>
diff --git a/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb b/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb index 7083b2a96..64f9a0269 100644 --- a/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb +++ b/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb @@ -7,9 +7,9 @@ <%= render partial: "applications_table", locals: { applications: @applications} %>
-
- <%= render partial:"application_cards", collection: @applications, as: :application %> -
+ + <%#= render partial:"application_cards", collection: @applications, as: :application %> +

<% end %> <% end %> diff --git a/app/views/organizations/staff/pets/tabs/partials/_application_create_button.html.erb b/app/views/organizations/staff/pets/tabs/partials/_application_create_button.html.erb index 26f0a9716..e2f28c868 100644 --- a/app/views/organizations/staff/pets/tabs/partials/_application_create_button.html.erb +++ b/app/views/organizations/staff/pets/tabs/partials/_application_create_button.html.erb @@ -3,7 +3,7 @@ <%= button_to "New Adoption", staff_matches_path, method: :post, params: {match: {pet_id: app.pet_id, - person_id: app.form_submission.person_id, + person_id: app.person_id, match_type: :adoption} }, class: "btn btn-outline-primary", diff --git a/test/controllers/organizations/adopter_fosterer/adopter_applications_controller_test.rb b/test/controllers/organizations/adopter_fosterer/adopter_applications_controller_test.rb index fd8fc2d7d..22ef1c950 100644 --- a/test/controllers/organizations/adopter_fosterer/adopter_applications_controller_test.rb +++ b/test/controllers/organizations/adopter_fosterer/adopter_applications_controller_test.rb @@ -7,7 +7,6 @@ class Organizations::AdopterFosterer::AdopterApplicationsControllerTest < Action setup do @user = create(:adopter) - @form_submission = @user.person.latest_form_submission sign_in @user end @@ -29,8 +28,7 @@ class Organizations::AdopterFosterer::AdopterApplicationsControllerTest < Action end should "count the total number of applications" do - form_submission = create(:form_submission, person: @user.person) - create_list(:adopter_application, 2, form_submission: form_submission) + create_list(:adopter_application, 2, person: @user.person) get adopter_fosterer_dashboard_index_path @@ -48,7 +46,7 @@ class Organizations::AdopterFosterer::AdopterApplicationsControllerTest < Action @pet = create(:pet) @params = {adopter_application: { pet_id: @pet.id, - form_submission_id: @form_submission.id + person_id: @user.person.id }} end @@ -65,7 +63,7 @@ class Organizations::AdopterFosterer::AdopterApplicationsControllerTest < Action context "#update" do setup do - @adopter_application = create(:adopter_application, form_submission: @form_submission) + @adopter_application = create(:adopter_application, person: @user.person) @params = {adopter_application: { status: "withdrawn" }} diff --git a/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb b/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb index 5a54bc1d3..f0fde0f80 100644 --- a/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb +++ b/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb @@ -6,12 +6,14 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis include ActionPolicy::TestHelper setup do + @user = create(:admin) + @adopter = create(:adopter) @organization = ActsAsTenant.current_tenant @form_submission = create(:form_submission) - @adopter_application = create(:adopter_application, form_submission: @form_submission) + @adopter_application = create(:adopter_application, person: @adopter.person) + - user = create(:admin) - sign_in user + sign_in @user end context "index" do @@ -86,6 +88,7 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis context "Filtering adoption applications" do setup do + @adopter = create(:adopter) @user = create(:admin) sign_in @user end @@ -98,8 +101,8 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis setup do pet1 = create(:pet, name: "Pango") pet2 = create(:pet, name: "Tycho") - create(:adopter_application, pet: pet1, form_submission: create(:form_submission)) - create(:adopter_application, pet: pet2, form_submission: create(:form_submission)) + create(:adopter_application, pet: pet1, person: @adopter.person) + create(:adopter_application, pet: pet2, person: @adopter.person) end should "return applications for a specific pet name" do @@ -113,11 +116,9 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis context "by applicant name" do setup do @pet = create(:pet) - create(:form_submission, person: create(:person, first_name: "David", last_name: "Attenborough")) - create(:form_submission, person: create(:person, first_name: "Jane", last_name: "Goodall")) - create(:adopter_application, pet: @pet, form_submission: create(:form_submission)) - create(:adopter_application, pet: @pet, form_submission: create(:form_submission)) + create(:adopter_application, pet: @pet, person: create(:person, first_name: "David", last_name: "Attenborough")) + create(:adopter_application, pet: @pet, person: create(:person, first_name: "Jane", last_name: "Goodall")) end should "return applications for a specific applicant name" do @@ -130,9 +131,8 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis context "Filtering by application status" do setup do - @pet = create(:pet) - @application_under_review = create(:adopter_application, pet: @pet, status: :under_review, form_submission: create(:form_submission)) - @application_awaiting_review = create(:adopter_application, pet: @pet, status: :awaiting_review, form_submission: create(:form_submission)) + @application_under_review = create(:adopter_application, status: :under_review, person: @adopter.person) + @application_awaiting_review = create(:adopter_application, status: :awaiting_review, person: @adopter.person) end should "return pets only with applications of the specified status" do @@ -150,9 +150,9 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis sign_in @user @adopter = create(:adopter) - @form_submission = @adopter.person.latest_form_submission + @form_submission = create(:form_submission, person: @adopter.person) @form_answers = create_list(:form_answer, 3, form_submission: @form_submission) - @adopter_application = create(:adopter_application, form_submission: @form_submission) + @adopter_application = create(:adopter_application, person: @adopter.person) end context "#show" do diff --git a/test/factories/adopter_applications.rb b/test/factories/adopter_applications.rb index 9075d83dd..4b96bf434 100644 --- a/test/factories/adopter_applications.rb +++ b/test/factories/adopter_applications.rb @@ -3,14 +3,13 @@ notes { Faker::Lorem.paragraph } profile_show { true } status { 1 } + association :person + association :pet transient do user { nil } end - pet - form_submission - trait :adoption_pending do status { 2 } end diff --git a/test/integration/organizations/staff/adoption_application_reviews_test.rb b/test/integration/organizations/staff/adoption_application_reviews_test.rb index 99f5e7556..3d00d4ce7 100644 --- a/test/integration/organizations/staff/adoption_application_reviews_test.rb +++ b/test/integration/organizations/staff/adoption_application_reviews_test.rb @@ -2,20 +2,19 @@ class Organizations::Staff::AdoptionApplicationReviewsTest < ActionDispatch::IntegrationTest setup do - form_submission = create(:form_submission) - @awaiting_review_app = create(:adopter_application, status: :awaiting_review, form_submission: form_submission) - @under_review_app = create(:adopter_application, status: :under_review, form_submission: form_submission) - create(:adopter_application, :adoption_pending, form_submission: form_submission) - create(:adopter_application, :withdrawn, form_submission: form_submission) - create(:adopter_application, status: :successful_applicant, form_submission: form_submission) - create(:adopter_application, status: :adoption_made, form_submission: form_submission) + @adopter = create(:adopter) + @awaiting_review_app = create(:adopter_application, status: :awaiting_review) + @under_review_app = create(:adopter_application, status: :under_review) + create(:adopter_application, :adoption_pending) + create(:adopter_application, :withdrawn) + create(:adopter_application, status: :successful_applicant) + create(:adopter_application, status: :adoption_made) @custom_page = create(:custom_page, organization: ActsAsTenant.current_tenant) # Setup for show view tests - @adopter = create(:adopter) @form_submission = @adopter.person.latest_form_submission @form_answers = create_list(:form_answer, 3, form_submission: @form_submission) - @adopter_application = create(:adopter_application, form_submission: @form_submission) + @adopter_application = create(:adopter_application, person: @adopter.person) end context "non-staff" do diff --git a/test/models/adopter_application_test.rb b/test/models/adopter_application_test.rb index 3416f2eb8..053b6a365 100644 --- a/test/models/adopter_application_test.rb +++ b/test/models/adopter_application_test.rb @@ -2,29 +2,28 @@ class AdopterApplicationTest < ActiveSupport::TestCase setup do - @form_submission = create(:form_submission) - @application = create(:adopter_application, form_submission: @form_submission) + @user = create(:adopter) + @application = create(:adopter_application, person: @user.person) end context "associations" do should belong_to(:pet).touch(true) - should belong_to(:form_submission) + should belong_to(:person) end context "validations" do - should validate_uniqueness_of(:pet_id).scoped_to(:form_submission_id) + should validate_uniqueness_of(:pet_id).scoped_to(:person_id) .with_message("Only one application per pet per person is allowed") end context "self.retire_applications" do context "when some applications match pet_id and some do not" do setup do - @form_submissions = create_list(:form_submission, 3) @selected_applications = 3.times.map do |i| - create(:adopter_application, pet_id: @application.pet_id, form_submission: @form_submissions[i]) + create(:adopter_application, pet_id: @application.pet_id) end @unselected_applications = Array.new(2) { - create(:adopter_application, form_submission: @form_submission) + create(:adopter_application, person: @user.person) } end diff --git a/test/models/form_submission_test.rb b/test/models/form_submission_test.rb index 9cde1fcec..d75c802f1 100644 --- a/test/models/form_submission_test.rb +++ b/test/models/form_submission_test.rb @@ -3,7 +3,6 @@ class FormSubmissionTest < ActiveSupport::TestCase context "associations" do should belong_to(:person) - should have_many(:adopter_applications) should have_many(:form_answers).dependent(:destroy) end end diff --git a/test/policies/adopter_application_policy_test.rb b/test/policies/adopter_application_policy_test.rb index 53283e1ea..866f12bff 100644 --- a/test/policies/adopter_application_policy_test.rb +++ b/test/policies/adopter_application_policy_test.rb @@ -16,29 +16,18 @@ class AdopterApplicationPolicyTest < ActiveSupport::TestCase } end - context "when user is adopter without form submission" do + context "when user is adopter" do setup do @user = create(:adopter) end - should "return empty array" do - assert_equal([], @scope.call) - end - end - - context "when user is adopter with form submission" do - setup do - @user = create(:adopter) - @form_submission = create(:form_submission, person: @user.person) - end - context "when there are applications that do not belong to user" do setup do @user_applications = [ - create(:adopter_application, form_submission: @form_submission), - create(:adopter_application, form_submission: @form_submission) + create(:adopter_application, person: @user.person), + create(:adopter_application, person: @user.person) ] - @other_application = create(:adopter_application, form_submission: create(:form_submission)) + @other_application = create(:adopter_application) end should "return only user's applications" do @@ -49,8 +38,7 @@ class AdopterApplicationPolicyTest < ActiveSupport::TestCase context "when user has no applications" do setup do - @form_submission = create(:form_submission, person_id: @user.person_id) - @other_application = create(:adopter_application, form_submission: create(:form_submission)) + @other_application = create(:adopter_application) end should "return empty array" do @@ -78,20 +66,9 @@ class AdopterApplicationPolicyTest < ActiveSupport::TestCase end end - context "when user has no form submission" do - setup do - @user = create(:user) - end - - should "return false" do - assert_equal false, @action.call - end - end - - context "when user is adopter with form submission" do + context "when user is adopter" do setup do @user = create(:adopter) - create(:form_submission, person: @user.person) end should "return true" do @@ -130,20 +107,9 @@ class AdopterApplicationPolicyTest < ActiveSupport::TestCase end end - context "when user has no form submission" do - setup do - @user = create(:user) - end - - should "return false" do - assert_equal false, @action.call - end - end - - context "when user is adopter with form submission" do + context "when user is adopter" do setup do @user = create(:adopter) - @form_submission = create(:form_submission, person: @user.person) end context "when pet application is paused" do @@ -163,9 +129,7 @@ class AdopterApplicationPolicyTest < ActiveSupport::TestCase context "when user already has an existing application for the pet" do setup do - _existing_app = create(:adopter_application, - pet: @pet, - form_submission: @form_submission) + _existing_app = create(:adopter_application, pet: @pet, person: @user.person) end should "return false" do @@ -194,8 +158,8 @@ class AdopterApplicationPolicyTest < ActiveSupport::TestCase context "existing record action" do setup do - form_submission = create(:form_submission) - @adopter_application = create(:adopter_application, form_submission:) + @adopter = create(:adopter) + @adopter_application = create(:adopter_application, person: @adopter.person) @policy = -> { AdopterApplicationPolicy.new(@adopter_application, user: @user) } @@ -257,18 +221,6 @@ class AdopterApplicationPolicyTest < ActiveSupport::TestCase end end end - - context "when form submission belongs to user" do - setup do - @user = create(:adopter) - form_submission = create(:form_submission, person: @user.person) - @adopter_application = create(:adopter_application, form_submission:) - end - - should "return true" do - assert_equal true, @action.call - end - end end end end diff --git a/test/policies/organizations/adopter_application_policy_test.rb b/test/policies/organizations/adopter_application_policy_test.rb index fff221c18..b3ba47ca4 100644 --- a/test/policies/organizations/adopter_application_policy_test.rb +++ b/test/policies/organizations/adopter_application_policy_test.rb @@ -113,8 +113,8 @@ class Organizations::AdopterApplicationPolicyTest < ActiveSupport::TestCase context "existing record action" do setup do - @form_submission = create(:form_submission) - @adopter_application = create(:adopter_application, form_submission: @form_submission) + @user = create(:adopter) + @adopter_application = create(:adopter_application, person: @user.person) @policy = -> { Organizations::AdopterApplicationPolicy.new( @adopter_application, user: @user @@ -166,7 +166,8 @@ class Organizations::AdopterApplicationPolicyTest < ActiveSupport::TestCase setup do ActsAsTenant.with_tenant(create(:organization)) do @form_submission = create(:form_submission) - @adopter_application = create(:adopter_application, form_submission: @form_submission) + @adopter = create(:adopter) + @adopter_application = create(:adopter_application, person: @adopter.person) end end @@ -201,7 +202,8 @@ class Organizations::AdopterApplicationPolicyTest < ActiveSupport::TestCase setup do ActsAsTenant.with_tenant(create(:organization)) do @form_submission = create(:form_submission) - @adopter_application = create(:adopter_application, form_submission: @form_submission) + @adopter = create(:adopter) + @adopter_application = create(:adopter_application, person: @adopter.person) end end diff --git a/test/system/adoption_creation_test.rb b/test/system/adoption_creation_test.rb index 599bcd7be..f262f815f 100644 --- a/test/system/adoption_creation_test.rb +++ b/test/system/adoption_creation_test.rb @@ -3,8 +3,9 @@ class AdoptionCreationTest < ApplicationSystemTestCase setup do user = create(:admin) + adopter = create(:adopter) @pet = create(:pet) - create(:adopter_application, :successful_applicant, pet_id: @pet.id, form_submission: create(:form_submission)) + create(:adopter_application, :successful_applicant, pet_id: @pet.id, person: adopter.person) sign_in user end diff --git a/test/system/adoption_fosterer_test.rb b/test/system/adoption_fosterer_test.rb index 9ee9802c2..682a789f9 100644 --- a/test/system/adoption_fosterer_test.rb +++ b/test/system/adoption_fosterer_test.rb @@ -5,7 +5,7 @@ class AdoptionFostererTest < ApplicationSystemTestCase @user = create(:adopter_fosterer) @pet = create(:pet) - create(:adopter_application, pet: @pet, form_submission: @user.person.form_submissions.create) + create(:adopter_application, pet: @pet, person: @user.person) sign_in @user end From 263a92f68f6116e06ad67ed7427eac94c63d6632 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 12 Dec 2024 10:51:06 -0800 Subject: [PATCH 05/21] remove creation of form submission on adopter sign up --- app/controllers/registrations_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index a803016f0..1c2def2ab 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -16,7 +16,6 @@ def create super do |resource| if resource.persisted? resource.add_role(:adopter, Current.organization) - resource.person.form_submissions.create end end end From 1c21e178056e839fb78bc5d0c6fbc43465c2f22a Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 12 Dec 2024 14:43:02 -0800 Subject: [PATCH 06/21] implemenet routs, controllers, views and policies for staff to review form submissions and form answers; --- ...adoption_application_reviews_controller.rb | 7 ----- .../staff/form_answers_controller.rb | 24 +++++++++++++++ .../staff/form_submissions_controller.rb | 27 +++++++++++++++++ app/models/concerns/authorizable.rb | 1 + .../organizations/form_submission_policy.rb | 12 ++++++++ .../adopter_applications/index.html.erb | 6 ++-- .../show.html.erb | 29 ------------------ .../staff/form_answers/index.html.erb | 16 ++++++++++ .../_form_submissions_table.html.erb | 26 ++++++++++++++++ .../staff/form_submissions/index.html.erb | 30 +++++++++++++++++++ .../_application_info_table_row.html.erb | 2 +- app/views/shared/_empty_state.html.erb | 5 ++++ config/breadcrumbs.rb | 4 +++ config/locales/en.yml | 3 ++ config/routes.rb | 12 +++++++- 15 files changed, 163 insertions(+), 41 deletions(-) create mode 100644 app/controllers/organizations/staff/form_answers_controller.rb create mode 100644 app/controllers/organizations/staff/form_submissions_controller.rb create mode 100644 app/policies/organizations/form_submission_policy.rb delete mode 100644 app/views/organizations/staff/adoption_application_reviews/show.html.erb create mode 100644 app/views/organizations/staff/form_answers/index.html.erb create mode 100644 app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb create mode 100644 app/views/organizations/staff/form_submissions/index.html.erb create mode 100644 app/views/shared/_empty_state.html.erb diff --git a/app/controllers/organizations/staff/adoption_application_reviews_controller.rb b/app/controllers/organizations/staff/adoption_application_reviews_controller.rb index 3fde30dee..bf3cc7092 100644 --- a/app/controllers/organizations/staff/adoption_application_reviews_controller.rb +++ b/app/controllers/organizations/staff/adoption_application_reviews_controller.rb @@ -41,13 +41,6 @@ def update end end - def show - authorize! AdopterApplication, - context: {organization: Current.organization} - - @form_answers = @application.person.latest_form_submission.form_answers - end - private def application_params diff --git a/app/controllers/organizations/staff/form_answers_controller.rb b/app/controllers/organizations/staff/form_answers_controller.rb new file mode 100644 index 000000000..053b71d26 --- /dev/null +++ b/app/controllers/organizations/staff/form_answers_controller.rb @@ -0,0 +1,24 @@ +module Organizations + module Staff + class FormAnswersController < Organizations::BaseController + before_action :context_authorize!, only: %i[index] + before_action :set_form_submission + + def index + @form_answers = @form_submission.form_answers.order(created_at: :desc) + end + + private + + def set_form_submission + @form_submission = FormSubmission.find_by(id: params[:form_submission_id]) + end + + def context_authorize! + authorize! FormAnswer, + context: {organization: Current.organization}, + with: Organizations::FormSubmissionPolicy + end + end + end +end diff --git a/app/controllers/organizations/staff/form_submissions_controller.rb b/app/controllers/organizations/staff/form_submissions_controller.rb new file mode 100644 index 000000000..179647302 --- /dev/null +++ b/app/controllers/organizations/staff/form_submissions_controller.rb @@ -0,0 +1,27 @@ +module Organizations + module Staff + class FormSubmissionsController < Organizations::BaseController + layout "dashboard" + + before_action :context_authorize!, only: %i[index] + before_action :set_person + + def index + @form_submissions = @person.form_submissions.order(created_at: :desc) + end + + private + + def set_person + @person = Person.find_by(id: params[:person_id]) + + redirect_back_or_to staff_dashboard_index_path if @person.nil? + end + + def context_authorize! + authorize! FormSubmission, + context: {organization: Current.organization} + end + end + end +end diff --git a/app/models/concerns/authorizable.rb b/app/models/concerns/authorizable.rb index 8c10b36df..1526a1f4e 100644 --- a/app/models/concerns/authorizable.rb +++ b/app/models/concerns/authorizable.rb @@ -54,6 +54,7 @@ def staff?(organization) manage_tasks view_organization_dashboard view_people + view_form_submissions manage_faqs ] ).freeze diff --git a/app/policies/organizations/form_submission_policy.rb b/app/policies/organizations/form_submission_policy.rb new file mode 100644 index 000000000..288c27029 --- /dev/null +++ b/app/policies/organizations/form_submission_policy.rb @@ -0,0 +1,12 @@ +module Organizations + class FormSubmissionPolicy < ApplicationPolicy + pre_check :verify_organization! + pre_check :verify_active_staff! + + alias_rule :index?, to: :manage? + + def manage? + permission?(:view_form_submissions) + end + end +end diff --git a/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb b/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb index 64f9a0269..7083b2a96 100644 --- a/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb +++ b/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb @@ -7,9 +7,9 @@ <%= render partial: "applications_table", locals: { applications: @applications} %> - - <%#= render partial:"application_cards", collection: @applications, as: :application %> - +
+ <%= render partial:"application_cards", collection: @applications, as: :application %> +
<% end %> <% end %> diff --git a/app/views/organizations/staff/adoption_application_reviews/show.html.erb b/app/views/organizations/staff/adoption_application_reviews/show.html.erb deleted file mode 100644 index bbb66d9e6..000000000 --- a/app/views/organizations/staff/adoption_application_reviews/show.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<%= render DashboardPageComponent.new(crumb: :dashboard_applications, crumb_options: [@application]) do |c| %> - <% c.with_header_title { t(:form_answers) } %> - <% c.with_body do %> -
-
-
- <%= @application.person.full_name %> -
- <%= mail_to @application.person.email, @application.person.email, class: "link-underline link-underline-opacity-0" %> -
-
-
-
- <% @form_answers.each do |form_answer| %> -
-
-
-
-
- Q: <%= form_answer.question_snapshot %> -

A: <%= form_answer.value %>

-
-
-
-
-
- <% end %> - <% end %> -<% end %> diff --git a/app/views/organizations/staff/form_answers/index.html.erb b/app/views/organizations/staff/form_answers/index.html.erb new file mode 100644 index 000000000..4b39f5df1 --- /dev/null +++ b/app/views/organizations/staff/form_answers/index.html.erb @@ -0,0 +1,16 @@ +<%= turbo_frame_tag :form_answers do %> + <% @form_answers.each do |form_answer| %> +
+
+
+
+
+ Q: <%= form_answer.question_snapshot %> +

A: <%= form_answer.value %>

+
+
+
+
+
+ <% end %> +<% end %> diff --git a/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb b/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb new file mode 100644 index 000000000..dd4fca673 --- /dev/null +++ b/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb @@ -0,0 +1,26 @@ +
+ +
+ + + + + + + + + + <% form_submissions.each do |form_submission| %> + + + + + <% end %> + +
SubmittedAction
+

<%= form_submission.created_at.strftime("%Y-%m-%d") %>

+
+ <%= link_to "View Submission", staff_form_submission_form_answers_path(form_submission), data: { turbo_frame: "form_answers" } %> +
+
+
diff --git a/app/views/organizations/staff/form_submissions/index.html.erb b/app/views/organizations/staff/form_submissions/index.html.erb new file mode 100644 index 000000000..68db23d27 --- /dev/null +++ b/app/views/organizations/staff/form_submissions/index.html.erb @@ -0,0 +1,30 @@ +<%= render DashboardPageComponent.new(crumb: :form_submissions, crumb_options: [@person]) do |c| %> + <% c.with_header_title { t('.header') } %> + <% c.with_body do %> +
+
+
+

<%= @person.full_name %>

+
+ <%= mail_to @person.email, @person.email, class: "link-underline link-underline-opacity-0" %> +
+
+
+
+
+ <% if @form_submissions.present? %> + <%= render partial: "form_submissions_table", locals: { form_submissions: @form_submissions } %> + <% else %> + <% message = "#{@person.full_name} does not have any imported form data. If they have completed a third party form, please upload the data #{link_to 'here', staff_external_form_upload_index_path}.".html_safe %> + +
+ <%= render partial: "shared/empty_state", locals: { message: message } %> +
+ <% end %> +
+ + <%= turbo_frame_tag :form_answers do %> + <%# Form answers will be loaded here via turbo frame %> + <% end %> + <% end %> +<% end %> diff --git a/app/views/organizations/staff/pets/tabs/partials/_application_info_table_row.html.erb b/app/views/organizations/staff/pets/tabs/partials/_application_info_table_row.html.erb index 2f4f78b0c..cfdcb8bc4 100644 --- a/app/views/organizations/staff/pets/tabs/partials/_application_info_table_row.html.erb +++ b/app/views/organizations/staff/pets/tabs/partials/_application_info_table_row.html.erb @@ -1,6 +1,6 @@ - <%= link_to app.person.full_name, staff_adoption_application_review_path(app), + <%= link_to app.person.full_name, staff_person_form_submissions_path(app.person), class: "link-underline link-underline-opacity-0" %> diff --git a/app/views/shared/_empty_state.html.erb b/app/views/shared/_empty_state.html.erb new file mode 100644 index 000000000..3f31bb0e5 --- /dev/null +++ b/app/views/shared/_empty_state.html.erb @@ -0,0 +1,5 @@ +
+
+

<%= message %>

+
+
diff --git a/config/breadcrumbs.rb b/config/breadcrumbs.rb index a2c317c8e..84173442d 100644 --- a/config/breadcrumbs.rb +++ b/config/breadcrumbs.rb @@ -70,6 +70,10 @@ link "Applications", staff_adoption_application_reviews_path end +crumb :form_submissions do |person| + link "Form Submissions", staff_person_form_submissions_path(person.id) +end + crumb :dashboard_applications do |application| link application.person.full_name, staff_adoption_application_reviews_path(application) parent :applications diff --git a/config/locales/en.yml b/config/locales/en.yml index cbd0fc805..76c495d5f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -403,6 +403,9 @@ en: login: "Log in" important_info: "Important Information" staff: + form_submissions: + index: + header: "Form Submissions" fosterers: update: success: Fosterer was susccessfully updated diff --git a/config/routes.rb b/config/routes.rb index 48937d920..fd85b8a06 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,7 @@ resources :home, only: [:index] resources :adoptable_pets, only: %i[index show] resources :faq, only: [:index] + namespace :staff do resource :organization, only: %i[edit update] resource :custom_page, only: %i[edit update] @@ -33,7 +34,15 @@ end resources :matches, only: %i[create destroy] - resources :adoption_application_reviews, only: %i[index edit update show] + resources :people do + resources :form_submissions, only: [:index] + end + + resources :form_submissions do + resources :form_answers, only: [:index] + end + + resources :adoption_application_reviews, only: %i[index edit update] resources :manage_fosters, only: %i[new create index edit update destroy] resources :fosterers, only: %i[index edit update] resources :adopters, only: %i[index] @@ -52,6 +61,7 @@ post "user_roles/:id/to_admin", to: "user_roles#to_admin", as: "user_to_admin" post "user_roles/:id/to_super_admin", to: "user_roles#to_super_admin", as: "user_to_super_admin" end + delete "staff/attachments/:id/purge", to: "attachments#purge", as: "staff_purge_attachment" delete "attachments/:id/purge_avatar", to: "attachments#purge_avatar", as: "purge_avatar" From 3b5d6fbf61ecf4fa528581620dbed80ce7b70911 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 12 Dec 2024 14:44:01 -0800 Subject: [PATCH 07/21] lint --- .../organizations/staff/form_answers_controller.rb | 4 ++-- .../organizations/staff/form_submissions_controller.rb | 2 +- app/models/adopter_application.rb | 2 +- .../staff/adoption_application_reviews_controller_test.rb | 1 - 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/organizations/staff/form_answers_controller.rb b/app/controllers/organizations/staff/form_answers_controller.rb index 053b71d26..19cea4c7f 100644 --- a/app/controllers/organizations/staff/form_answers_controller.rb +++ b/app/controllers/organizations/staff/form_answers_controller.rb @@ -16,8 +16,8 @@ def set_form_submission def context_authorize! authorize! FormAnswer, - context: {organization: Current.organization}, - with: Organizations::FormSubmissionPolicy + context: {organization: Current.organization}, + with: Organizations::FormSubmissionPolicy end end end diff --git a/app/controllers/organizations/staff/form_submissions_controller.rb b/app/controllers/organizations/staff/form_submissions_controller.rb index 179647302..1f7cd8244 100644 --- a/app/controllers/organizations/staff/form_submissions_controller.rb +++ b/app/controllers/organizations/staff/form_submissions_controller.rb @@ -20,7 +20,7 @@ def set_person def context_authorize! authorize! FormSubmission, - context: {organization: Current.organization} + context: {organization: Current.organization} end end end diff --git a/app/models/adopter_application.rb b/app/models/adopter_application.rb index d0693ba1d..1da255bf2 100644 --- a/app/models/adopter_application.rb +++ b/app/models/adopter_application.rb @@ -29,7 +29,7 @@ class AdopterApplication < ApplicationRecord belongs_to :person validates :pet_id, uniqueness: {scope: :person_id} - + enum :status, [:awaiting_review, :under_review, :adoption_pending, diff --git a/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb b/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb index f0fde0f80..566773e56 100644 --- a/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb +++ b/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb @@ -12,7 +12,6 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis @form_submission = create(:form_submission) @adopter_application = create(:adopter_application, person: @adopter.person) - sign_in @user end From a5951d8b016f4fb812ecb32de5f34a4b7558dad8 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 12 Dec 2024 14:54:53 -0800 Subject: [PATCH 08/21] appease brakeman --- .../organizations/staff/form_submissions/index.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/organizations/staff/form_submissions/index.html.erb b/app/views/organizations/staff/form_submissions/index.html.erb index 68db23d27..c7a2aec03 100644 --- a/app/views/organizations/staff/form_submissions/index.html.erb +++ b/app/views/organizations/staff/form_submissions/index.html.erb @@ -15,10 +15,10 @@ <% if @form_submissions.present? %> <%= render partial: "form_submissions_table", locals: { form_submissions: @form_submissions } %> <% else %> - <% message = "#{@person.full_name} does not have any imported form data. If they have completed a third party form, please upload the data #{link_to 'here', staff_external_form_upload_index_path}.".html_safe %> - -
- <%= render partial: "shared/empty_state", locals: { message: message } %> +
+
+

<%= @person.full_name %> does not have any imported form data. If they have completed a third party form, please upload the data <%= link_to 'here', staff_external_form_upload_index_path %>.

+
<% end %> From 704fa5cdd13f07a44629259d9be29c8a32a153f9 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 09:45:20 -0800 Subject: [PATCH 09/21] add tests; add form answer header --- .../staff/form_answers/index.html.erb | 2 + .../form_submission_policy_test.rb | 323 ++++++++++++++++++ 2 files changed, 325 insertions(+) create mode 100644 test/policies/organizations/form_submission_policy_test.rb diff --git a/app/views/organizations/staff/form_answers/index.html.erb b/app/views/organizations/staff/form_answers/index.html.erb index 4b39f5df1..73be3a941 100644 --- a/app/views/organizations/staff/form_answers/index.html.erb +++ b/app/views/organizations/staff/form_answers/index.html.erb @@ -1,4 +1,6 @@ <%= turbo_frame_tag :form_answers do %> +

Form Answers (<%= @form_submission.created_at.strftime("%Y-%m-%d") %>)

+ <% @form_answers.each do |form_answer| %>
diff --git a/test/policies/organizations/form_submission_policy_test.rb b/test/policies/organizations/form_submission_policy_test.rb new file mode 100644 index 000000000..f57361c9f --- /dev/null +++ b/test/policies/organizations/form_submission_policy_test.rb @@ -0,0 +1,323 @@ +require "test_helper" + +# See https://actionpolicy.evilmartians.io/#/testing?id=testing-policies +module Organizations + class FormSubmissionPolicyTest < ActiveSupport::TestCase + include PetRescue::PolicyAssertions + + context "context only action" do + setup do + @organization = ActsAsTenant.current_tenant + @policy = -> { + Organizations::FormSubmissionPolicy.new(FormSubmission, user: @user, + organization: @organization) + } + end + + context "#manage?" do + setup do + @action = -> { @policy.call.apply(:manage?) } + end + + context "when user is nil" do + setup do + @user = nil + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is adopter" do + setup do + @user = create(:adopter) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is fosterer" do + setup do + @user = create(:fosterer) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is activated admin" do + setup do + @user = create(:admin) + end + + context "when organization context is a different organization" do + setup do + @organization = create(:organization) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when organization context is admin organization" do + should "return true" do + assert_equal true, @action.call + end + end + end + + context "when user is deactivated admin" do + setup do + @user = create(:admin, :deactivated) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is superadmin" do + setup do + @user = create(:super_admin) + end + + context "when organization context is a different organization" do + setup do + @organization = create(:organization) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when organization context is superadmin organization" do + should "return true" do + assert_equal true, @action.call + end + end + end + end + + context "#index?" do + should "be an alias to :manage?" do + assert_alias_rule @policy.call, :index?, :manage? + end + end + end + + context "existing record action" do + setup do + @form_submission = create(:form_submission) + @policy = -> { + Organizations::FormSubmissionPolicy.new(@form_submission, user: @user) + } + end + + context "#manage?" do + setup do + @action = -> { @policy.call.apply(:manage?) } + end + + context "when user is nil" do + setup do + @user = nil + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is adopter" do + setup do + @user = create(:adopter) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is fosterer" do + setup do + @user = create(:fosterer) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is activated admin" do + setup do + @user = create(:admin) + end + + context "when FormSubmission belongs to a different organization" do + setup do + ActsAsTenant.with_tenant(create(:organization)) do + @form_submission = create(:form_submission) + end + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when FAQ belongs to admin organization" do + should "return true" do + assert_equal true, @action.call + end + end + end + + context "when user is deactivated admin" do + setup do + @user = create(:admin, :deactivated) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is admin" do + setup do + @user = create(:super_admin) + end + + context "when FormSubmission belongs to a different organization" do + setup do + ActsAsTenant.with_tenant(create(:organization)) do + @form_submission = create(:form_submission) + end + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when FormSubmission belongs to admin organization" do + should "return true" do + assert_equal true, @action.call + end + end + end + end + end + + context "existing record action" do + setup do + @form_submission = create(:form_submission) + @form_answer = create(:form_answer, form_submission: @form_submission) + @policy = -> { + Organizations::FormSubmissionPolicy.new(@form_answer, user: @user) + } + end + + context "#manage?" do + setup do + @action = -> { @policy.call.apply(:manage?) } + end + + context "when user is nil" do + setup do + @user = nil + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is adopter" do + setup do + @user = create(:adopter) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is fosterer" do + setup do + @user = create(:fosterer) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is activated admin" do + setup do + @user = create(:admin) + end + + context "when FormSubmission belongs to a different organization" do + setup do + ActsAsTenant.with_tenant(create(:organization)) do + @form_submission = create(:form_submission) + @form_answer = create(:form_answer, form_submission: @form_submission) + end + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when FAQ belongs to admin organization" do + should "return true" do + assert_equal true, @action.call + end + end + end + + context "when user is deactivated admin" do + setup do + @user = create(:admin, :deactivated) + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when user is admin" do + setup do + @user = create(:super_admin) + end + + context "when FormSubmission belongs to a different organization" do + setup do + ActsAsTenant.with_tenant(create(:organization)) do + @form_submission = create(:form_submission) + @form_answer = create(:form_answer, form_submission: @form_submission) + end + end + + should "return false" do + assert_equal false, @action.call + end + end + + context "when FormSubmission belongs to admin organization" do + should "return true" do + assert_equal true, @action.call + end + end + end + end + end + end +end From 6c100df637d24a58e5dcf929cf50daa05b5fe6f4 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 10:16:40 -0800 Subject: [PATCH 10/21] update tests --- ...ion_application_reviews_controller_test.rb | 26 --------------- .../registrations_controller_test.rb | 8 ----- .../adoption_application_reviews_test.rb | 33 +------------------ 3 files changed, 1 insertion(+), 66 deletions(-) diff --git a/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb b/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb index 566773e56..21c017513 100644 --- a/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb +++ b/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb @@ -72,17 +72,6 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis end end end - - context "#show" do - should "be authorized" do - assert_authorized_to( - :manage?, @adopter_application, - with: Organizations::AdopterApplicationPolicy - ) do - get staff_adoption_application_review_url(@adopter_application) - end - end - end end context "Filtering adoption applications" do @@ -153,20 +142,5 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis @form_answers = create_list(:form_answer, 3, form_submission: @form_submission) @adopter_application = create(:adopter_application, person: @adopter.person) end - - context "#show" do - should "fetch the form answers" do - get staff_adoption_application_review_url(@adopter_application) - - assert_response :success - assert_equal @form_answers.count, assigns(:form_answers).count - - @form_answers.each do |form_answer| - assert assigns(:form_answers).include?(form_answer) - assert_equal form_answer.question_snapshot, form_answer.question_snapshot - assert_equal form_answer.value, form_answer.value - end - end - end end end diff --git a/test/controllers/registrations_controller_test.rb b/test/controllers/registrations_controller_test.rb index 100d24c85..d17cccfcd 100644 --- a/test/controllers/registrations_controller_test.rb +++ b/test/controllers/registrations_controller_test.rb @@ -12,14 +12,6 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest assert_equal true, has_role end - test "should create form submission when user is persisted" do - assert_difference "FormSubmission.count", 1 do - registration_params = {user: attributes_for(:user)} - - post user_registration_url, params: registration_params - end - end - test "should get new with dashboard layout when signed in as staff" do user = create(:admin) organization = user.organization diff --git a/test/integration/organizations/staff/adoption_application_reviews_test.rb b/test/integration/organizations/staff/adoption_application_reviews_test.rb index 3d00d4ce7..518e1a531 100644 --- a/test/integration/organizations/staff/adoption_application_reviews_test.rb +++ b/test/integration/organizations/staff/adoption_application_reviews_test.rb @@ -12,7 +12,7 @@ class Organizations::Staff::AdoptionApplicationReviewsTest < ActionDispatch::Int @custom_page = create(:custom_page, organization: ActsAsTenant.current_tenant) # Setup for show view tests - @form_submission = @adopter.person.latest_form_submission + @form_submission = create(:form_submission, person: @adopter.person) @form_answers = create_list(:form_answer, 3, form_submission: @form_submission) @adopter_application = create(:adopter_application, person: @adopter.person) end @@ -29,18 +29,6 @@ class Organizations::Staff::AdoptionApplicationReviewsTest < ActionDispatch::Int follow_redirect! assert_equal I18n.t("errors.authorization_error"), flash[:alert] end - - should "not be able to view application details" do - @user = create(:user) - sign_in @user - - get staff_adoption_application_review_path(@adopter_application) - - assert_response :redirect - follow_redirect! - follow_redirect! - assert_equal I18n.t("errors.authorization_error"), flash[:alert] - end end context "active staff" do @@ -78,25 +66,6 @@ class Organizations::Staff::AdoptionApplicationReviewsTest < ActionDispatch::Int assert_equal("some notes", @under_review_app.notes) end - context "viewing application details" do - should "assign correct form answers" do - get staff_adoption_application_review_path(@adopter_application) - - assert_response :success - assert_equal @form_answers, assigns(:form_answers) - assert_equal 3, assigns(:form_answers).count - end - - should "have correct application and person data" do - get staff_adoption_application_review_path(@adopter_application) - - assert_response :success - - assert_equal @adopter_application, assigns(:application) - assert_equal @adopter_application.person, assigns(:application).person - end - end - context "deactivated staff" do setup do sign_in create(:admin, :deactivated) From 285ca2ce215fed654d954a5f0896f334fbfe7ccc Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 10:17:00 -0800 Subject: [PATCH 11/21] lint --- test/policies/organizations/form_submission_policy_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/policies/organizations/form_submission_policy_test.rb b/test/policies/organizations/form_submission_policy_test.rb index f57361c9f..c476ebd68 100644 --- a/test/policies/organizations/form_submission_policy_test.rb +++ b/test/policies/organizations/form_submission_policy_test.rb @@ -10,7 +10,7 @@ class FormSubmissionPolicyTest < ActiveSupport::TestCase @organization = ActsAsTenant.current_tenant @policy = -> { Organizations::FormSubmissionPolicy.new(FormSubmission, user: @user, - organization: @organization) + organization: @organization) } end From efcaf6b3671ac72a5ea05b5beefea57e33f4fb83 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 10:22:05 -0800 Subject: [PATCH 12/21] remove handling the nil person case, this should fail loudly as it should not occur --- .../organizations/staff/form_submissions_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/organizations/staff/form_submissions_controller.rb b/app/controllers/organizations/staff/form_submissions_controller.rb index 1f7cd8244..0950e4380 100644 --- a/app/controllers/organizations/staff/form_submissions_controller.rb +++ b/app/controllers/organizations/staff/form_submissions_controller.rb @@ -14,8 +14,6 @@ def index def set_person @person = Person.find_by(id: params[:person_id]) - - redirect_back_or_to staff_dashboard_index_path if @person.nil? end def context_authorize! From efb41ff0401859585cba2e1cb7b03cb4334c068a Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 10:24:43 -0800 Subject: [PATCH 13/21] remove partial as I am not using it --- app/views/shared/_empty_state.html.erb | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 app/views/shared/_empty_state.html.erb diff --git a/app/views/shared/_empty_state.html.erb b/app/views/shared/_empty_state.html.erb deleted file mode 100644 index 3f31bb0e5..000000000 --- a/app/views/shared/_empty_state.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -
-
-

<%= message %>

-
-
From e8af96c93ffe8f0443f424dc86988d46c8e3050d Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 10:37:20 -0800 Subject: [PATCH 14/21] move empty state text to translation file --- app/views/organizations/staff/form_submissions/index.html.erb | 4 ++-- config/locales/en.yml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/organizations/staff/form_submissions/index.html.erb b/app/views/organizations/staff/form_submissions/index.html.erb index c7a2aec03..b48edf0ab 100644 --- a/app/views/organizations/staff/form_submissions/index.html.erb +++ b/app/views/organizations/staff/form_submissions/index.html.erb @@ -12,12 +12,12 @@
- <% if @form_submissions.present? %> + <% if false %> <%= render partial: "form_submissions_table", locals: { form_submissions: @form_submissions } %> <% else %>
-

<%= @person.full_name %> does not have any imported form data. If they have completed a third party form, please upload the data <%= link_to 'here', staff_external_form_upload_index_path %>.

+

<%= t('.empty_state', person_name: @person.full_name) %> <%= link_to t('general.here'), staff_external_form_upload_index_path %>.

<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 76c495d5f..fabbe9304 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -57,6 +57,7 @@ en: organization_name: Organization name your_name: Your name general: + here: "here" attach: "Attach" adoption_pending: "(Adoption Pending)" adopted: Adopted @@ -406,6 +407,7 @@ en: form_submissions: index: header: "Form Submissions" + empty_state: "%{person_name} does not have any imported form data. If they have completed a third party form, please upload the data" fosterers: update: success: Fosterer was susccessfully updated From efc750895070d1dfa92978925f27773f4c980137 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 10:39:15 -0800 Subject: [PATCH 15/21] fix --- app/views/organizations/staff/form_submissions/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/organizations/staff/form_submissions/index.html.erb b/app/views/organizations/staff/form_submissions/index.html.erb index b48edf0ab..85da1c821 100644 --- a/app/views/organizations/staff/form_submissions/index.html.erb +++ b/app/views/organizations/staff/form_submissions/index.html.erb @@ -12,7 +12,7 @@
- <% if false %> + <% if @form_submissions.present? %> <%= render partial: "form_submissions_table", locals: { form_submissions: @form_submissions } %> <% else %>
From 0fa66936c468e1fd2c0a64552a5cfd8f999b505b Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 13 Dec 2024 10:48:08 -0800 Subject: [PATCH 16/21] update foster links to fosterer data --- .../staff/manage_fosters/_foster_cards.html.erb | 5 +---- .../staff/manage_fosters/_foster_table_row.html.erb | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/views/organizations/staff/manage_fosters/_foster_cards.html.erb b/app/views/organizations/staff/manage_fosters/_foster_cards.html.erb index 9a38233bf..36369aadb 100644 --- a/app/views/organizations/staff/manage_fosters/_foster_cards.html.erb +++ b/app/views/organizations/staff/manage_fosters/_foster_cards.html.erb @@ -25,10 +25,7 @@
  • Fosterer:
    - <%= link_to "PLACEHOLDER FOR FORM ANSWERS", - nil, - class: "link-underline link-underline-opacity-0" - %> + <%= link_to foster.person.full_name, staff_person_form_submissions_path(foster.person)%>
  • diff --git a/app/views/organizations/staff/manage_fosters/_foster_table_row.html.erb b/app/views/organizations/staff/manage_fosters/_foster_table_row.html.erb index 0d2eb8069..b7503f9c0 100644 --- a/app/views/organizations/staff/manage_fosters/_foster_table_row.html.erb +++ b/app/views/organizations/staff/manage_fosters/_foster_table_row.html.erb @@ -1,11 +1,9 @@ - <%= link_to "PLACEHOLDER FOR FORM ANSWERS", - nil, - class: "link-underline link-underline-opacity-0" - %> + <%= link_to foster.person.full_name, staff_person_form_submissions_path(foster.person)%> +
    From 022d69e8c1de99b9ab5165fba065e75d65d1612b Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 14 Dec 2024 14:09:14 -0800 Subject: [PATCH 17/21] Update to show csv_timestamp and import date and show HH MM on the submitted at in case someone submits a form twice in one day, then it is easiser to determine which answers you are looking at --- app/models/form_submission.rb | 2 ++ .../organizations/staff/form_answers/index.html.erb | 2 +- .../form_submissions/_form_submissions_table.html.erb | 10 +++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/form_submission.rb b/app/models/form_submission.rb index b141ec681..e50493541 100644 --- a/app/models/form_submission.rb +++ b/app/models/form_submission.rb @@ -33,4 +33,6 @@ class FormSubmission < ApplicationRecord has_many :form_answers, dependent: :destroy delegate :user, to: :person + + validates :csv_timestamp, presence: true end diff --git a/app/views/organizations/staff/form_answers/index.html.erb b/app/views/organizations/staff/form_answers/index.html.erb index 73be3a941..6bdbb2f06 100644 --- a/app/views/organizations/staff/form_answers/index.html.erb +++ b/app/views/organizations/staff/form_answers/index.html.erb @@ -1,5 +1,5 @@ <%= turbo_frame_tag :form_answers do %> -

    Form Answers (<%= @form_submission.created_at.strftime("%Y-%m-%d") %>)

    +

    Form Answers (<%= @form_submission.csv_timestamp.strftime("%Y-%m-%d") %> at <%= @form_submission.csv_timestamp.strftime("%H:%M") %>)

    <% @form_answers.each do |form_answer| %>
    diff --git a/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb b/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb index dd4fca673..18745fedb 100644 --- a/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb +++ b/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb @@ -4,8 +4,9 @@ - + + @@ -13,10 +14,13 @@ <% form_submissions.each do |form_submission| %> + <% end %> From 3ef21278f312848243f868e582f8fb837f1c4a64 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 14 Dec 2024 14:23:15 -0800 Subject: [PATCH 18/21] merge main --- db/seeds/01_alta.rb | 3 ++- db/seeds/02_baja.rb | 3 ++- test/factories/form_submission.rb | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/db/seeds/01_alta.rb b/db/seeds/01_alta.rb index 4006dbd22..be8149e07 100644 --- a/db/seeds/01_alta.rb +++ b/db/seeds/01_alta.rb @@ -231,7 +231,8 @@ FormSubmission.create( person: @adopter_one, - organization: @organization + organization: @organization, + csv_timestamp: Time.current ) FormSubmission.all.each do |submission| diff --git a/db/seeds/02_baja.rb b/db/seeds/02_baja.rb index fe4f8c97e..63ad10b97 100644 --- a/db/seeds/02_baja.rb +++ b/db/seeds/02_baja.rb @@ -183,7 +183,8 @@ FormSubmission.create( person: @adopter_one, - organization: @organization + organization: @organization, + csv_timestamp: Time.current ) FormSubmission.all.each do |submission| diff --git a/test/factories/form_submission.rb b/test/factories/form_submission.rb index db52f4b99..a386a03f9 100644 --- a/test/factories/form_submission.rb +++ b/test/factories/form_submission.rb @@ -2,5 +2,6 @@ factory :form_submission do # organization assigned by ActsAsTenant association :person + csv_timestamp { Time.current } end end From 8806b4cef5d5b46b48c1da10ff668315ba9c91b1 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 14 Dec 2024 14:27:40 -0800 Subject: [PATCH 19/21] remove creation of formsubmission on creation of adopter user in seeds --- db/seeds/01_alta.rb | 6 ------ db/seeds/02_baja.rb | 8 +------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/db/seeds/01_alta.rb b/db/seeds/01_alta.rb index be8149e07..ca37360a0 100644 --- a/db/seeds/01_alta.rb +++ b/db/seeds/01_alta.rb @@ -66,8 +66,6 @@ @user_adopter_one.add_role(:adopter, @organization) - @adopter_one.form_submissions.create! - @adopter_two = Person.create!( email: "adopter2@alta.com", first_name: "Kamala", @@ -85,8 +83,6 @@ @user_adopter_two.add_role(:adopter, @organization) - @adopter_two.form_submissions.create! - @adopter_three = Person.create!( email: "adopter3@alta.com", first_name: "Bad", @@ -104,8 +100,6 @@ @user_adopter_three.add_role(:adopter, @organization) - @adopter_three.form_submissions.create! - @fosterer_one = Person.create!( email: "fosterer1@alta.com", first_name: "Simon", diff --git a/db/seeds/02_baja.rb b/db/seeds/02_baja.rb index 63ad10b97..ae8145fd4 100644 --- a/db/seeds/02_baja.rb +++ b/db/seeds/02_baja.rb @@ -65,8 +65,6 @@ @user_adopter_one.add_role(:adopter, @organization) - @adopter_one.form_submissions.create! - @adopter_two = Person.create!( email: "adopter2@baja.com", first_name: "Kamala", @@ -84,8 +82,6 @@ @user_adopter_two.add_role(:adopter, @organization) - @adopter_two.form_submissions.create! - @adopter_three = Person.create!( email: "adopter3@baja.com", first_name: "Bad", @@ -102,9 +98,7 @@ ) @user_adopter_three.add_role(:adopter, @organization) - - @adopter_three.form_submissions.create! - + @fosterer_one = Person.create!( email: "fosterer1@baja.com", first_name: "Simon", From 85b50fcb06adabdc1e984be4e612570519503a94 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 14 Dec 2024 14:29:12 -0800 Subject: [PATCH 20/21] lint --- db/seeds/02_baja.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds/02_baja.rb b/db/seeds/02_baja.rb index ae8145fd4..7244f28a6 100644 --- a/db/seeds/02_baja.rb +++ b/db/seeds/02_baja.rb @@ -98,7 +98,7 @@ ) @user_adopter_three.add_role(:adopter, @organization) - + @fosterer_one = Person.create!( email: "fosterer1@baja.com", first_name: "Simon", From ba38ff4df58fed0608d6ff0d0a654ea7e16cede2 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 14 Dec 2024 15:17:55 -0800 Subject: [PATCH 21/21] add remaining translations --- .../form_submissions/_form_submissions_table.html.erb | 8 ++++---- config/locales/en.yml | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb b/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb index 18745fedb..ffeae9f3f 100644 --- a/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb +++ b/app/views/organizations/staff/form_submissions/_form_submissions_table.html.erb @@ -4,9 +4,9 @@
    Submitted ActionForm SubmittedImport Date
    -

    <%= form_submission.created_at.strftime("%Y-%m-%d") %>

    + <%= link_to "View Submission", staff_form_submission_form_answers_path(form_submission), data: { turbo_frame: "form_answers" } %>
    - <%= link_to "View Submission", staff_form_submission_form_answers_path(form_submission), data: { turbo_frame: "form_answers" } %> +

    <%= form_submission.csv_timestamp.strftime("%Y-%m-%d") %> at <%= form_submission.csv_timestamp.strftime("%H:%M") %>

    +
    +

    <%= form_submission.created_at.strftime("%Y-%m-%d") %>

    - - - + + + @@ -14,7 +14,7 @@ <% form_submissions.each do |form_submission| %>
    ActionForm SubmittedImport Date<%= t("organizations.staff.form_submissions.action") %><%= t("organizations.staff.form_submissions.form_submitted") %><%= t("organizations.staff.form_submissions.import_date") %>
    - <%= link_to "View Submission", staff_form_submission_form_answers_path(form_submission), data: { turbo_frame: "form_answers" } %> + <%= link_to t("organizations.staff.form_submissions.view_submission"), staff_form_submission_form_answers_path(form_submission), data: { turbo_frame: "form_answers" } %>

    <%= form_submission.csv_timestamp.strftime("%Y-%m-%d") %> at <%= form_submission.csv_timestamp.strftime("%H:%M") %>

    diff --git a/config/locales/en.yml b/config/locales/en.yml index fabbe9304..21612c99c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -405,6 +405,10 @@ en: important_info: "Important Information" staff: form_submissions: + action: "Action" + form_submitted: "Form Submitted" + import_date: "Import Date" + view_submission: "View Submission" index: header: "Form Submissions" empty_state: "%{person_name} does not have any imported form data. If they have completed a third party form, please upload the data"