Class: Argus::Trail::Role
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Argus::Trail::Role
- Defined in:
- app/models/argus/trail/role.rb
Instance Method Summary collapse
-
#sync_permissions!(new_permission_ids, changed_by: Argus::Trail.config.changed_by_resolver.call) ⇒ Object
Diffs the requested permission ids against the role's current ones and writes one AuditEntry per addition/removal, so the audit log captures exactly which permissions were granted or revoked (not just "something changed").
Instance Method Details
#sync_permissions!(new_permission_ids, changed_by: Argus::Trail.config.changed_by_resolver.call) ⇒ Object
Diffs the requested permission ids against the role's current ones and writes one AuditEntry per addition/removal, so the audit log captures exactly which permissions were granted or revoked (not just "something changed").
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/argus/trail/role.rb', line 19 def (, changed_by: Argus::Trail.config.changed_by_resolver.call) new_ids = Array().map(&:to_i).reject(&:zero?) current_ids = added_ids = new_ids - current_ids removed_ids = current_ids - new_ids transaction do self. = new_ids Argus::Trail.config..where(id: added_ids).find_each do || ("permission_granted", , changed_by) end Argus::Trail.config..where(id: removed_ids).find_each do || ("permission_revoked", , changed_by) end end end |