Class: AgentPolicy

Inherits:
ApplicationPolicy
  • Object
show all
Defined in:
app/policies/agent_policy.rb

Instance Method Summary collapse

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/policies/agent_policy.rb', line 19

def create?
  true if user.try(:has_role?, 'Librarian')
end

#destroy?Boolean

Returns:

  • (Boolean)


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

def destroy?
  true if user.try(:has_role?, 'Librarian')
end

#index?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'app/policies/agent_policy.rb', line 2

def index?
  true
end

#show?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/policies/agent_policy.rb', line 6

def show?
  case user.try(:role).try(:name)
  when 'Administrator'
    true
  when 'Librarian'
    true if record.required_role_id <= 3
  when 'User'
    true if record.required_role_id <= 2
  else
    true if record.required_role_id <= 1
  end
end

#update?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/policies/agent_policy.rb', line 23

def update?
  true if user.try(:has_role?, 'Librarian')
end