forbid removed users from joining the group again

This commit is contained in:
2458773093 2019-07-16 17:10:14 +03:00
parent b9641b41e7
commit 6e37a72ed6
1 changed files with 5 additions and 0 deletions

View File

@ -24,6 +24,7 @@ class GroupPolicy < ApplicationPolicy
def join?
check_archive!
raise GabSocial::ValidationError, "User is already a member of this group." if is_member?
raise GabSocial::ValidationError, "Account is removed from this group." if is_removed?
return true
end
@ -56,6 +57,10 @@ class GroupPolicy < ApplicationPolicy
private
def is_removed?
record.group_removed_accounts.where(account_id: current_account.id).exists?
end
def is_member?
record.group_accounts.where(account_id: current_account.id).exists?
end