mikras_utils 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mikras_utils/mkacl/generators/id_functions.rb +23 -15
- data/lib/mikras_utils/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c7d48444e75236d0188b539182a80aefeaea2770cdf7982188d7f055c8b552e
|
4
|
+
data.tar.gz: 5d790361a1c314d7bda6013c1db9c904b50c81f3be39c8396d6c9e4da43e68bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e117ef1b45f0217ec14065d37405cf4b043259465c82a7df09caebc416a60ec15b80293c45c349ffb9cd0b9bd07fe8b9420b85e19f24a88a5dd62d3be62380f
|
7
|
+
data.tar.gz: 285faf4c815810af7111d49176218401f86afc1568a915c721ee67787cbb11df2cd6c016bad9d7b33db61b6120d5726d65aa8e2f0d27fc4cfb06a5685f69de9f
|
@@ -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
|
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 (
|
33
|
+
and dst_table_name in #{conn.quote_value_list(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
|
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
|
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
|
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(
|
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
|
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
|
data/lib/mikras_utils/version.rb
CHANGED