Class: Locomotive::MembershipPolicy

Inherits:
ApplicationPolicy show all
Defined in:
app/policies/locomotive/membership_policy.rb

Instance Attribute Summary

Attributes inherited from ApplicationPolicy

#membership, #resource

Instance Method Summary collapse

Methods inherited from ApplicationPolicy

#destroy_all?, #edit?, #initialize, #new?, #persisted?, #show?, #site_admin?, #site_admin_or_designer?, #site_staff?, #super_admin?

Constructor Details

This class inherits a constructor from Locomotive::ApplicationPolicy

Instance Method Details

#change_role?Boolean

The role cannot be set higher than the current one (we use the index in the roles array to check role presidence)

Returns:



22
23
24
25
# File 'app/policies/locomotive/membership_policy.rb', line 22

def change_role?
  roles = Locomotive::Membership::ROLES
  roles.index(resource.role.to_s) <= roles.index(membership.role.to_s)
end

#create?Boolean

Returns:



8
9
10
# File 'app/policies/locomotive/membership_policy.rb', line 8

def create?
  site_admin_or_designer?
end

#destroy?Boolean

Returns:



16
17
18
# File 'app/policies/locomotive/membership_policy.rb', line 16

def destroy?
  site_admin_or_designer? && change_role?
end

#index?Boolean

Returns:



4
5
6
# File 'app/policies/locomotive/membership_policy.rb', line 4

def index?
  site_admin_or_designer?
end

#permitted_attributesObject



27
28
29
# File 'app/policies/locomotive/membership_policy.rb', line 27

def permitted_attributes
  [:email, :role]
end

#update?Boolean

Returns:



12
13
14
# File 'app/policies/locomotive/membership_policy.rb', line 12

def update?
  site_admin_or_designer? && change_role?
end