Class: ProfilePolicy

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

Instance Attribute Summary

Attributes inherited from ApplicationPolicy

#record, #user

Instance Method Summary collapse

Methods inherited from ApplicationPolicy

#edit?, #initialize, #new?, #scope

Constructor Details

This class inherits a constructor from ApplicationPolicy

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)


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

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

#destroy?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/policies/profile_policy.rb', line 36

def destroy?
  return false unless user
  return false unless user.try(:has_role?, 'Librarian')
  if record.user
    if record != user.profile && record.user.id != 1
      if defined?(EnjuCirculation)
        if record.user.checkouts.not_returned.empty?
          true if record.user.deletable_by?(user)
        end
      else
        true if record.user.deletable_by?(user)
      end
    else
      false
    end
  else
    true
  end
end

#index?Boolean

Returns:

  • (Boolean)


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

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

#show?Boolean

Returns:

  • (Boolean)


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

def show?
  case user.try(:role).try(:name)
  when 'Administrator'
    true
  when 'Librarian'
    return true if record == user.profile
    true if %w(Librarian User Guest).include?(record.required_role.name)
  when 'User'
    return true if record == user.profile
    true if %w(User Guest).include?(record.required_role.name)
  end
end

#update?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/policies/profile_policy.rb', line 23

def update?
  case user.try(:role).try(:name)
  when 'Administrator'
    true
  when 'Librarian'
    unless record.user.try(:has_role?, 'Administrator')
      true if %w(User Guest Librarian).include?(record.required_role.name)
    end
  when 'User'
    return true if record == user.profile
  end
end