Class: MembershipPolicy

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

Overview

Protects Membership objects

Instance Method Summary collapse

Methods inherited from ApplicationPolicy

#initialize, #scope, #user

Constructor Details

This class inherits a constructor from ApplicationPolicy

Instance Method Details

#create?false Also known as: new?

Returns Memberships can only be created via Invitation

Returns:

  • (false)

    Memberships can only be created via Invitation

See Also:



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

def create?
  false
end

#destroy?Boolean

Returns if attempting to destroy one's own membership, or if the user is an admin and is not attempting to destroy another admin's membership

Returns:

  • (Boolean)

    if attempting to destroy one's own membership, or if the user is an admin and is not attempting to destroy another admin's membership



31
32
33
34
35
36
# File 'app/policies/membership_policy.rb', line 31

def destroy?
  return true if organization_user.staff?
  return true if self?
  return false if same_rank_or_lower?
  organization_user.admin?
end

#index?Boolean Also known as: show?

Returns all users can view an organization's memberships

Returns:

  • (Boolean)

    all users can view an organization's memberships



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

def index?
  true
end

#update?true, false Also known as: edit?

Returns:

  • (true)

    if the user is an admin and is not editing his/her own membership

  • (false)

    if the user is not an admin, or is an admin who is trying to edit his/her own membership



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

def update?
  return true if organization_user.staff?
  return false if self?
  return false if same_rank_or_lower?
  organization_user.admin?
end