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 %>