From 5d8513ca749e651fc228d734697dc8b5f269358d Mon Sep 17 00:00:00 2001 From: Trevor Robinson <72584659+Trevor-Robinson@users.noreply.github.com> Date: Wed, 3 Jul 2024 13:23:50 -0600 Subject: [PATCH] 819 replace page text with custom page (#854) * replace all occurances of page text with custom page * fix unintended changes to migration files * change missed instances of PageText * change view folder name to custom pages * nested module/classes for custom pages controller * updated files that got missed for custom page change * ran linter --- .../adoptable_pets_controller.rb | 2 +- .../staff/custom_pages_controller.rb | 29 +++++++++++++++++++ .../staff/page_texts_controller.rb | 25 ---------------- app/models/concerns/authorizable.rb | 2 +- app/models/{page_text.rb => custom_page.rb} | 6 ++-- app/models/organization.rb | 2 +- .../organizations/custom_page_policy.rb | 8 +++++ .../organizations/page_text_policy.rb | 8 ----- app/services/organizations/create_service.rb | 6 ++-- app/views/layouts/dashboard/_sidebar.html.erb | 4 +-- app/views/organizations/home/index.html.erb | 14 ++++----- .../_form.html.erb | 8 ++--- .../edit.html.erb | 7 +++-- config/breadcrumbs.rb | 4 +-- config/locales/en.yml | 2 +- config/routes.rb | 2 +- .../20240225160909_create_page_texts.rb | 2 +- ...40_add_adoptable_pet_info_to_page_texts.rb | 2 +- ...65551_change_page_texts_to_custom_pages.rb | 5 ++++ db/schema.rb | 24 +++++++-------- db/seeds/01_alta.rb | 2 +- db/seeds/02_baja.rb | 2 +- .../image_attachment_table_component_test.rb | 6 ++-- ...est.rb => custom_pages_controller_test.rb} | 24 +++++++-------- .../{page_text.rb => custom_page.rb} | 10 +++---- test/factories/organizations.rb | 4 +-- test/integration/adoptable_pet_show_test.rb | 2 +- .../adoption_application_reviews_test.rb | 2 +- ...{page_text_test.rb => custom_page_test.rb} | 18 ++++++------ test/models/organization_test.rb | 2 +- ...icy_test.rb => custom_page_policy_test.rb} | 4 +-- .../organizations/create_service_test.rb | 4 +-- test/system/adoption_fosterer_test.rb | 2 +- test/system/home_page_test.rb | 4 +-- test/system/login_test.rb | 4 +-- test/system/registration_test.rb | 2 +- test/system/users_test.rb | 2 +- 37 files changed, 133 insertions(+), 123 deletions(-) create mode 100644 app/controllers/organizations/staff/custom_pages_controller.rb delete mode 100644 app/controllers/organizations/staff/page_texts_controller.rb rename app/models/{page_text.rb => custom_page.rb} (88%) create mode 100644 app/policies/organizations/custom_page_policy.rb delete mode 100644 app/policies/organizations/page_text_policy.rb rename app/views/organizations/staff/{page_texts => custom_pages}/_form.html.erb (89%) rename app/views/organizations/staff/{page_texts => custom_pages}/edit.html.erb (53%) create mode 100644 db/migrate/20240628165551_change_page_texts_to_custom_pages.rb rename test/controllers/organizations/staff/{page_texts_controller_test.rb => custom_pages_controller_test.rb} (50%) rename test/factories/{page_text.rb => custom_page.rb} (75%) rename test/models/{page_text_test.rb => custom_page_test.rb} (53%) rename test/policies/organizations/{page_text_policy_test.rb => custom_page_policy_test.rb} (93%) diff --git a/app/controllers/organizations/adoptable_pets_controller.rb b/app/controllers/organizations/adoptable_pets_controller.rb index dc50d00cc..e3beba871 100644 --- a/app/controllers/organizations/adoptable_pets_controller.rb +++ b/app/controllers/organizations/adoptable_pets_controller.rb @@ -17,7 +17,7 @@ def index end def show - @adoptable_pet_info = PageText.first&.adoptable_pet_info + @adoptable_pet_info = CustomPage.first&.adoptable_pet_info @pet = Pet.find(params[:id]) authorize! @pet, with: Organizations::AdoptablePetPolicy diff --git a/app/controllers/organizations/staff/custom_pages_controller.rb b/app/controllers/organizations/staff/custom_pages_controller.rb new file mode 100644 index 000000000..34e9ff159 --- /dev/null +++ b/app/controllers/organizations/staff/custom_pages_controller.rb @@ -0,0 +1,29 @@ +module Organizations + module Staff + class CustomPagesController < Organizations::BaseController + layout "dashboard" + before_action :set_custom_page, only: %i[edit update] + def edit + end + + def update + if @custom_page.update(custom_page_params) + redirect_to edit_staff_custom_page_path, notice: t(".success") + else + redirect_to edit_staff_custom_page_path, alert: @custom_page.errors.full_messages.to_sentence + end + end + + private + + def custom_page_params + params.require(:custom_page).permit(:hero, :about, :hero_image, :adoptable_pet_info, about_us_images: []) + end + + def set_custom_page + @custom_page = CustomPage.first + authorize! @custom_page + end + end + end +end diff --git a/app/controllers/organizations/staff/page_texts_controller.rb b/app/controllers/organizations/staff/page_texts_controller.rb deleted file mode 100644 index 3c76eab2e..000000000 --- a/app/controllers/organizations/staff/page_texts_controller.rb +++ /dev/null @@ -1,25 +0,0 @@ -class Organizations::Staff::PageTextsController < Organizations::BaseController - layout "dashboard" - before_action :set_page_text, only: %i[edit update] - def edit - end - - def update - if @page_text.update(page_text_params) - redirect_to edit_staff_page_text_path, notice: t(".success") - else - redirect_to edit_staff_page_text_path, alert: @page_text.errors.full_messages.to_sentence - end - end - - private - - def page_text_params - params.require(:page_text).permit(:hero, :about, :hero_image, :adoptable_pet_info, about_us_images: []) - end - - def set_page_text - @page_text = PageText.first - authorize! @page_text - end -end diff --git a/app/models/concerns/authorizable.rb b/app/models/concerns/authorizable.rb index 16dcb18b7..d41e6b311 100644 --- a/app/models/concerns/authorizable.rb +++ b/app/models/concerns/authorizable.rb @@ -47,7 +47,7 @@ activate_staff invite_staff manage_organization_profile - manage_page_text + manage_custom_page manage_staff change_user_roles ] diff --git a/app/models/page_text.rb b/app/models/custom_page.rb similarity index 88% rename from app/models/page_text.rb rename to app/models/custom_page.rb index f8364cb6d..261ef8d2f 100644 --- a/app/models/page_text.rb +++ b/app/models/custom_page.rb @@ -1,6 +1,6 @@ # == Schema Information # -# Table name: page_texts +# Table name: custom_pages # # id :bigint not null, primary key # about :text @@ -12,13 +12,13 @@ # # Indexes # -# index_page_texts_on_organization_id (organization_id) +# index_custom_pages_on_organization_id (organization_id) # # Foreign Keys # # fk_rails_... (organization_id => organizations.id) # -class PageText < ApplicationRecord +class CustomPage < ApplicationRecord acts_as_tenant(:organization) has_one_attached :hero_image diff --git a/app/models/organization.rb b/app/models/organization.rb index 4d9a55695..b17148b5d 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -25,5 +25,5 @@ class Organization < ApplicationRecord has_one :profile, dependent: :destroy, class_name: "OrganizationProfile", required: true has_one :location, through: :profile - has_one :page_text, dependent: :destroy + has_one :custom_page, dependent: :destroy end diff --git a/app/policies/organizations/custom_page_policy.rb b/app/policies/organizations/custom_page_policy.rb new file mode 100644 index 000000000..a3fa00b57 --- /dev/null +++ b/app/policies/organizations/custom_page_policy.rb @@ -0,0 +1,8 @@ +class Organizations::CustomPagePolicy < ApplicationPolicy + pre_check :verify_organization! + pre_check :verify_active_staff! + + def manage? + permission?(:manage_custom_page) + end +end diff --git a/app/policies/organizations/page_text_policy.rb b/app/policies/organizations/page_text_policy.rb deleted file mode 100644 index f24fb9323..000000000 --- a/app/policies/organizations/page_text_policy.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Organizations::PageTextPolicy < ApplicationPolicy - pre_check :verify_organization! - pre_check :verify_active_staff! - - def manage? - permission?(:manage_page_text) - end -end diff --git a/app/services/organizations/create_service.rb b/app/services/organizations/create_service.rb index ee6783f54..7d0394fa7 100644 --- a/app/services/organizations/create_service.rb +++ b/app/services/organizations/create_service.rb @@ -39,7 +39,7 @@ def signal(args) create_staff_account add_admin_role_to_staff_account send_email - create_page_text + create_custom_page end rescue => e raise "An error occurred: #{e.message}" @@ -102,9 +102,9 @@ def send_email .create_new_org_and_admin(@organization.slug).deliver_now end - def create_page_text + def create_custom_page ActsAsTenant.with_tenant(@organization) do - PageText.create! + CustomPage.create! end end end diff --git a/app/views/layouts/dashboard/_sidebar.html.erb b/app/views/layouts/dashboard/_sidebar.html.erb index 5725a6b1c..2b97c8850 100644 --- a/app/views/layouts/dashboard/_sidebar.html.erb +++ b/app/views/layouts/dashboard/_sidebar.html.erb @@ -71,8 +71,8 @@ <% end %>