Class: Locomotive::ApplicationPolicy

Inherits:
Object
  • Object
show all
Defined in:
app/policies/locomotive/application_policy.rb

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(membership, resource) ⇒ ApplicationPolicy

The resource is always scoped by the site defined by the membership.

Raises:

  • (Pundit::NotAuthorizedError)

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

def initialize(membership, resource)
  @membership = membership
  @resource   = resource

  raise Pundit::NotAuthorizedError, 'must be logged in' unless 
  raise Pundit::NotAuthorizedError, 'should have a resource' unless resource
end

Instance Attribute Details

#membershipObject (readonly)

Returns the value of attribute membership


17
18
19
# File 'app/policies/locomotive/application_policy.rb', line 17

def membership
  @membership
end

#resourceObject (readonly)

Returns the value of attribute resource


17
18
19
# File 'app/policies/locomotive/application_policy.rb', line 17

def resource
  @resource
end

Instance Method Details

#create?Boolean

Returns:


48
49
50
# File 'app/policies/locomotive/application_policy.rb', line 48

def create?
  false
end

#destroy?Boolean

Returns:


52
53
54
# File 'app/policies/locomotive/application_policy.rb', line 52

def destroy?
  false
end

#destroy_all?Boolean

Returns:


56
57
58
# File 'app/policies/locomotive/application_policy.rb', line 56

def destroy_all?
  false
end

#edit?Boolean

Returns:


36
37
38
# File 'app/policies/locomotive/application_policy.rb', line 36

def edit?
  update?
end

#index?Boolean

Returns:


28
29
30
# File 'app/policies/locomotive/application_policy.rb', line 28

def index?
  false
end

#new?Boolean

Returns:


44
45
46
# File 'app/policies/locomotive/application_policy.rb', line 44

def new?
  create?
end

#persisted?Boolean

Returns:


76
77
78
# File 'app/policies/locomotive/application_policy.rb', line 76

def persisted?
  resource.try(:persisted?)
end

#show?Boolean

Returns:


32
33
34
# File 'app/policies/locomotive/application_policy.rb', line 32

def show?
  index?
end

#site_admin?Boolean

Returns:


72
73
74
# File 'app/policies/locomotive/application_policy.rb', line 72

def site_admin?
  membership.admin?
end

#site_admin_or_designer?Boolean

Returns:


68
69
70
# File 'app/policies/locomotive/application_policy.rb', line 68

def site_admin_or_designer?
  membership.admin? || membership.designer?
end

#site_staff?Boolean

Returns:


60
61
62
# File 'app/policies/locomotive/application_policy.rb', line 60

def site_staff?
  membership.site.present?
end

#super_admin?Boolean

Returns:


64
65
66
# File 'app/policies/locomotive/application_policy.rb', line 64

def super_admin?
  .super_admin?
end

#update?Boolean

Returns:


40
41
42
# File 'app/policies/locomotive/application_policy.rb', line 40

def update?
  false
end