diff --git a/app/controllers/metadata_profiles_controller.rb b/app/controllers/metadata_profiles_controller.rb index 1c811ec5..a18842aa 100644 --- a/app/controllers/metadata_profiles_controller.rb +++ b/app/controllers/metadata_profiles_controller.rb @@ -122,7 +122,6 @@ def new # def show # N.B.: these include only directly-assigned units and collections. - @units = @profile.units @collections = @profile.collections @new_element = MetadataProfileElement.new end diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index 69e9f914..92ddeffd 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -306,7 +306,6 @@ def show # Responds to `GET /units/:id/about` # def show_about - @metadata_profile = @unit.effective_metadata_profile @num_downloads = MonthlyUnitItemDownloadCount.sum_for_unit(unit: @unit) @num_submitted_items = @unit.submitted_item_count @collections = Collection.search. @@ -600,9 +599,8 @@ def submissions_in_progress(start, limit) end def unit_params - params.require(:unit).permit(:institution_id, :introduction, - :metadata_profile_id, :parent_id, :rights, - :short_description, :title) + params.require(:unit).permit(:institution_id, :introduction, :parent_id, + :rights, :short_description, :title) end end diff --git a/app/models/collection.rb b/app/models/collection.rb index d8bdbb9d..dd61cf3e 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -376,12 +376,11 @@ def effective_administering_users ## # @return [MetadataProfile] The metadata profile assigned to the instance, or - # the profile assigned to the primary unit, or the institution's - # default profile as a last resort. + # else the institution's default profile. # def effective_metadata_profile #noinspection RubyMismatchedReturnType - self.metadata_profile || self.primary_unit&.effective_metadata_profile + self.metadata_profile || self.institution.default_metadata_profile end ## diff --git a/app/models/metadata_profile.rb b/app/models/metadata_profile.rb index 3932d0e1..167ea98e 100644 --- a/app/models/metadata_profile.rb +++ b/app/models/metadata_profile.rb @@ -43,8 +43,6 @@ class MetadataProfile < ApplicationRecord has_many :elements, -> { order(:position) }, class_name: "MetadataProfileElement", inverse_of: :metadata_profile, dependent: :destroy - has_many :units, inverse_of: :metadata_profile, - dependent: :restrict_with_exception normalizes :name, with: -> (value) { value.squish } diff --git a/app/models/unit.rb b/app/models/unit.rb index 89ffcd22..caab456d 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -22,14 +22,6 @@ # * `created_at` Managed by ActiveRecord. # * `institution_id` Foreign key to {Institution}. # * `introduction` Introduction string. May contain HTML. -# * `metadata_profile_id` Foreign key to {MetadataProfile}. Instances without -# this set will use the -# {Institution#default_metadata_profile default -# metadata profile of the institution}. Child -# collections may override it with their own -# {metadata_profile} property. In most cases, -# {effective_metadata_profile} should be used instead -# of accessing this directly. # * `parent_id` Foreign key to a parent {Unit}. # * `rights` Rights string. # * `short_description` Short description string. @@ -64,7 +56,6 @@ class IndexFields end belongs_to :institution - belongs_to :metadata_profile, inverse_of: :units, optional: true belongs_to :parent, class_name: "Unit", foreign_key: "parent_id", optional: true has_many :administrators, class_name: "UnitAdministrator" @@ -281,16 +272,6 @@ def effective_administering_users @effective_administering_users end - ## - # @return [MetadataProfile] The metadata profile assigned to the instance, or - # the owning institution's default metadata profile if no profile is - # assigned to the instance. - # - def effective_metadata_profile - #noinspection RubyMismatchedReturnType - self.metadata_profile || self.institution.default_metadata_profile - end - ## # Un-buries an instance. # @@ -362,8 +343,7 @@ def move_to(institution:, user:) progress.report(entity_idx, "Moving #{unit.title} to #{institution.name}") unit.administrators.destroy_all unit.administrator_groups.destroy_all - unit.update!(institution_id: institution.id, - metadata_profile: nil) + unit.update!(institution_id: institution.id) unit.collections.each do |collection| progress.report(entity_idx, "Moving #{collection.title} to #{institution.name}") collection.administrators.destroy_all diff --git a/app/util/csv_exporter.rb b/app/util/csv_exporter.rb index d36af815..157ef904 100644 --- a/app/util/csv_exporter.rb +++ b/app/util/csv_exporter.rb @@ -44,7 +44,7 @@ def export(units: [], collections: [], elements: []) # Compile a list of elements to include. if elements.empty? profile = collections.first&.effective_metadata_profile || - units.first&.effective_metadata_profile + units.first&.institution&.default_metadata_profile elements = profile.elements.map(&:name) end diff --git a/app/views/metadata_profiles/show.html.haml b/app/views/metadata_profiles/show.html.haml index a5f23322..d8dfeba8 100644 --- a/app/views/metadata_profiles/show.html.haml +++ b/app/views/metadata_profiles/show.html.haml @@ -40,16 +40,6 @@ Elements %span.badge.rounded-pill.text-bg-secondary= @profile.elements.count - unless @profile.global? - %li.nav-item - %button#units-tab.nav-link{"data-bs-target": "#units", - "data-bs-toggle": "tab", - role: "tab", - type: "button", - "aria-controls": "units", - "aria-selected": "false"} - = icon_for(Unit) - Directly Assigned Units - %span.badge.rounded-pill.text-bg-secondary= @units.count %li.nav-item %button#collections-tab.nav-link{"data-bs-target": "#collections", "data-bs-toggle": "tab", @@ -166,12 +156,6 @@ = element.relevance_weight - unless @profile.global? - #units.tab-pane.fade{role: "tabpanel", - "aria-labelledby": "units-tab"} - - if @units.exists? - = resource_list(@units) - - else - This metadata profile is not directly assigned to any units. #collections.tab-pane.fade{role: "tabpanel", "aria-labelledby": "collections-tab"} - if @collections.exists? diff --git a/app/views/units/_properties_form.html.haml b/app/views/units/_properties_form.html.haml index cb307436..b6af331c 100644 --- a/app/views/units/_properties_form.html.haml +++ b/app/views/units/_properties_form.html.haml @@ -26,14 +26,6 @@ = f.label :rights = f.text_area :rights, class: "form-control" - .mb-3 - = f.label :metadata_profile_id, "Metadata Profile" - = f.select :metadata_profile_id, MetadataProfile.where(institution: f.object.institution).order(:name).pluck(:name, :id), - { include_blank: true }, class: "form-select" - %p.form-text - = icon_for(:info) - If left blank, the default metadata profile will be used. - .clearfix .float-end %button.btn.btn-light{"data-bs-dismiss": "modal", type: "button"} Cancel diff --git a/app/views/units/_show_about_tab.html.haml b/app/views/units/_show_about_tab.html.haml index 0957cdf5..1b6d33e1 100644 --- a/app/views/units/_show_about_tab.html.haml +++ b/app/views/units/_show_about_tab.html.haml @@ -22,15 +22,6 @@ %dt Handle URI %dd= @unit.handle&.permanent_url - if policy(@unit).show_extended_about? - %dt Metadata Profile - %dd - - if @unit.metadata_profile - - if policy(@metadata_profile).show? - = link_to(@metadata_profile.name, @metadata_profile) - - else - = @metadata_profile.name - - else - = raw("Not assigned (falling back to #{link_to(@metadata_profile.name, @metadata_profile)})") %dt File Downloads %dd= number_with_delimiter(@num_downloads) %dt Items Awaiting Review diff --git a/app/views/units/_show_items_tab.html.haml b/app/views/units/_show_items_tab.html.haml index 7369191b..eb54d531 100644 --- a/app/views/units/_show_items_tab.html.haml +++ b/app/views/units/_show_items_tab.html.haml @@ -52,7 +52,7 @@ = filter_field #advanced-search.tab-pane.fade.mt-3{role: "tabpanel", "aria-labelledby": "advanced-search-tab"} - = advanced_search_form(@unit.effective_metadata_profile) + = advanced_search_form(@unit.institution.default_metadata_profile) .row.justify-content-between .col-8 diff --git a/db/migrate/20240311195942_remove_metadata_profile_id_column_from_units.rb b/db/migrate/20240311195942_remove_metadata_profile_id_column_from_units.rb new file mode 100644 index 00000000..cdea1099 --- /dev/null +++ b/db/migrate/20240311195942_remove_metadata_profile_id_column_from_units.rb @@ -0,0 +1,5 @@ +class RemoveMetadataProfileIdColumnFromUnits < ActiveRecord::Migration[7.1] + def change + remove_column :units, :metadata_profile_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 79a84091..422ced47 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.1].define(version: 2024_03_11_185518) do +ActiveRecord::Schema[7.1].define(version: 2024_03_11_195942) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "unaccent" @@ -779,9 +779,7 @@ t.text "introduction" t.text "rights" t.boolean "buried", default: false, null: false - t.bigint "metadata_profile_id" t.index ["institution_id"], name: "index_units_on_institution_id" - t.index ["metadata_profile_id"], name: "index_units_on_metadata_profile_id" t.index ["parent_id"], name: "index_units_on_parent_id" end @@ -922,7 +920,6 @@ add_foreign_key "unit_collection_memberships", "collections", on_update: :cascade, on_delete: :cascade add_foreign_key "unit_collection_memberships", "units", on_update: :cascade, on_delete: :cascade add_foreign_key "units", "institutions", on_update: :cascade, on_delete: :restrict - add_foreign_key "units", "metadata_profiles", on_update: :cascade, on_delete: :restrict add_foreign_key "units", "units", column: "parent_id", on_update: :cascade, on_delete: :restrict add_foreign_key "user_groups", "institutions", on_update: :cascade, on_delete: :cascade add_foreign_key "user_groups_users", "user_groups", on_update: :cascade, on_delete: :cascade diff --git a/test/models/collection_test.rb b/test/models/collection_test.rb index b4878bff..585883ce 100644 --- a/test/models/collection_test.rb +++ b/test/models/collection_test.rb @@ -371,18 +371,9 @@ class CollectionTest < ActiveSupport::TestCase assert_equal profile, @instance.effective_metadata_profile end - test "effective_metadata_profile() falls back to the primary unit's profile - if no profile is assigned" do - profile = metadata_profiles(:southeast_default) - @instance.metadata_profile = nil - @instance.primary_unit.metadata_profile = profile - assert_equal profile, @instance.effective_metadata_profile - end - test "effective_metadata_profile() falls back to the institution's default - profile if no profile is assigned to the primary unit" do + profile if no profile is assigned" do @instance.metadata_profile = nil - @instance.primary_unit.metadata_profile = nil assert_equal metadata_profiles(:southeast_default), @instance.effective_metadata_profile end diff --git a/test/models/metadata_profile_test.rb b/test/models/metadata_profile_test.rb index f9c530a7..8e831010 100644 --- a/test/models/metadata_profile_test.rb +++ b/test/models/metadata_profile_test.rb @@ -8,15 +8,6 @@ class MetadataProfileTest < ActiveSupport::TestCase # base-level tests - test "instances with dependent units cannot be destroyed" do - @instance = metadata_profiles(:southeast_unused) - unit = units(:southeast_unit1) - unit.update!(metadata_profile: @instance) - assert_raises ActiveRecord::DeleteRestrictionError do - @instance.destroy! - end - end - test "destroying an instance destroys its dependent MetadataProfileElements" do elements = @instance.elements @instance.collections = [] diff --git a/test/models/unit_test.rb b/test/models/unit_test.rb index eff73766..2001202c 100644 --- a/test/models/unit_test.rb +++ b/test/models/unit_test.rb @@ -293,21 +293,6 @@ class UnitTest < ActiveSupport::TestCase assert_equal 2, admins.length end - # effective_metadata_profile() - - test "effective_metadata_profile() returns the assigned metadata profile" do - profile = metadata_profiles(:southeast_unused) - @instance.metadata_profile = profile - assert_equal profile, @instance.effective_metadata_profile - end - - test "effective_metadata_profile() falls back to the institution's default - profile if no profile is assigned" do - @instance.metadata_profile = nil - assert_equal metadata_profiles(:southeast_default), - @instance.effective_metadata_profile - end - # exhume!() test "exhume!() exhumes a buried unit" do