A platform for community discussion. Free, open, simple.
FIX: Allow a user to remove their title
Blake Erickson7750b30016fd
diff --git a/lib/guardian.rb b/lib/guardian.rbindex baa26363aa3..528a190ff79 100644--- a/lib/guardian.rb+++ b/lib/guardian.rb@@ -222,6 +222,7 @@ class Guardiandef 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 stringreturn false if user != @userreturn 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.rbindex d849d583f59..5b29ff6f430 100644--- a/spec/components/guardian_spec.rb+++ b/spec/components/guardian_spec.rb@@ -2243,6 +2243,10 @@ describe Guardian doit "returns false if title is from a group the user doesn't belong to" doexpect(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)+ endendend