FIX: Allow a user to remove their title
Somewhere there was a regression and a user couldn't remove their own title. If they selected '(none)' in the UI it would say it was saved, but it would not actually be updated in the db.
This commit is contained in:
parent
1a55948525
commit
7750b30016
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue