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.
77
78
79
80
81
|
# File 'app/services/hyrax/access_control_list.rb', line 77
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
102
103
104
105
106
107
108
|
# File 'app/services/hyrax/access_control_list.rb', line 102
def <<(permission)
permission.access_to = resource.id
change_set.permissions += [permission]
true
end
|
#delete(permission) ⇒ Boolean
117
118
119
120
121
|
# File 'app/services/hyrax/access_control_list.rb', line 117
def delete(permission)
change_set.permissions -= [permission]
true
end
|
#destroy ⇒ Boolean
Deletes the ACL for the resource
200
201
202
203
204
205
|
# File 'app/services/hyrax/access_control_list.rb', line 200
def destroy
persister.delete(resource: change_set.resource) if change_set.resource.persisted?
@change_set = nil
true
end
|
#grant(mode) ⇒ Object
130
131
132
|
# File 'app/services/hyrax/access_control_list.rb', line 130
def grant(mode)
ModeGrant.new(self, mode)
end
|
#pending_changes? ⇒ Boolean
138
139
140
|
# File 'app/services/hyrax/access_control_list.rb', line 138
def pending_changes?
change_set.changed?
end
|
146
147
148
|
# File 'app/services/hyrax/access_control_list.rb', line 146
def permissions
Set.new(change_set.permissions)
end
|
#permissions=(new_permissions) ⇒ Array<Hyrax::Permission>
154
155
156
157
|
# File 'app/services/hyrax/access_control_list.rb', line 154
def permissions=(new_permissions)
change_set.permissions = []
new_permissions.each { |p| self << p }
end
|
#revoke(mode) ⇒ Object
166
167
168
|
# File 'app/services/hyrax/access_control_list.rb', line 166
def revoke(mode)
ModeRevoke.new(self, mode)
end
|
#save ⇒ Boolean
Saves the ACL for the resource, by saving each permission policy
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'app/services/hyrax/access_control_list.rb', line 176
def save
return true unless pending_changes?
change_set.sync
@access_control_model = persister.save(resource: change_set.resource)
Hyrax.publisher.publish('object.acl.updated', acl: self, result: :success)
@change_set = nil
true
end
|