mumukit-auth 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f582e482347dc9147657752b0307c6756d81b627
4
- data.tar.gz: 9a783d130d27f08a61fec39d6a34348c8355fb48
3
+ metadata.gz: 8fbc5aece9f1ceef11e2f32c4e1bb84a4644031b
4
+ data.tar.gz: 588bd33d6ba3f2d5e01e03242a461b67a369277e
5
5
  SHA512:
6
- metadata.gz: 7154ba40df463d0110b76c96d04cc335dc421db62e310b5788d78bd9712536b4606baeac7e4c1f75040ea600f8434152f4662f314636f72851eddc578b0a5cbb
7
- data.tar.gz: 9faa565b72369ff5213f3bd440b8c4f62726fdca9cddd423f33a513c335ad7c4e334d4be89783df03b18fe428bd160c9fd76973746ea6622c93103c2801bdaf4
6
+ metadata.gz: 56728c7d40f73f4f6a8a7c35189b355b72842d44fc2ab08ccce57b4bae7eeb5e180731ccb89e3bab3529a49734c723be4b6856d931a9c2f15917385e00df7d72
7
+ data.tar.gz: d6caaa9740b5ed65217ad769ffcfc6e42159454b5facfffd0250a63587f7236ddccd7d55053c7ec0393e478e19255f55873697f101eea1109cd119756fefd771
@@ -30,11 +30,15 @@ class Mumukit::Auth::Permissions
30
30
  end
31
31
 
32
32
  def add_permission!(role, *grants)
33
- scope_for(role)&.add_grant! *grants
33
+ scope_for(role).add_grant! *grants
34
+ end
35
+
36
+ def merge(other)
37
+ self.class.new(scopes.merge(other.scopes) { |_key, left, right| left.merge right})
34
38
  end
35
39
 
36
40
  def remove_permission!(role, grant)
37
- scope_for(role)&.remove_grant!(grant)
41
+ scope_for(role).remove_grant!(grant)
38
42
  end
39
43
 
40
44
  def update_permission!(role, old_grant, new_grant)
@@ -3,7 +3,8 @@ module Mumukit::Auth
3
3
  attr_accessor :grants
4
4
 
5
5
  def initialize(grants=[])
6
- @grants = grants
6
+ @grants = []
7
+ add_grant! *grants
7
8
  end
8
9
 
9
10
  def protect!(resource_slug)
@@ -15,7 +16,7 @@ module Mumukit::Auth
15
16
  end
16
17
 
17
18
  def add_grant!(*grants)
18
- self.grants.push *grants.map(&:to_mumukit_grant)
19
+ grants.each { |grant| push_and_compact! grant }
19
20
  end
20
21
 
21
22
  def remove_grant!(grant)
@@ -23,6 +24,10 @@ module Mumukit::Auth
23
24
  self.grants.delete(grant)
24
25
  end
25
26
 
27
+ def merge(other)
28
+ self.class.new grants + other.grants
29
+ end
30
+
26
31
  def to_s
27
32
  grants.map(&:to_s).join(':')
28
33
  end
@@ -44,5 +49,20 @@ module Mumukit::Auth
44
49
  def any_grant?(&block)
45
50
  @grants.any?(&block)
46
51
  end
52
+
53
+ def push_and_compact!(grant)
54
+ grant = grant.to_mumukit_grant
55
+ return if has_broader_grant? grant
56
+ remove_narrower_grants! grant
57
+ grants << grant
58
+ end
59
+
60
+ def remove_narrower_grants!(grant)
61
+ grants.reject! { |it| grant.allows? it }
62
+ end
63
+
64
+ def has_broader_grant?(grant)
65
+ grants.any? { |it| it.allows? grant }
66
+ end
47
67
  end
48
68
  end
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Auth
3
- VERSION = '3.2.0'
3
+ VERSION = '3.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumukit-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2016-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler