-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathlimited_access.rb
More file actions
42 lines (33 loc) · 964 Bytes
/
limited_access.rb
File metadata and controls
42 lines (33 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Edition::LimitedAccess
extend ActiveSupport::Concern
included do
enum :access_limited, { disabled: 0, organisations: 1, named_users: 2 }
has_many :edition_user_accesses, dependent: :destroy, inverse_of: :edition
after_initialize :set_access_limited
end
module ClassMethods
def access_limited_by_default?
false
end
end
def access_limited_object
self
end
def access_limited?
organisations? || named_users?
end
delegate :access_limited_by_default?, to: :class
def access_limited=(value)
@_access_limited_explicitly_set = true
super
end
def set_access_limited
return unless new_record?
return if @_access_limited_explicitly_set
self.access_limited = access_limited_by_default? ? :organisations : :disabled
@_access_limited_explicitly_set = false
end
def accessible_to?(user)
user.present? && Whitehall::Authority::Enforcer.new(user, self).can?(:see)
end
end