From 05d283865a8fb4b0afccac9b537741805506adb5 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Wed, 20 Dec 2023 09:27:04 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Clean=20up=20model=20overrides?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of what's in this commit is just updating the Hyrax version in the override comments. There was also an opportunity to switch the `ContactForm` model to a decorator. --- app/models/ability.rb | 2 +- .../hyrax/ability/collection_ability.rb | 2 +- .../hyrax/ability/solr_document_ability.rb | 2 +- app/models/content_block.rb | 5 ++- .../access_controls/embargo_decorator.rb | 2 +- .../hydra/access_controls/lease_decorator.rb | 2 +- .../collection_type_participant_decorator.rb | 2 +- app/models/hyrax/contact_form.rb | 40 ------------------- app/models/hyrax/contact_form_decorator.rb | 25 ++++++++++++ app/models/hyrax/group.rb | 2 +- .../permission_template_access_decorator.rb | 2 +- 11 files changed, 36 insertions(+), 50 deletions(-) delete mode 100644 app/models/hyrax/contact_form.rb create mode 100644 app/models/hyrax/contact_form_decorator.rb diff --git a/app/models/ability.rb b/app/models/ability.rb index c433ad198..80708e606 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -25,7 +25,7 @@ class Ability self.ability_logic += %i[everyone_can_create_curation_concerns] end - # OVERRIDE METHOD from blacklight-access_controls v0.6.2 + # OVERRIDE METHOD from blacklight-access_controls v6.0.1 # # NOTE: DO NOT RENAME THIS METHOD - it is required for permissions to function properly. # diff --git a/app/models/concerns/hyrax/ability/collection_ability.rb b/app/models/concerns/hyrax/ability/collection_ability.rb index 4f208b412..612e1070a 100644 --- a/app/models/concerns/hyrax/ability/collection_ability.rb +++ b/app/models/concerns/hyrax/ability/collection_ability.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# OVERRIDE Hyrax v3.4.2 Alter abilities for Groups with Roles feature +# OVERRIDE Hyrax v5.0.0rc2 Alter abilities for Groups with Roles feature module Hyrax module Ability # rubocop:disable Metrics/ModuleLength diff --git a/app/models/concerns/hyrax/ability/solr_document_ability.rb b/app/models/concerns/hyrax/ability/solr_document_ability.rb index b3e5616e4..1248eefbc 100644 --- a/app/models/concerns/hyrax/ability/solr_document_ability.rb +++ b/app/models/concerns/hyrax/ability/solr_document_ability.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# OVERRIDE Hyrax v3.4.2 Alter abilities for Groups with Roles feature +# OVERRIDE Hyrax v5.0.0rc2 Alter abilities for Groups with Roles feature module Hyrax module Ability module SolrDocumentAbility diff --git a/app/models/content_block.rb b/app/models/content_block.rb index 7fcab340c..b4f291f43 100644 --- a/app/models/content_block.rb +++ b/app/models/content_block.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true -# OVERRIDE Hyrax v3.4.0 to add home_text to registry -# and getter/setter methods - Adding themes +# OVERRIDE Hyrax v5.0.0rc to add home_text to registry and getter/setter methods - Adding themes +# NOTE: This class inherits from ApplicationRecord while Hyrax's version inherits from ActiveRecord::Base +# so we cannot use the decorator pattern to override the methods. # rubocop:disable Metrics/ClassLength class ContentBlock < ApplicationRecord # The keys in this registry are "public" names for collaborator diff --git a/app/models/hydra/access_controls/embargo_decorator.rb b/app/models/hydra/access_controls/embargo_decorator.rb index 6d1bed4ed..9daf716e3 100644 --- a/app/models/hydra/access_controls/embargo_decorator.rb +++ b/app/models/hydra/access_controls/embargo_decorator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# OVERRIDE Hydra-access-controls 12.0.1 +# OVERRIDE Hydra-access-controls v12.1.0 # Fix releasing embargos on the day they are expired - this solves a 1 second bug around how # midnights are calculated, which causes day of embargos to incorrectly set the permissions to private module Hydra diff --git a/app/models/hydra/access_controls/lease_decorator.rb b/app/models/hydra/access_controls/lease_decorator.rb index 971f7f58b..37ab3b856 100644 --- a/app/models/hydra/access_controls/lease_decorator.rb +++ b/app/models/hydra/access_controls/lease_decorator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# OVERRIDE Hydra-access-controls 12.0.1 +# OVERRIDE Hydra-access-controls 12.1.0 # Fix releasing leases on the day they are expired - this solves a 1 second bug around how # midnights are calculated, which causes day of leases to incorrectly set the permissions to private module Hydra diff --git a/app/models/hyrax/collection_type_participant_decorator.rb b/app/models/hyrax/collection_type_participant_decorator.rb index c64b667d2..164f101a1 100644 --- a/app/models/hyrax/collection_type_participant_decorator.rb +++ b/app/models/hyrax/collection_type_participant_decorator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# OVERRIDE Hyrax v3.4.2 Expand functionality for Groups with Roles feature +# OVERRIDE Hyrax v5.0.0rc2 Expand functionality for Groups with Roles feature module Hyrax module CollectionTypeParticipantDecorator # OVERRIDE: #titleize agent_id for groups since we are displaying their humanized names in the dropdown diff --git a/app/models/hyrax/contact_form.rb b/app/models/hyrax/contact_form.rb deleted file mode 100644 index fc03c74ee..000000000 --- a/app/models/hyrax/contact_form.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -# OVERRIDE Hyrax 3.4.0 to override the mail to -module Hyrax - class ContactForm - include ActiveModel::Model - attr_accessor :contact_method, :category, :name, :email, :subject, :message - validates :email, :category, :name, :subject, :message, presence: true - validates :email, format: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i, allow_blank: true - - # - can't use this without ActiveRecord::Base - # validates_inclusion_of :category, in: self.class.issue_types_for_locale - - # They should not have filled out the `contact_method' field. That's there to prevent spam. - def spam? - contact_method.present? - end - - # Declare the e-mail headers. It accepts anything the mail method - # in ActionMailer accepts. - ###### OVERRODE the to: field to add the Tenant's email, first - def contact_email - Site.account.contact_email_to - end - - def headers - ## OVERRIDE Hyrax 3.4.0 send the mail 'from' the submitter, which doesn't work on most smtp transports - { - subject: "#{Site.account.email_subject_prefix} #{email} #{subject}", - to: contact_email, - from: Site.account.contact_email, - reply_to: email - } - end - - def self.issue_types_for_locale - I18n.t('hyrax.contact_form.issue_types').values.select(&:present?) - end - end -end diff --git a/app/models/hyrax/contact_form_decorator.rb b/app/models/hyrax/contact_form_decorator.rb new file mode 100644 index 000000000..27cbf3fb0 --- /dev/null +++ b/app/models/hyrax/contact_form_decorator.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# OVERRIDE Hyrax v5.0.0rc2 to override the mail to +module Hyrax + module ContactFormDecorator + # Declare the e-mail headers. It accepts anything the mail method + # in ActionMailer accepts. + ###### OVERRIDE the to: field to add the Tenant's email, first + def contact_email + Site.account.contact_email_to + end + + def headers + ## OVERRIDE Hyrax 3.4.0 send the mail 'from' the submitter, which doesn't work on most smtp transports + { + subject: "#{Site.account.email_subject_prefix} #{email} #{subject}", + to: contact_email, + from: Site.account.contact_email, + reply_to: email + } + end + end +end + +Hyrax::ContactForm.prepend(Hyrax::ContactFormDecorator) diff --git a/app/models/hyrax/group.rb b/app/models/hyrax/group.rb index 27a6a327a..640498f77 100644 --- a/app/models/hyrax/group.rb +++ b/app/models/hyrax/group.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# OVERRIDE Hyrax v3.4.2 Expand functionality for Groups with Roles Feature +# OVERRIDE Hyrax v5.0.0rc2 Expand functionality for Groups with Roles Feature # @see https://github.com/samvera/hyku/wiki/Groups-with-Roles-Feature module Hyrax class Group < ApplicationRecord diff --git a/app/models/hyrax/permission_template_access_decorator.rb b/app/models/hyrax/permission_template_access_decorator.rb index 7ca6bb32b..f6f6fa479 100644 --- a/app/models/hyrax/permission_template_access_decorator.rb +++ b/app/models/hyrax/permission_template_access_decorator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# OVERRIDE Hyrax v3.4.2 #titleize agent_id for groups since we are displaying their humanized names in the dropdown +# OVERRIDE Hyrax v5.0.0rc2 #titleize agent_id for groups since we are displaying their humanized names in the dropdown module Hyrax module PermissionTemplateAccessDecorator def label