mumukit-auth 7.5.2 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a233658a7f1e3cfb135b4a483349e9fe38e20d92a5bf8a97040ccc618640c077
4
- data.tar.gz: 0664fea5f198d4870f21c681f1e42e36df4d4081735e4844edc0891211ffe5a2
3
+ metadata.gz: 6e2864d6f9f4aa09030ed3d4a71f1235edb1e3d96ab88d519d1abdc57eede221
4
+ data.tar.gz: 4184f9c764bd8d54d9c93351fbf0f087df2086cd69ec7244d21a9f1031ee95f0
5
5
  SHA512:
6
- metadata.gz: 836d44fcc5880cbc22268a9705e4f4d5a9f77256d7de7a84851356ce7da06daf5b5da0bea28b56a7aebabd1b89109b9e556e6af728ea6edbb923cc13e67e8d37
7
- data.tar.gz: d8860943ad2c1da1190189664deaeb73681abf3543c93e219b7c563eb1c27d998954678ef70da2de6b7c22e4332115af612b7aea31db325b27d08aba10e9ebef
6
+ metadata.gz: d6a0ee484b131da39f8590d58973f98193e05f55e958326f299602e5e97c91882132ba69116f6e96ad5a7d25994c2cd4b527779f697e237a022f43197ffe8367
7
+ data.tar.gz: 0a4f659f95f3592ae4c26b286fd58c58869f071907c3ead1df0f979b5b8ea1a4b04fd6078346b3814f50d3b847eb9791dc0adc8dd01c1265a99a740e8ce0e277
@@ -59,11 +59,11 @@ module Mumukit::Auth
59
59
 
60
60
  class FirstPartGrant < Grant
61
61
  def initialize(first)
62
- @first = first.downcase
62
+ @first = first.parameterize
63
63
  end
64
64
 
65
65
  def allows?(resource_slug)
66
- resource_slug.to_mumukit_slug.match_first @first
66
+ resource_slug.to_mumukit_slug.normalize!.match_first @first
67
67
  end
68
68
 
69
69
  def to_s
@@ -77,16 +77,16 @@ module Mumukit::Auth
77
77
 
78
78
  class SingleGrant < Grant
79
79
  def initialize(slug)
80
- @slug = slug
80
+ @slug = slug.normalize
81
81
  end
82
82
 
83
83
  def allows?(resource_slug)
84
- resource_slug = resource_slug.to_mumukit_slug
84
+ resource_slug = resource_slug.to_mumukit_slug.normalize!
85
85
  resource_slug.match_first(@slug.first) && resource_slug.match_second(@slug.second)
86
86
  end
87
87
 
88
88
  def to_s
89
- @slug.to_case_insensitive_s
89
+ @slug.to_s
90
90
  end
91
91
 
92
92
  def to_mumukit_slug
@@ -28,8 +28,21 @@ class Mumukit::Auth::Permissions
28
28
  self.scopes[role] ||= Mumukit::Auth::Scope.new
29
29
  end
30
30
 
31
+ # Deprecated: use `student_granted_organizations` organizations instead
31
32
  def accessible_organizations
32
- scope_for(:student)&.grants&.map { |grant| grant.to_mumukit_slug.organization }.to_set
33
+ warn "Don't use accessible_organizations, since this method is probably not doing what you would expect.\n" +
34
+ "Use student_granted_organizations if you still need its behaviour"
35
+ student_granted_organizations
36
+ end
37
+
38
+ # Answers the organizations for which the user has been explicitly granted acceses as student.
39
+ # This method does not include the organizations the user has access because of the roles hierarchy
40
+ def student_granted_organizations
41
+ granted_organizations_for :student
42
+ end
43
+
44
+ def granted_organizations_for(role)
45
+ scope_for(role)&.grants&.map { |grant| grant.to_mumukit_slug.organization }.to_set
33
46
  end
34
47
 
35
48
  def add_permission!(role, *grants)
@@ -23,11 +23,11 @@ module Mumukit::Auth
23
23
  end
24
24
 
25
25
  def match_first(first)
26
- match self.first.downcase, first.downcase
26
+ match self.first, first
27
27
  end
28
28
 
29
29
  def match_second(second)
30
- match self.second.downcase, second.downcase
30
+ match self.second, second
31
31
  end
32
32
 
33
33
  def rebase(new_organizaton)
@@ -35,21 +35,29 @@ module Mumukit::Auth
35
35
  end
36
36
 
37
37
  def ==(o)
38
- self.class == o.class && to_case_insensitive_s == o.to_case_insensitive_s
38
+ self.class == o.class && self.normalize.eql?(o.normalize)
39
39
  end
40
40
 
41
- alias_method :eql?, :==
41
+ def eql?(o)
42
+ self.class == o.class && to_s == o.to_s
43
+ end
42
44
 
43
45
  def hash
44
- to_case_insensitive_s.hash
46
+ to_s.hash
45
47
  end
46
48
 
47
49
  def to_s
48
50
  "#{first}/#{second}"
49
51
  end
50
52
 
51
- def to_case_insensitive_s
52
- @case_insensitive_s ||= to_s.downcase
53
+ def normalize!
54
+ @first = @first.parameterize
55
+ @second = @second.parameterize
56
+ self
57
+ end
58
+
59
+ def normalize
60
+ dup.normalize!
53
61
  end
54
62
 
55
63
  def inspect
@@ -90,6 +98,10 @@ module Mumukit::Auth
90
98
  parse '_/_'
91
99
  end
92
100
 
101
+ def self.normalize(first, second)
102
+ new(first, second).normalize!
103
+ end
104
+
93
105
  private
94
106
 
95
107
  def match(pattern, part)
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Auth
3
- VERSION = '7.5.2'
3
+ VERSION = '7.6.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: 7.5.2
4
+ version: 7.6.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: 2019-01-29 00:00:00.000000000 Z
11
+ date: 2019-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler