Class: Hyrax::AccessControlList
- Inherits:
-
Object
- Object
- Hyrax::AccessControlList
show all
- Defined in:
- app/services/hyrax/access_control_list.rb
Overview
ACLs for ‘Hyrax::Resource` models
Allows managing ‘Hyrax::Permission` entries referring to a specific `Hyrax::Resource` using a simple add/delete model.
Defined Under Namespace
Classes: ModeEditor, ModeGrant, ModeRevoke
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(resource:, persister: Hyrax.persister, query_service: Hyrax.query_service) ⇒ AccessControlList
Returns a new instance of AccessControlList.
67
68
69
70
71
|
# File 'app/services/hyrax/access_control_list.rb', line 67
def initialize(resource:, persister: Hyrax.persister, query_service: Hyrax.query_service)
self.resource = resource
@persister = persister
@query_service = query_service
end
|
Instance Attribute Details
#persister ⇒ #save
57
58
59
|
# File 'app/services/hyrax/access_control_list.rb', line 57
def persister
@persister
end
|
#query_service ⇒ Object
57
|
# File 'app/services/hyrax/access_control_list.rb', line 57
attr_reader :persister, :query_service
|
#resource ⇒ Valkyrie::Resource
57
|
# File 'app/services/hyrax/access_control_list.rb', line 57
attr_reader :persister, :query_service
|
Class Method Details
Copy and save permissions from source to target
Instance Method Details
#<<(permission) ⇒ Boolean
Also known as:
add
92
93
94
95
96
97
98
|
# File 'app/services/hyrax/access_control_list.rb', line 92
def <<(permission)
permission.access_to = resource.id
change_set.permissions += [permission]
true
end
|
#delete(permission) ⇒ Boolean
107
108
109
110
111
|
# File 'app/services/hyrax/access_control_list.rb', line 107
def delete(permission)
change_set.permissions -= [permission]
true
end
|
#destroy ⇒ Boolean
Deletes the ACL for the resource
183
184
185
186
187
188
|
# File 'app/services/hyrax/access_control_list.rb', line 183
def destroy
persister.delete(resource: change_set.resource) if change_set.resource.persisted?
@change_set = nil
true
end
|
#grant(mode) ⇒ Object
120
121
122
|
# File 'app/services/hyrax/access_control_list.rb', line 120
def grant(mode)
ModeGrant.new(self, mode)
end
|
#pending_changes? ⇒ Boolean
128
129
130
|
# File 'app/services/hyrax/access_control_list.rb', line 128
def pending_changes?
change_set.changed?
end
|
136
137
138
|
# File 'app/services/hyrax/access_control_list.rb', line 136
def permissions
Set.new(change_set.permissions)
end
|
#permissions=(new_permissions) ⇒ Array<Hyrax::Permission>
144
145
146
147
|
# File 'app/services/hyrax/access_control_list.rb', line 144
def permissions=(new_permissions)
change_set.permissions = []
new_permissions.each { |p| self << p }
end
|
#revoke(mode) ⇒ Object
156
157
158
|
# File 'app/services/hyrax/access_control_list.rb', line 156
def revoke(mode)
ModeRevoke.new(self, mode)
end
|
#save ⇒ Boolean
Saves the ACL for the resource, by saving each permission policy
166
167
168
169
170
171
172
173
174
175
|
# File 'app/services/hyrax/access_control_list.rb', line 166
def save
return true unless pending_changes?
change_set.sync
persister.save(resource: change_set.resource)
Hyrax.publisher.publish('object.acl.updated', acl: self, result: :success)
@change_set = nil
true
end
|