card-mod-permissions 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/set/all/permissions.rb +45 -52
  3. data/set/right/read.rb +13 -14
  4. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 443a944aa0813b46f7f712e8d309dcf1cf65fb621f2a16a2a3931788dc13013b
4
- data.tar.gz: 86ef98147edad0eed532e3a4c4307bf15368b763b83b41da39fdfff19981f47a
3
+ metadata.gz: 0f6078e690d49effad8b5e8dcc2c17b5c25360612b183c9958eb3403e7ee468c
4
+ data.tar.gz: 7bb9710db77010d387df7d73f7fed189c9ed25e3370aeb560d03e4646f6eb98e
5
5
  SHA512:
6
- metadata.gz: efdb829467f04d220efecbc5cee7cd5133c778616e9c5fb7ac60b0de68ba9b8f4081ae68cf89bf7782e3915c129f436893d1c799f73bfd46dc5c826cb39704f3
7
- data.tar.gz: 531fb7979d8696002843ae28999a49ea9c8eb4427f75b6ee0379b04b29a518b2289043848f5bcb546f763f105d14522a15f2bee71d88a205cd3b652c2faf8b4f
6
+ metadata.gz: 738ab74454596e1bfcdeafdf4c6047c2f1b5e8c135a8bcf830e2baa3825d6b467606b7d05d923d22cfbaf762198c027fdb793fe379b5ddd66a457316309ce4db
7
+ data.tar.gz: 2629efb0acb72b37e51235f917dc38a60cab7b489254b516de311426b4214307746d00e16a159cf5553793f662523f26ba426713a82671af8516fcb0ecdf79d4
@@ -1,16 +1,28 @@
1
- module ClassMethods
2
- def repair_all_permissions
3
- Card.where("(read_rule_class is null or read_rule_id is null) and trash is false")
4
- .each do |broken_card|
5
- broken_card.include_set_modules
6
- broken_card.repair_permissions!
7
- end
1
+ event :set_read_rule, :store, on: :save, changed: %i[type_id name] do
2
+ read_rule_id, read_rule_class = permission_rule_id_and_class(:read)
3
+ self.read_rule_id = read_rule_id
4
+ self.read_rule_class = read_rule_class
5
+ end
6
+
7
+ event :set_field_read_rules, after: :set_read_rule, on: :update, changed: :type_id do
8
+ each_field_as_bot(&:update_read_rule)
9
+ end
10
+
11
+ event :update_read_rule do
12
+ without_timestamps do
13
+ reset_patterns # why is this needed?
14
+ set_read_rule
15
+ Card.where(id: id).update_all read_rule_id: read_rule_id,
16
+ read_rule_class: read_rule_class
17
+ expire :shared
18
+ update_field_read_rules
8
19
  end
9
20
  end
10
21
 
11
- def repair_permissions!
12
- rule_id, rule_class = permission_rule_id_and_class :read
13
- update_columns read_rule_id: rule_id, read_rule_class: rule_class
22
+ event :check_permissions, :validate do
23
+ track_permission_errors do
24
+ ok? action_for_permission_check
25
+ end
14
26
  end
15
27
 
16
28
  # ok? and ok! are public facing methods to approve one action at a time
@@ -21,8 +33,6 @@ end
21
33
  # trait: :account would fetch this card plus a tag codenamed :account
22
34
  # trait: :roles, new: {} would initialize a new card with default ({})
23
35
  # options.
24
- #
25
- #
26
36
 
27
37
  def ok? action
28
38
  @ok ||= {}
@@ -42,12 +52,6 @@ def anyone_can? action
42
52
  who_can(action).include? AnyoneID
43
53
  end
44
54
 
45
- def direct_rule_card action
46
- direct_rule_id = rule_card_id action
47
- require_permission_rule! direct_rule_id, action
48
- Card.quick_fetch direct_rule_id
49
- end
50
-
51
55
  def permission_rule_id action
52
56
  if compound? && rule(action).match?(/^\[?\[?_left\]?\]?$/)
53
57
  left_permission_rule_id action
@@ -159,16 +163,6 @@ end
159
163
  # self.read_rule_id = self.read_rule_class = nil
160
164
  # end
161
165
 
162
- event :set_read_rule, :store, on: :save, changed: %i[type_id name] do
163
- read_rule_id, read_rule_class = permission_rule_id_and_class(:read)
164
- self.read_rule_id = read_rule_id
165
- self.read_rule_class = read_rule_class
166
- end
167
-
168
- event :set_field_read_rules, after: :set_read_rule, on: :update, changed: :type_id do
169
- each_field_as_bot(&:update_read_rule)
170
- end
171
-
172
166
  def update_field_read_rules
173
167
  return unless type_id_changed? || read_rule_id_changed?
174
168
 
@@ -186,6 +180,13 @@ def each_field_as_bot &block
186
180
  end
187
181
  end
188
182
 
183
+ def repair_permissions!
184
+ rule_id, rule_class = permission_rule_id_and_class :read
185
+ update_columns read_rule_id: rule_id, read_rule_class: rule_class
186
+ end
187
+
188
+ private
189
+
189
190
  def without_timestamps
190
191
  Card.record_timestamps = false
191
192
  yield
@@ -193,30 +194,6 @@ ensure
193
194
  Card.record_timestamps = true
194
195
  end
195
196
 
196
- event :update_read_rule do
197
- without_timestamps do
198
- reset_patterns # why is this needed?
199
- rcard_id, rclass = permission_rule_id_and_class :read
200
- # these two are just to make sure vals are correct on current object
201
- self.read_rule_id = rcard_id
202
- self.read_rule_class = rclass
203
- Card.where(id: id).update_all read_rule_id: rcard_id, read_rule_class: rclass
204
- expire :hard
205
- # binding.pry if field_cards.include? nil
206
- update_field_read_rules
207
- end
208
- end
209
-
210
- def add_to_read_rule_update_queue updates
211
- @read_rule_update_queue = Array.wrap(@read_rule_update_queue).concat updates
212
- end
213
-
214
- event :check_permissions, :validate do
215
- track_permission_errors do
216
- ok? action_for_permission_check
217
- end
218
- end
219
-
220
197
  def action_for_permission_check
221
198
  commenting? ? :update : action
222
199
  end
@@ -228,3 +205,19 @@ def track_permission_errors
228
205
  @permission_errors = nil
229
206
  result
230
207
  end
208
+
209
+ def direct_rule_card action
210
+ direct_rule_id = rule_card_id action
211
+ require_permission_rule! direct_rule_id, action
212
+ Card.quick_fetch direct_rule_id
213
+ end
214
+
215
+ module ClassMethods
216
+ def repair_all_permissions
217
+ Card.where("(read_rule_class is null or read_rule_id is null) and trash is false")
218
+ .each do |broken_card|
219
+ broken_card.include_set_modules
220
+ broken_card.repair_permissions!
221
+ end
222
+ end
223
+ end
data/set/right/read.rb CHANGED
@@ -5,11 +5,24 @@ assign_type :list
5
5
  format :html do include Abstract::Permission::HtmlFormat end
6
6
 
7
7
  event :cascade_read_rule, :finalize, after: :update_rule_cache, when: :rule? do
8
+ # left&.update_lexicon
8
9
  return unless name_is_changing? || trash_is_changing?
9
10
 
10
11
  update_read_ruled_cards
11
12
  end
12
13
 
14
+ def rule_pattern_index
15
+ return if trash
16
+
17
+ @rule_pattern_index ||= pattern_index rule_set&.tag&.id
18
+ end
19
+
20
+ def pattern_index pattern_id
21
+ Pattern.ids.index(pattern_id) || invalid_pattern_id(pattern_id)
22
+ end
23
+
24
+ private
25
+
13
26
  def update_read_ruled_cards
14
27
  Card::Rule.clear_read_rule_cache
15
28
  Card.cache.reset # maybe be more surgical, just Auth.user related
@@ -57,20 +70,6 @@ def all_members
57
70
  rule_set.item_cards limit: 0
58
71
  end
59
72
 
60
- def rule_pattern_index
61
- return if trash
62
-
63
- @rule_pattern_index ||= pattern_index rule_set&.tag&.id
64
- end
65
-
66
- def pattern_index pattern_id
67
- Pattern.ids.index(pattern_id) || invalid_pattern_id(pattern_id)
68
- end
69
-
70
73
  def invalid_pattern_id pattern_id
71
74
  Rails.logger.info "invalid pattern id for read rule: #{pattern_id}"
72
75
  end
73
-
74
- event :process_read_rule_update_queue, :finalize do
75
- left&.update_read_rule
76
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-permissions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-06-12 00:00:00.000000000 Z
13
+ date: 2024-10-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.107.0
21
+ version: 1.108.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.107.0
28
+ version: 1.108.0
29
29
  description: ''
30
30
  email:
31
31
  - info@decko.org
@@ -55,7 +55,7 @@ files:
55
55
  - set/self/update.rb
56
56
  homepage: https://decko.org
57
57
  licenses:
58
- - GPL-3.0
58
+ - GPL-3.0-or-later
59
59
  metadata:
60
60
  source_code_uri: https://github.com/decko-commons/decko
61
61
  homepage_uri: https://decko.org
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.5.10
82
+ rubygems_version: 3.5.7
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: decko permissions