diff --git a/lib/guardian.rb b/lib/guardian.rb index baa26363aa3..528a190ff79 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -222,6 +222,7 @@ class Guardian def can_grant_title?(user, title = nil) return true if user && is_staff? return false if title.nil? + return true if title.empty? # A title set to '(none)' in the UI is an empty string return false if user != @user return true if user.badges.where(name: title, allow_title: true).exists? user.groups.where(title: title).exists? diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index d849d583f59..5b29ff6f430 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -2243,6 +2243,10 @@ describe Guardian do it "returns false if title is from a group the user doesn't belong to" do expect(Guardian.new(user).can_grant_title?(user, group.title)).to eq(false) end + + it "returns true if the title is set to an empty string" do + expect(Guardian.new(user).can_grant_title?(user, '')).to eq(true) + end end end