mikras_utils 0.10.1 → 0.12.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: 664cc0291b18e0f9068704c14f3e65adb808c099510b0334684a3b5a13a0d83a
4
- data.tar.gz: 1e372dae3fb50ada2eb071a5d4b679777cb159b43db1e71a343e02802f279771
3
+ metadata.gz: c16e80939523ecb0aaaf1c5bcc688f78868fc3074e9baf59f33376b119048816
4
+ data.tar.gz: 1d8ff5f5f1b5cf67841f6e21737b31bb12b3d5ed5f0813694e403450b5c9324f
5
5
  SHA512:
6
- metadata.gz: 195f1c258a5e54092eae258420f850b8719ea7bc3e2d5ebbba3ffb2cf8ec813d008dc0e0ba8263f0383064914c0dc96267c7652b5a052008c307824c2f76bca2
7
- data.tar.gz: 5827e7fdaa3d2888b341b4a1d70d4d2a42b3890ab00b090747556e3a85d8b459418a3b669302b6ed53b7392911680f833e5c01938831182f9ecfe02627bcdf7f
6
+ metadata.gz: 83cf23edadfd58d6aa08af29bf832146f7860924d9a2899f69473e82431d8bf2bbfb0707f375d3c11a0947830cde968c3481e04cdb92e2928306d21cd60b256d
7
+ data.tar.gz: 9520bc10e0e990be7d5a17efba03682881396b4ab6928a06dea92357213abe430d06af02705090c561d8a2b00eca6faeda2e6a06bebb78c8fadcfe59fa63c1a2
@@ -21,6 +21,7 @@ module MkAcl
21
21
  private
22
22
  def clean_tables
23
23
  puts %(
24
+ delete from acl_portal.acl_timestamps;
24
25
  delete from acl_portal.acl_rules;
25
26
  delete from acl_portal.acl_actions;
26
27
  delete from acl_portal.acl_tables;
@@ -57,10 +58,11 @@ module MkAcl
57
58
  puts
58
59
 
59
60
  action.rules.each { |rule|
60
- fields = %w(roles filter assert fields tables ordinal)
61
+ fields = %w(roles filter assert mutation fields tables ordinal)
61
62
  values = fields.map { |field| conn.quote_value(rule.send(field.to_sym), elem_type: :text) }
62
63
  puts %(
63
- insert into acl_portal.acl_rules (acl_action_id, roles, filter, assert, fields, tables, ordinal)
64
+ insert into acl_portal.acl_rules (
65
+ acl_action_id, roles, filter, assert, mutation, fields, tables, ordinal)
64
66
  values (:action_id, #{values.join(', ')});
65
67
  ).align
66
68
  puts
@@ -68,8 +70,13 @@ module MkAcl
68
70
 
69
71
  action.timestamps.each { |timestamp|
70
72
  puts %(
71
- insert into acl_portal.acl_timestamps (action_id, watch, stamp)
72
- values (:action_id, #{conn.quote_value(timestamp.watch)}, '#{timestamp.stamp}');
73
+ insert into acl_portal.acl_timestamps (action_id, watch, assign, stamp)
74
+ values (
75
+ :action_id,
76
+ #{conn.quote_value(timestamp.watch)},
77
+ #{conn.quote_value(timestamp.assign)},
78
+ #{conn.quote_value(timestamp.stamp)}
79
+ );
73
80
  ).align
74
81
  puts
75
82
  }
@@ -59,6 +59,7 @@ module MkAcl
59
59
  constrain?(action_name, :insert, :select, :update, :delete, :attach, :detach) or
60
60
  error "Illegal action '#{action_name}'"
61
61
 
62
+ # real_action_names break :attach into both :attach and :detach
62
63
  for real_action_name in (action_name == :attach ? [:attach, :detach] : [action_name])
63
64
  constrain?(entries, String, Array, Hash) or
64
65
  error "Illegal value for #{action_name} entry '#{entries}'"
@@ -72,6 +73,7 @@ module MkAcl
72
73
  when String
73
74
  entries = [{ roles: entries }]
74
75
  when Array
76
+ # Arrays can't specify mutations (for now)
75
77
  entries.reject! { |element|
76
78
  timestamps = element.delete(:timestamps) and parse_timestamps(action, timestamps)
77
79
  }
@@ -88,14 +90,23 @@ module MkAcl
88
90
  case timestamps
89
91
  when String
90
92
  timestamps.split.each { |watch_field|
91
- Timestamp.new(table, watch_field)
93
+ case watch_field
94
+ when /^(.*)(?:_by_id|_to_id)$/
95
+ Timestamp.new(table, watch_field, nil, "#{$1}_at")
96
+ when /^(created|updated|deleted)_at$/
97
+ Timestamp.new(table, nil, "#{$1}_by_id", watch_field)
98
+ else
99
+ raise ArgumentError, "Illegal timestamp specifier: #{watch_field.inspect}"
100
+ end
92
101
  }
102
+
93
103
  when Array
94
104
  for entry in timestamps
95
105
  timestamp = Timestamp.new(table)
96
106
  for key, value in entry
97
107
  case key
98
108
  when :watch; timestamp.watch = value
109
+ when :assign; timestamp.assign = value
99
110
  when :stamp; timestamp.stamp = value
100
111
  else
101
112
  error "Illegal field '#{key}' in #{table} timestamps"
@@ -118,6 +129,7 @@ module MkAcl
118
129
  when :roles; rule.roles = norm_array(value)
119
130
  when :filter; rule.filter = norm_value(value)
120
131
  when :assert; rule.assert = norm_value(value)
132
+ when :mutation; rule.mutation = value.nil? ? nil : norm_value(value)
121
133
  when :fields; rule.fields = value.nil? ? nil : norm_array(value)
122
134
  when :tables; rule.tables = norm_array(value)
123
135
  else
@@ -131,4 +143,27 @@ module MkAcl
131
143
  end
132
144
  end
133
145
  end
146
+
147
+ #def declare_record(name, array_arg = nil, &record_
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
134
169
 
@@ -1,5 +1,7 @@
1
1
 
2
2
  module MkAcl
3
+ DEFAULT_MUTATION = "app_portal.mutate"
4
+
3
5
  class Spec
4
6
  # Source SPEC file. Only for informational purposes
5
7
  attr_reader :file
@@ -188,24 +190,16 @@ module MkAcl
188
190
  attr_reader :action
189
191
  forward_to :action, :table, :name
190
192
  attr_accessor :watch
193
+ attr_accessor :assign
191
194
  attr_accessor :stamp
192
195
 
193
- def created_at?() = watch == "insert"
194
- def updated_at?() = watch == "update"
195
- def deleted_at?() = watch == "delete"
196
+ # def created_at?() = watch == "insert"
197
+ # def updated_at?() = watch == "update"
198
+ # def deleted_at?() = watch == "delete"
196
199
 
197
- def initialize(action, watch = nil, stamp = nil)
200
+ def initialize(action, watch = nil, assign = nil, stamp = nil)
198
201
  @action = action
199
-
200
- case watch
201
- when /^(.*)(?:_by_id|_to_id)$/
202
- @watch, @stamp = watch, stamp || "#{$1}_at"
203
- when "created_at", "updated_at", "deleted_at"
204
- @watch, @stamp = nil, watch
205
- else
206
- @watch, @stamp = watch, stamp
207
- end
208
-
202
+ @watch, @assign, @stamp = watch, assign, stamp
209
203
  action.send :attach_timestamp, self
210
204
  end
211
205
 
@@ -213,6 +207,7 @@ module MkAcl
213
207
 
214
208
  def dump
215
209
  puts "watch: #{watch}"
210
+ puts "watch: #{assign}"
216
211
  puts "stamp: #{stamp}"
217
212
  end
218
213
  end
@@ -225,6 +220,7 @@ module MkAcl
225
220
  attr_accessor :roles # Roles that this rule applies to
226
221
  attr_accessor :filter # Goes into the postgres policy, may be nil
227
222
  attr_accessor :assert # Goes into the postgres trigger, may be nil
223
+ attr_accessor :mutation # Mutation function to use, may be nil. Default app_portal.mutate()
228
224
  attr_accessor :fields # Only used for insert and update, nil otherwise
229
225
  attr_accessor :tables # Only used for attach and detach, nil otherwise
230
226
  attr_reader :ordinal
@@ -241,6 +237,7 @@ module MkAcl
241
237
  @roles = []
242
238
  @filter = nil
243
239
  @assert = nil
240
+ @mutation = DEFAULT_MUTATION
244
241
  @fields = %w(insert update).include?(action.name) ? [] : nil
245
242
  @tables = %w(attach).include?(action.name) ? [] : nil
246
243
 
@@ -251,6 +248,7 @@ module MkAcl
251
248
  puts "roles: [#{roles.join(' ')}]"
252
249
  puts "filter: #{filter}" if filter
253
250
  puts "assert: #{assert}" if assert
251
+ puts "mutation: #{mutation || 'nil'}" if mutation != DEFAULT_MUTATION
254
252
  puts "fields: [#{fields.join(' ')}]" if fields && !fields.empty?
255
253
  puts "tables: [#{tables.join(' ')}]" if tables && !tables.empty?
256
254
  puts "ordinal: #{ordinal}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MikrasUtils
4
- VERSION = "0.10.1"
4
+ VERSION = "0.12.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikras_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-06 00:00:00.000000000 Z
11
+ date: 2025-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg_conn