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

- (AdminOnlyPolicy) initialize(user, record)

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

- (Object) record (readonly)

Returns the value of attribute record



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

def record
  @record
end

- (Object) user (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

- (Boolean) create?

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

- (Boolean) destroy?

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

- (Boolean) edit?

Returns:

  • (Boolean)


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

def edit?
  update?
end

- (Boolean) index?

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

- (Boolean) new?

Returns:

  • (Boolean)


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

def new?
  create?
end

- (Object) scope



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

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

- (Boolean) show?

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

- (Boolean) update?

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