diff --git a/app/models/creatorship.rb b/app/models/creatorship.rb index c9db5842ae7..fcd8700ce1f 100644 --- a/app/models/creatorship.rb +++ b/app/models/creatorship.rb @@ -17,8 +17,8 @@ class Creatorship < ApplicationRecord validates_uniqueness_of :pseud, scope: [:creation_type, :creation_id], on: :create validate :check_invalid, on: :create - validate :check_disallowed, on: :create validate :check_banned, on: :create + validate :check_disallowed, on: :create validate :check_approved_becoming_false, on: :update # Update approval status if this creatorship should be automatically approved. @@ -41,24 +41,24 @@ def check_invalid end end + # Make sure that the user isn't banned or suspended. + def check_banned + return unless pseud&.user&.banned || pseud&.user&.suspended + + errors.add(:base, ts("%{name} cannot be listed as a co-creator.", + name: pseud.byline)) + throw :abort + end + # Make sure that if this is an invitation, we're not inviting someone who has # disabled invitations. def check_disallowed return if approved? || pseud.nil? return if pseud&.user&.preference&.allow_cocreator - errors.add(:base, ts("%{name} does not allow others to invite them to be a co-creator.", name: pseud.byline)) end - # Make sure that the user isn't banned or suspended. - def check_banned - return unless pseud&.user&.banned || pseud&.user&.suspended - - errors.add(:base, ts("%{name} is currently banned and cannot be listed as a co-creator.", - name: pseud.byline)) - end - # Make sure that we're not trying to set approved to false, since that could # potentially violate some rules about co-creators. (e.g. Having a user # listed as a chapter co-creator, but not a work co-creator.) diff --git a/features/works/work_create.feature b/features/works/work_create.feature index bbbf30effde..65c3cbb900a 100755 --- a/features/works/work_create.feature +++ b/features/works/work_create.feature @@ -200,7 +200,7 @@ Feature: Create Works When I fill in "work_collection_names" with "" And I fill in "pseud_byline" with "badcoauthor" And I press "Preview" - Then I should see "badcoauthor is currently banned" + Then I should see "badcoauthor cannot be listed as a co-creator" When I fill in "pseud_byline" with "coauthor" And I fill in "Additional Tags" with "this is a very long tag more than one hundred characters in length how would this normally even be created" And I press "Preview"