mikras_utils 0.3.0 → 0.3.2

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: '039c1d561f66158183511f72a09ce9b76b3de0c7110d8e6aadce11b338985209'
4
- data.tar.gz: dae3de2a17dd845f6a350ec3b63636e97ff2b565a75d40bd47e429abe5654668
3
+ metadata.gz: 356975b3f96e8341dba97e96ca170a0fb181c3c8654bc874300144774094daba
4
+ data.tar.gz: 5cb71f7c6add1f89ca5025bcc9630a58474055516295e50d9ad6a2386cf6eb84
5
5
  SHA512:
6
- metadata.gz: 4651ae8fc80806930718c561c94ae10547d80654802cb88f19020b020871d5de73cd4b736ad98755f63333f8262c44a438ab6134d87d9f51989d68e5ed1bee43
7
- data.tar.gz: 05a47f398922d45c61e3746c28a5fae17a334e38c9a7eb4a35dbdd4764d4d86dcd57b293fa14b6600e80da5f54b26a65aada13e3679ed56aa670107b457e4ebf
6
+ metadata.gz: 74ba9b96d512f831d0dd1a691d1c6892447ac21f29fe91a1f62a5cd87dfefda93d95229c16ddd063ff6bfe3ae1782ea44bda0189eedf7cf757ee7ab5825e9497
7
+ data.tar.gz: 1d5a378eddd2900ef31cfcd908bdcdd4f780eaf89a162946bdf445429ef076a8fee43e2b5b7709f3fbc2852f166f43983a4b87064f59574674f64cded967e0de
@@ -101,7 +101,7 @@ module MkAcl
101
101
  case_roles = rule.roles.select { _1 == _1.upcase }
102
102
 
103
103
  if !auth_roles.empty?
104
- role_seq = conn.quote_value_seq(auth_roles)
104
+ role_seq = conn.quote_values(auth_roles)
105
105
  puts %(
106
106
  -- Find "#{action}" system role ACLs
107
107
  _acls := array[]::integer[];
@@ -114,7 +114,7 @@ module MkAcl
114
114
  end
115
115
 
116
116
  if !case_roles.empty?
117
- role_seq = conn.quote_value_seq(case_roles)
117
+ role_seq = conn.quote_values(case_roles)
118
118
  puts %(
119
119
  -- Find "#{action}" case role ACLs
120
120
  select _acls || array_agg(id)
@@ -151,8 +151,8 @@ module MkAcl
151
151
  # Insert a attach record per parent table. This snippet handles
152
152
  # multiple parents of a record but the check algorithm probably does
153
153
  # not TODO
154
- auth_role_list = conn.quote_value_seq table.insert.rules.map(&:auth_roles).flatten
155
- case_role_list = conn.quote_value_seq table.insert.rules.map(&:case_roles).flatten
154
+ auth_role_list = conn.quote_values table.insert.rules.map(&:auth_roles).flatten
155
+ case_role_list = conn.quote_values table.insert.rules.map(&:case_roles).flatten
156
156
  for parent in table.parents
157
157
  id_fields = conn.values %(select column_name from acl.links where table_name = '#{table}')
158
158
  for id_field in id_fields
@@ -9,7 +9,7 @@ module MkAcl
9
9
 
10
10
  # Map from domain table to list of [table, path, links] tuples. The
11
11
  # entries describes the SQL link chain from the table to the given domain
12
- # table (cases or events)
12
+ # table (cases, events, or visits)
13
13
  attr_reader :chains
14
14
 
15
15
  def initialize(generator)
@@ -30,7 +30,7 @@ module MkAcl
30
30
  meta.chains
31
31
  where src_schema_name = '#{app_schema}'
32
32
  and dst_schema_name = '#{app_schema}'
33
- and dst_table_name in ('cases', 'events')
33
+ and dst_table_name in (#{conn.quote_values(DOMAIN_TABLES)})
34
34
  )
35
35
 
36
36
  generate_per_table_id_functions
@@ -45,10 +45,10 @@ module MkAcl
45
45
  # def table_seq() @table_seq ||= spec.tables.map(&:uid).join(', ') end
46
46
 
47
47
  # Generate a set of per-table functions that returns the associated
48
- # case_id/event_id for the given record. The Functions are generated for
49
- # each table in the spec file
48
+ # case_id/event_id/vist_id for the given record. The Functions are
49
+ # generated for each table in the spec file
50
50
  #
51
- # The geneated functions are
51
+ # The geneated functions are
52
52
  #
53
53
  # case_id_of_RECORD(id integer)
54
54
  # event_id_of_RECORD(id integer)
@@ -72,7 +72,7 @@ module MkAcl
72
72
  #
73
73
  def generate_per_table_id_functions
74
74
  # Generate functions by domain
75
- for domain in %w(case event)
75
+ for domain in DOMAINS
76
76
 
77
77
  # Create the identity functions first. The identity functions are
78
78
  # case_id_of_case() and event_id_of_event(). This makes some stuff
@@ -95,7 +95,7 @@ module MkAcl
95
95
  record_name = Prick::Inflector.singularize(table_name)
96
96
  id_arg = "_#{id_field}"
97
97
  signature = "#{acl_schema}.#{id_field}_of_#{record_name}(#{id_arg} integer)"
98
- puts "drop function if exists #{signature} cascade;"
98
+ puts "drop function if exists #{signature} cascade;"
99
99
  puts "create function #{signature} returns integer as $$"
100
100
  indent {
101
101
  tables.pop
@@ -120,14 +120,17 @@ module MkAcl
120
120
  end
121
121
  end
122
122
 
123
+ # Tables that references visits, events, and cases
124
+ visit_tables = chains['visits'].map(&:first)
125
+
123
126
  # Tables that references events and cases
124
- event_tables = chains['events'].map(&:first)
127
+ event_tables = chains['events'].map(&:first) - visit_tables
125
128
 
126
- # Tables that references only cases
129
+ # Tables that references only cases
127
130
  case_tables = chains['cases'].map(&:first) - event_tables
128
131
 
129
132
  # Create domain functions
130
- for domain, tables in { case: case_tables, event: event_tables }
133
+ for domain, tables in { case: case_tables, event: event_tables, visit: visit_tables }
131
134
  for table_name in tables
132
135
  record_name = Prick::Inflector.singularize(table_name)
133
136
  signature = "#{acl_schema}.domain_id_of_#{record_name}(_id integer)"
@@ -154,7 +157,7 @@ module MkAcl
154
157
  # specialized versions above
155
158
  #
156
159
  def generate_general_id_functions
157
- for domain in %w(case event)
160
+ for domain in DOMAINS
158
161
  domain_table = Prick::Inflector.pluralize(domain)
159
162
  field = "#{domain}_id"
160
163
  signature = "#{acl_schema}.#{field}_of(_table varchar, _id integer)"
@@ -162,7 +165,7 @@ module MkAcl
162
165
  puts %(
163
166
  drop function if exists #{signature} cascade;
164
167
  create function #{signature} returns integer as $$
165
- select
168
+ select
166
169
  ).align
167
170
  indent(2) {
168
171
  puts "case _table"
@@ -174,6 +177,7 @@ module MkAcl
174
177
  end
175
178
  puts "when 'cases' then _id"
176
179
  puts "when 'events' then _id"
180
+ puts "when 'visits' then _id"
177
181
  puts "else null"
178
182
  }
179
183
  puts "end case;"
@@ -187,7 +191,11 @@ module MkAcl
187
191
  -- FIXME: Ugly implementation
188
192
  drop function if exists #{signature} cascade;
189
193
  create function #{signature} returns integer as $$
190
- select coalesce(acl_portal.event_id_of(_table, _id), acl_portal.case_id_of(_table, _id));
194
+ select coalesce(
195
+ acl_portal.visit_id_of(_table, _id),
196
+ acl_portal.event_id_of(_table, _id),
197
+ acl_portal.case_id_of(_table, _id)
198
+ );
191
199
  $$ language sql;
192
200
  ).align
193
201
  puts
@@ -199,8 +207,8 @@ module MkAcl
199
207
  # event_id_of(r record)
200
208
  # domain_id_of(r record)
201
209
  #
202
- # Returns the case or event id associated with the given record. The
203
- # record should be an ACL table record type
210
+ # Returns the case, event, or visit id associated with the given record.
211
+ # The record should be an ACL table record type
204
212
  #
205
213
  # Very useful in before insert triggers because it takes a record (eg.
206
214
  # NEW) instead of an ID
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MikrasUtils
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.2"
5
5
  end
@@ -1,8 +1,10 @@
1
1
 
2
+ drop function if exists public.current_role_ids() cascade;
3
+ drop function if exists public.current_domain_roles(integer) cascade;
4
+
2
5
  -- Returns an array of role IDs for the current user (from both auth and
3
6
  -- app_portal). This array is matched against the relevant ACL field in the RLS
4
7
  -- policies so performance is important (TODO)
5
- drop function if exists public.current_role_ids() cascade;
6
8
  create function public.current_role_ids() returns integer[] as $$
7
9
  select acl_portal.select_user_acl(public.current_user_id());
8
10
  $$ language sql
@@ -13,7 +15,6 @@ $$ language sql
13
15
 
14
16
  -- Returns an array of app_portal role names (kind) for the current user in the
15
17
  -- given domain
16
- drop function if exists public.current_domain_roles(integer) cascade;
17
18
  create function public.current_domain_roles(_domain_id integer) returns text[] as $$
18
19
  select coalesce(array_agg(dr.role), array[]::text[])
19
20
  from acl_portal.domain_users du
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.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-15 00:00:00.000000000 Z
11
+ date: 2024-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg_conn