shark-permissions-core 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: c8fe97d4806a76b363e8b8654cda1df78b26c2a81272d8592f2e457e203a2b34
4
- data.tar.gz: 7e50f496ab65ca30fabbea8f2bf69b3a98ca65f0ec2a159ae353075a5cddd36e
3
+ metadata.gz: aa785346b047b8a08e057ecdd18d197e5d308b478fadb7515507f6c86e8e6cd1
4
+ data.tar.gz: a543fe0cf713c913755cfc68a51018dedb5ff8178c9243bd3151df00b111c484
5
5
  SHA512:
6
- metadata.gz: 24a28fc4b1420a52f9b0083b92b704c28cb957f23248014d1f989385e5c97569373d902477f80924e819439e388bfa2cbeff238feb3de40f3ca391493a222de2
7
- data.tar.gz: 9ae791ae0f3766df9a0d0e96839104ce10097b70f002fe8e5ad6d5f53d8fa56483b6a1cfcb0c649f68634317cf5f00c1ecd364815368a33c1c1060fd9a9850ae
6
+ metadata.gz: 34898960845052d163f20a0816f5de43155a622c0d6c215670caa73388328eaa124f1aa480fb0313d9877c07a3bfbbab21643410d4954d7f2a0c7df2016f5e23
7
+ data.tar.gz: 3613657948b015a35f3b5da853b48ac60f40e63c7ce7e91ce5376ef7f36d8086cca26df4e72b95db5dd0ca3db21a18dbbc61dfc99ca99cdb5ba91c30aa2c889c
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
  ## Changelog
2
2
 
3
+ #### 0.2.0
4
+ - [fix] `Permissions::List`: rename `#merge!` to `Permissions::List#update`
5
+ - [fix] `Permissions::List`: add original `#merge!` implementation from `bima-doorkeeper-rails`
6
+
3
7
  #### 0.1.0
4
8
  - initial
@@ -24,8 +24,16 @@ module Shark
24
24
  @privileges[:new][key] = new_value
25
25
  end
26
26
 
27
+ # @return [Boolean]
28
+ # @api public
29
+ def empty?
30
+ effect.empty? && privileges.empty?
31
+ end
32
+
33
+ # @return [Boolean]
34
+ # @api public
27
35
  def present?
28
- @effect.present? || privileges.present?
36
+ !empty?
29
37
  end
30
38
  end
31
39
  end
@@ -107,14 +107,42 @@ module Shark
107
107
  self.class.new(filtered_rules)
108
108
  end
109
109
 
110
+ # @param other_list [Shark::Permissions::List]
111
+ # @return [Hash]
112
+ # @api public
110
113
  def merge(other_list)
111
114
  clone.merge!(other_list)
112
115
  end
113
116
 
117
+ # Merges another list into this list. Allowed privileges are not removed.
118
+ # Changes are not tracked.
119
+ #
120
+ # @param other_list [Shark::Permissions::List]
121
+ # @return [Hash]
122
+ # @api public
114
123
  def merge!(other_list)
115
- other_list.each do |key, other_rule|
116
- rules[key] = Permissions::Rule.new(resource: key) unless rules.key?(key)
117
- rules[key].update(other_rule)
124
+ other_list.each do |resource, rule|
125
+ if rules.key?(resource)
126
+ privileges = rules[resource].privileges
127
+ rule.privileges.each { |k, v| privileges[k] = privileges[k] || v }
128
+ else
129
+ rules[resource] = rule.clone
130
+ end
131
+ end
132
+
133
+ self
134
+ end
135
+
136
+ # Updates this list with rules from another list.
137
+ # All affected rules are updated and changes are tracked.
138
+ #
139
+ # @param other_list [Shark::Permissions::List]
140
+ # @return [Hash]
141
+ # @api public
142
+ def update(other_list)
143
+ other_list.each do |resource, other_rule|
144
+ rules[resource] = Permissions::Rule.new(resource: resource) unless rules.key?(resource)
145
+ rules[resource].update(other_rule)
118
146
  end
119
147
 
120
148
  self
@@ -62,9 +62,7 @@ module Shark
62
62
  # @return Boolean
63
63
  # @api public
64
64
  def ==(other)
65
- resource == other.resource &&
66
- effect == other.effect &&
67
- privileges == other.privileges
65
+ resource == other.resource && effect == other.effect && privileges == other.privileges
68
66
  end
69
67
 
70
68
  def as_json(*_args)
data/lib/shark/version.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Shark
4
4
  module Permissions
5
5
  module Core
6
- VERSION = '0.1.0'
6
+ VERSION = '0.2.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shark-permissions-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joergen Dahlke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-02 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport