From d9f6a142a05b6f00ab14da588661ebcf29aad7f5 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Tue, 5 Jan 2021 12:16:32 -0500 Subject: [PATCH] Updated GroupPolicy to allow moderators to perform most group actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Updated: - GroupPolicy to allow moderators to perform most group actions except for editing or destroying a group --- app/policies/group_policy.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/policies/group_policy.rb b/app/policies/group_policy.rb index 96d79091..fb45e1f7 100644 --- a/app/policies/group_policy.rb +++ b/app/policies/group_policy.rb @@ -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