Skip to content

Commit

Permalink
Use errors#add instead of <<
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcolvar committed Dec 13, 2024
1 parent 2942d68 commit bef3762
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/actors/hyrax/actors/add_to_work_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def new_works_for(env, new_work_ids)
end

def add_permissions_error(work)
work.errors[:in_works_ids] << "Works can only be related to each other if user has ability to edit both."
work.errors.add(:in_works_ids, "Works can only be related to each other if user has ability to edit both.")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/actors/hyrax/actors/apply_order_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def add_new_work_ids_not_already_in_curation_concern(env, ordered_member_ids)
env.curation_concern.ordered_members << work
env.curation_concern.save!
else
env.curation_concern.errors[:ordered_member_ids] << "Works can only be related to each other if user has ability to edit both."
env.curation_concern.errors.add(:ordered_member_ids, "Works can only be related to each other if user has ability to edit both.")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def destroy

def after_destroy_error
if source.admin_set?
@permission_template_access.errors[:base] <<
t('hyrax.admin.admin_sets.form.permission_destroy_errors.participants')
@permission_template_access.errors.add(:base,
t('hyrax.admin.admin_sets.form.permission_destroy_errors.participants'))
redirect_to hyrax.edit_admin_admin_set_path(source_id,
anchor: 'participants'),
alert: @permission_template_access.errors.full_messages.to_sentence
else
@permission_template_access.errors[:base] <<
t('hyrax.dashboard.collections.form.permission_update_errors.sharing')
@permission_template_access.errors.add(:base,
t('hyrax.dashboard.collections.form.permission_update_errors.sharing'))
redirect_to hyrax.edit_dashboard_collection_path(source_id,
anchor: 'sharing'),
alert: @permission_template_access.errors.full_messages.to_sentence
Expand Down
4 changes: 2 additions & 2 deletions app/models/admin_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def destroy_permission_template

def check_if_empty
return true if members.empty?
errors[:base] << I18n.t('hyrax.admin.admin_sets.delete.error_not_empty')
errors.add(:base, I18n.t('hyrax.admin.admin_sets.delete.error_not_empty'))
throw :abort
end

def check_if_not_default_set
return true unless Hyrax::AdminSetCreateService.default_admin_set?(id: id)
errors[:base] << I18n.t('hyrax.admin.admin_sets.delete.error_default_set')
errors.add(:base, I18n.t('hyrax.admin.admin_sets.delete.error_default_set'))
throw :abort
end
end
3 changes: 1 addition & 2 deletions app/models/concerns/hyrax/permissions/writable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def paranoid_permissions
valid = true
paranoid_edit_permissions.each do |validation|
next unless validation[:condition].call(self)
errors[validation[:key]] ||= []
errors[validation[:key]] << validation[:message]
errors.add(validation[:key], validation[:message])
valid = false
end
valid
Expand Down
8 changes: 4 additions & 4 deletions app/models/hyrax/collection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,26 @@ def assign_machine_id

def ensure_no_collections
return true unless collections?
errors[:base] << I18n.t('hyrax.admin.collection_types.errors.not_empty')
errors.add(:base, I18n.t('hyrax.admin.collection_types.errors.not_empty'))
throw :abort
end

def ensure_no_settings_changes_for_admin_set_type
return true unless admin_set? && collection_type_settings_changed? && exists_for_machine_id?(ADMIN_SET_MACHINE_ID)
errors[:base] << I18n.t('hyrax.admin.collection_types.errors.no_settings_change_for_admin_sets')
errors.add(:base, I18n.t('hyrax.admin.collection_types.errors.no_settings_change_for_admin_sets'))
throw :abort
end

def ensure_no_settings_changes_for_user_collection_type
return true unless user_collection? && collection_type_settings_changed? && exists_for_machine_id?(USER_COLLECTION_MACHINE_ID)
errors[:base] << I18n.t('hyrax.admin.collection_types.errors.no_settings_change_for_user_collections')
errors.add(:base, I18n.t('hyrax.admin.collection_types.errors.no_settings_change_for_user_collections'))
throw :abort
end

def ensure_no_settings_changes_if_collections_exist
return true unless collections?
return true unless collection_type_settings_changed?
errors[:base] << I18n.t('hyrax.admin.collection_types.errors.no_settings_change_if_not_empty')
errors.add(:base, I18n.t('hyrax.admin.collection_types.errors.no_settings_change_if_not_empty'))
throw :abort
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/single_use_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def expiration_date_cannot_be_in_the_past
end

def cannot_be_destroyed
errors[:base] << "Single Use Link has already been used" if destroyed?
errors.add(:base, "Single Use Link has already been used") if destroyed?
end

def set_defaults
Expand Down
2 changes: 1 addition & 1 deletion app/validators/hyrax/has_one_title_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Hyrax
class HasOneTitleValidator < ActiveModel::Validator
def validate(record)
return unless record.title.reject(&:empty?).empty?
record.errors[:title] << "You must provide a title"
record.errors.add(:title, "You must provide a title")
end
end
end

0 comments on commit bef3762

Please sign in to comment.