Class: ManifestationPolicy

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

Instance Method Summary collapse

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)


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

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

#destroy?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/policies/manifestation_policy.rb', line 38

def destroy?
  if record.items.empty?
    if !record.try(:is_reserved?)
      if record.series_master?
        if record.children.empty?
          case user.try(:role).try(:name)
          when 'Administrator'
            true
          when 'Librarian'
            true if record.required_role_id <= 3
          else
            false
          end
        else
          false
        end
      else
        case user.try(:role).try(:name)
        when 'Administrator'
          true
        when 'Librarian'
          true if record.required_role_id <= 3
        else
          false
        end
      end
    end
  end
end

#edit?Boolean

Returns:

  • (Boolean)


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

def edit?
  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
  end
end

#index?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'app/policies/manifestation_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/manifestation_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)


34
35
36
# File 'app/policies/manifestation_policy.rb', line 34

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