Skip to content

Commit

Permalink
Remove ability to ascribe metadata profiles to units
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Dolski committed Mar 11, 2024
1 parent fe84db6 commit a0f9994
Show file tree
Hide file tree
Showing 15 changed files with 14 additions and 104 deletions.
1 change: 0 additions & 1 deletion app/controllers/metadata_profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/units_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions app/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
2 changes: 0 additions & 2 deletions app/models/metadata_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
22 changes: 1 addition & 21 deletions app/models/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.
#
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/util/csv_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 0 additions & 16 deletions app/views/metadata_profiles/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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?
Expand Down
8 changes: 0 additions & 8 deletions app/views/units/_properties_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions app/views/units/_show_about_tab.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/units/_show_items_tab.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveMetadataProfileIdColumnFromUnits < ActiveRecord::Migration[7.1]
def change
remove_column :units, :metadata_profile_id
end
end
5 changes: 1 addition & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions test/models/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions test/models/metadata_profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
15 changes: 0 additions & 15 deletions test/models/unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0f9994

Please sign in to comment.