class ProjectPolicy < ApplicationPolicy class Scope < Scope def resolve if user.account_manager? scope.joins(account: :account_auths).where(account_auths: { user_id: user.id }) else scope.joins(:project_memberships).where(project_memberships: { user_id: user.id }) end end end def index? true end def create? user.account_manager? end def show? user.project_memberships.exists?(project: record) || user.account_manager? end def update? user.manager? || user.account_manager? end def destroy? false end def show_reports? update? end def show_downloads? show? end def show_task_results? show? end end