Fix #5146: Adding an existing favorite to favorite groups leads to an error.

Show "Favgroup already contains post XXX" error when trying to add a
post to a favgroup that already contains that post.
This commit is contained in:
evazion
2022-05-02 14:15:53 -05:00
parent 5e923e266b
commit 93352b318e
6 changed files with 26 additions and 17 deletions

View File

@@ -537,12 +537,12 @@ class Post < ApplicationRecord
in "-favgroup", name
favgroup = FavoriteGroup.find_by_name_or_id!(name, CurrentUser.user)
raise User::PrivilegeError unless Pundit.policy!(CurrentUser.user, favgroup).update?
favgroup&.remove!(self)
favgroup&.remove(self)
in "favgroup", name
favgroup = FavoriteGroup.find_by_name_or_id!(name, CurrentUser.user)
raise User::PrivilegeError unless Pundit.policy!(CurrentUser.user, favgroup).update?
favgroup&.add!(self)
favgroup&.add(self)
end
end
@@ -632,7 +632,7 @@ class Post < ApplicationRecord
def remove_from_fav_groups
FavoriteGroup.for_post(id).find_each do |favgroup|
favgroup.remove!(self)
favgroup.remove(self)
end
end
end