Class: Mumukit::Auth::Permissions::Diff
- Inherits:
-
Object
- Object
- Mumukit::Auth::Permissions::Diff
- Defined in:
- lib/mumuki/classroom/permissions_diff.rb
Instance Attribute Summary collapse
-
#changes ⇒ Object
Returns the value of attribute changes.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #changes_by_organization ⇒ Object
- #compare_grants!(role, some_permissions, another_permissions, change_type) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Diff
constructor
A new instance of Diff.
Constructor Details
#initialize ⇒ Diff
Returns a new instance of Diff.
47 48 49 |
# File 'lib/mumuki/classroom/permissions_diff.rb', line 47 def initialize @changes = [] end |
Instance Attribute Details
#changes ⇒ Object
Returns the value of attribute changes.
45 46 47 |
# File 'lib/mumuki/classroom/permissions_diff.rb', line 45 def changes @changes end |
Class Method Details
.diff(old_permissions, new_permissions) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mumuki/classroom/permissions_diff.rb', line 66 def self.diff(, ) return Mumukit::Auth::Permissions::Diff.new if .nil? = . = . new.tap do |it| Mumukit::Auth::Roles::ROLES.each do |role| it.compare_grants! role, , , :removed it.compare_grants! role, , , :added end end end |
Instance Method Details
#as_json(options = {}) ⇒ Object
79 80 81 |
# File 'lib/mumuki/classroom/permissions_diff.rb', line 79 def as_json( = {}) {changes: @changes}.as_json end |
#changes_by_organization ⇒ Object
51 52 53 |
# File 'lib/mumuki/classroom/permissions_diff.rb', line 51 def changes_by_organization changes.group_by(&:organization).with_indifferent_access end |
#compare_grants!(role, some_permissions, another_permissions, change_type) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/mumuki/classroom/permissions_diff.rb', line 59 def compare_grants!(role, , , change_type) .grants_for(role) .select { |grant| !.role_allows?(role, grant) } .each { |grant| changes << Change.new(role, grant, change_type) } end |
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/mumuki/classroom/permissions_diff.rb', line 55 def empty? changes.empty? end |