Updated GroupPolicy to allow moderators to perform most group actions

• Updated:
- GroupPolicy to allow moderators to perform most group actions except for editing or destroying a group
This commit is contained in:
mgabdev 2021-01-05 12:16:32 -05:00
parent 2fcc99cccf
commit d9f6a142a0
1 changed files with 10 additions and 6 deletions

View File

@ -29,12 +29,12 @@ class GroupPolicy < ApplicationPolicy
def approve_status?
check_archive!
is_group_admin?
is_group_admin_or_moderator?
end
def destroy_status?
check_archive!
is_group_admin?
is_group_admin_or_moderator?
end
def join?
@ -56,19 +56,19 @@ class GroupPolicy < ApplicationPolicy
end
def update_account?
is_group_admin?
is_group_admin_or_moderator?
end
def show_removed_accounts?
is_group_admin?
is_group_admin_or_moderator?
end
def create_removed_account?
is_group_admin?
is_group_admin_or_moderator?
end
def destroy_removed_account?
is_group_admin?
is_group_admin_or_moderator?
end
private
@ -85,6 +85,10 @@ class GroupPolicy < ApplicationPolicy
record.group_accounts.where(account_id: current_account.id, role: :admin).exists?
end
def is_group_admin_or_moderator?
record.group_accounts.where(account_id: current_account.id, role: [:moderator, :admin]).exists?
end
def check_archive!
raise GabSocial::ValidationError, "This group has been archived." if record.is_archived
end