Class: Faalis::AdminOnlyPolicy

Inherits:
Object
  • Object
show all
Defined in:
app/policies/faalis/admin_only_policy.rb

Overview

This class grant admin access only. This can be a good base class for your resource if you want to give access to admin only

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, record) ⇒ AdminOnlyPolicy

Returns a new instance of AdminOnlyPolicy.



7
8
9
10
# File 'app/policies/faalis/admin_only_policy.rb', line 7

def initialize(user, record)
  @user = user
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



5
6
7
# File 'app/policies/faalis/admin_only_policy.rb', line 5

def record
  @record
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'app/policies/faalis/admin_only_policy.rb', line 5

def user
  @user
end

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'app/policies/faalis/admin_only_policy.rb', line 24

def create?
  return false if @user.nil?
  return true if @user.admin?
  false
end

#destroy?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
# File 'app/policies/faalis/admin_only_policy.rb', line 44

def destroy?
  return false if @user.nil?
  return true if @user.admin?
  false
end

#edit?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/policies/faalis/admin_only_policy.rb', line 40

def edit?
  update?
end

#index?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'app/policies/faalis/admin_only_policy.rb', line 12

def index?
  return false if @user.nil?
  return true if @user.admin?
  false
end

#new?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/policies/faalis/admin_only_policy.rb', line 30

def new?
  create?
end

#scopeObject



50
51
52
# File 'app/policies/faalis/admin_only_policy.rb', line 50

def scope
  Pundit.policy_scope!(@user, record.class)
end

#show?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'app/policies/faalis/admin_only_policy.rb', line 18

def show?
  return false if @user.nil?
  return true if @user.admin?
  false
end

#update?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'app/policies/faalis/admin_only_policy.rb', line 34

def update?
  return false if @user.nil?
  return true if @user.admin?
  false
end