mikras_utils 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +10 -0
- data/README.md +31 -0
- data/Rakefile +8 -0
- data/acl-build +5 -0
- data/build +11 -0
- data/exe/mikras_utils +5 -0
- data/exe/mkacl +59 -0
- data/lib/mikras_utils/mkacl/analyzer.rb +46 -0
- data/lib/mikras_utils/mkacl/generator.rb +55 -0
- data/lib/mikras_utils/mkacl/generators/acl_functions.rb +208 -0
- data/lib/mikras_utils/mkacl/generators/id_functions.rb +262 -0
- data/lib/mikras_utils/mkacl/generators/insert_triggers.rb +267 -0
- data/lib/mikras_utils/mkacl/generators/role_functions.rb +72 -0
- data/lib/mikras_utils/mkacl/generators/rules.rb +80 -0
- data/lib/mikras_utils/mkacl/parser.rb +73 -0
- data/lib/mikras_utils/mkacl/spec.rb +154 -0
- data/lib/mikras_utils/mkacl.rb +18 -0
- data/lib/mikras_utils/version.rb +5 -0
- data/lib/mikras_utils.rb +6 -0
- data/sig/mikras_utils.rbs +4 -0
- data/tests/acl.fox +312 -0
- data/tests/acl.spec +135 -0
- data/tests/acl.sql +132 -0
- data/tests/acl_portal-functions.sql +94 -0
- data/tests/acl_portal-tables.sql +23 -0
- data/tests/acl_portal-views.sql +73 -0
- data/tests/agg.sql +25 -0
- data/tests/app.sql +48 -0
- data/tests/app_portal-tables.sql +138 -0
- data/tests/app_portal-triggers.sql +23 -0
- data/tests/app_portal-views.sql +203 -0
- data/tests/auth.sql +12 -0
- data/tests/auth.users.sql +5 -0
- data/tests/build +7 -0
- data/tests/final-functions.sql +28 -0
- data/tests/fox.sql +158 -0
- data/tests/initial-functions.sql +6 -0
- data/tests/meta.sql +197 -0
- data/tests/reflections.yml +5 -0
- data/tests/schemas.sql +25 -0
- data/tests/setup.sql +8 -0
- data/tests/sys_portal.sql +172 -0
- metadata +145 -0
@@ -0,0 +1,172 @@
|
|
1
|
+
|
2
|
+
\set ON_ERROR_STOP on
|
3
|
+
|
4
|
+
drop schema if exists sys_portal cascade;
|
5
|
+
create schema sys_portal;
|
6
|
+
set search_path to sys_portal;
|
7
|
+
|
8
|
+
/*
|
9
|
+
-- TODO: Move to acl_portal unify definitions
|
10
|
+
|
11
|
+
drop view if exists acl_roles cascade;
|
12
|
+
create view acl_roles as
|
13
|
+
select
|
14
|
+
id as "role_id",
|
15
|
+
'CASE'::varchar as "kind",
|
16
|
+
role
|
17
|
+
from
|
18
|
+
app_portal.case_roles
|
19
|
+
union
|
20
|
+
select
|
21
|
+
id as "role_id",
|
22
|
+
'EVENT'::varchar as "kind",
|
23
|
+
role
|
24
|
+
from
|
25
|
+
app_portal.event_roles
|
26
|
+
;
|
27
|
+
|
28
|
+
\echo ACL_ROLES
|
29
|
+
select * from acl_roles;
|
30
|
+
|
31
|
+
drop view if exists name_acl_roles cascade;
|
32
|
+
create view name_acl_roles as
|
33
|
+
select
|
34
|
+
ar.*,
|
35
|
+
case
|
36
|
+
when cr.id is not null then
|
37
|
+
c1.ident || '/' || cr.role
|
38
|
+
else
|
39
|
+
c2.ident || '/' || e.label || '/' || er.role
|
40
|
+
end as "acl"
|
41
|
+
from
|
42
|
+
acl_roles ar
|
43
|
+
left join app_portal.case_roles cr on cr.id = ar.role_id
|
44
|
+
left join app_portal.cases c1 on c1.id = cr.case_id
|
45
|
+
left join app_portal.event_roles er on er.id = ar.role_id
|
46
|
+
left join app_portal.events e on e.id = er.event_id
|
47
|
+
left join app_portal.cases c2 on c2.id = e.case_id
|
48
|
+
;
|
49
|
+
|
50
|
+
\echo NAME_ACL_ROLES
|
51
|
+
select * from name_acl_roles;
|
52
|
+
|
53
|
+
drop view if exists acl_users cascade;
|
54
|
+
create view acl_users as
|
55
|
+
with
|
56
|
+
case_acls as (
|
57
|
+
select
|
58
|
+
u.id as "user_id",
|
59
|
+
c.id as "case_id",
|
60
|
+
cr.id as "role_id"
|
61
|
+
from
|
62
|
+
auth.roles u
|
63
|
+
join app_portal.case_users cu on cu.user_id = u.id
|
64
|
+
join app_portal.case_roles cr on cr.id = cu.case_role_id
|
65
|
+
join app_portal.cases c on c.id = cr.case_id
|
66
|
+
where
|
67
|
+
c.closed = false
|
68
|
+
and cr.role <> 'TA'
|
69
|
+
),
|
70
|
+
event_acls as (
|
71
|
+
select
|
72
|
+
u.id as "user_id",
|
73
|
+
e.case_id as "case_id",
|
74
|
+
er.id as "role_id"
|
75
|
+
from
|
76
|
+
auth.roles u
|
77
|
+
join app_portal.event_users eu on eu.user_id = u.id
|
78
|
+
join app_portal.event_roles er on er.id = eu.event_role_id
|
79
|
+
join app_portal.events e on e.id = er.event_id
|
80
|
+
where
|
81
|
+
e.closed = false
|
82
|
+
),
|
83
|
+
te_acls as (
|
84
|
+
select
|
85
|
+
u.id as "user_id",
|
86
|
+
e.case_id as "case_id",
|
87
|
+
cr.id as "role_id"
|
88
|
+
from
|
89
|
+
auth.roles u
|
90
|
+
join app_portal.event_users eu on eu.user_id = u.id
|
91
|
+
join app_portal.event_roles er on er.id = eu.event_role_id
|
92
|
+
join app_portal.events e on e.id = er.event_id
|
93
|
+
join app_portal.case_roles cr on cr.case_id = e.case_id
|
94
|
+
where
|
95
|
+
er.role = 'TA'
|
96
|
+
and cr.role = 'TE'
|
97
|
+
)
|
98
|
+
select * from case_acls
|
99
|
+
union
|
100
|
+
select * from event_acls
|
101
|
+
union
|
102
|
+
select * from te_acls
|
103
|
+
;
|
104
|
+
|
105
|
+
\echo ACL_USERS
|
106
|
+
select * from acl_users;
|
107
|
+
|
108
|
+
drop view if exists agg_acl_users cascade;
|
109
|
+
create view agg_acl_users as
|
110
|
+
select
|
111
|
+
user_id,
|
112
|
+
array_agg(role_id) as "role_ids"
|
113
|
+
from
|
114
|
+
acl_users
|
115
|
+
group by
|
116
|
+
user_id
|
117
|
+
;
|
118
|
+
|
119
|
+
\echo AGG_ACL_USERS
|
120
|
+
select * from agg_acl_users;
|
121
|
+
|
122
|
+
drop view if exists name_acl_users;
|
123
|
+
create view name_acl_users as
|
124
|
+
select
|
125
|
+
au.*,
|
126
|
+
u.rolename,
|
127
|
+
c.ident as "case",
|
128
|
+
e.label as "event",
|
129
|
+
coalesce(cr.role, er.role) as "role",
|
130
|
+
case
|
131
|
+
when cr.id is not null then
|
132
|
+
c.ident || '/' || cr.role
|
133
|
+
else
|
134
|
+
c.ident || '/' || e.label || '/' || er.role
|
135
|
+
end as "acl"
|
136
|
+
from
|
137
|
+
acl_users au
|
138
|
+
join auth.roles u on u.id = au.user_id
|
139
|
+
join app_portal.cases c on c.id = au.case_id
|
140
|
+
left join app_portal.case_roles cr on cr.id = au.role_id
|
141
|
+
left join app_portal.event_roles er on er.id = au.role_id
|
142
|
+
left join app_portal.events e on e.id = er.event_id
|
143
|
+
;
|
144
|
+
|
145
|
+
\echo NAME_ACL_USERS
|
146
|
+
select * from name_acl_users;
|
147
|
+
|
148
|
+
drop view if exists agg_name_acl_users cascade;
|
149
|
+
create view agg_name_acl_users as
|
150
|
+
select
|
151
|
+
user_id,
|
152
|
+
array_agg(role_id) as role_ids,
|
153
|
+
rolename,
|
154
|
+
array_agg(acl) as acls
|
155
|
+
from
|
156
|
+
name_acl_users
|
157
|
+
group by
|
158
|
+
user_id,
|
159
|
+
rolename
|
160
|
+
;
|
161
|
+
|
162
|
+
\echo AGG_NAME_ACL_USERS
|
163
|
+
select * from agg_name_acl_users;
|
164
|
+
|
165
|
+
-- Materialized view or maintained by triggers
|
166
|
+
create view acls as
|
167
|
+
select * from agg_acl_users
|
168
|
+
;
|
169
|
+
|
170
|
+
\echo ACLS
|
171
|
+
select * from acls;
|
172
|
+
*/
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mikras_utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Claus Rasmussen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pg_conn
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: shellopts
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: string-text
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: prick-inflector
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Gem mikras_utils
|
70
|
+
email:
|
71
|
+
- claus.l.rasmussen@gmail.com
|
72
|
+
executables:
|
73
|
+
- mikras_utils
|
74
|
+
- mkacl
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".rspec"
|
79
|
+
- ".ruby-version"
|
80
|
+
- Gemfile
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- acl-build
|
84
|
+
- build
|
85
|
+
- exe/mikras_utils
|
86
|
+
- exe/mkacl
|
87
|
+
- lib/mikras_utils.rb
|
88
|
+
- lib/mikras_utils/mkacl.rb
|
89
|
+
- lib/mikras_utils/mkacl/analyzer.rb
|
90
|
+
- lib/mikras_utils/mkacl/generator.rb
|
91
|
+
- lib/mikras_utils/mkacl/generators/acl_functions.rb
|
92
|
+
- lib/mikras_utils/mkacl/generators/id_functions.rb
|
93
|
+
- lib/mikras_utils/mkacl/generators/insert_triggers.rb
|
94
|
+
- lib/mikras_utils/mkacl/generators/role_functions.rb
|
95
|
+
- lib/mikras_utils/mkacl/generators/rules.rb
|
96
|
+
- lib/mikras_utils/mkacl/parser.rb
|
97
|
+
- lib/mikras_utils/mkacl/spec.rb
|
98
|
+
- lib/mikras_utils/version.rb
|
99
|
+
- sig/mikras_utils.rbs
|
100
|
+
- tests/acl.fox
|
101
|
+
- tests/acl.spec
|
102
|
+
- tests/acl.sql
|
103
|
+
- tests/acl_portal-functions.sql
|
104
|
+
- tests/acl_portal-tables.sql
|
105
|
+
- tests/acl_portal-views.sql
|
106
|
+
- tests/agg.sql
|
107
|
+
- tests/app.sql
|
108
|
+
- tests/app_portal-tables.sql
|
109
|
+
- tests/app_portal-triggers.sql
|
110
|
+
- tests/app_portal-views.sql
|
111
|
+
- tests/auth.sql
|
112
|
+
- tests/auth.users.sql
|
113
|
+
- tests/build
|
114
|
+
- tests/final-functions.sql
|
115
|
+
- tests/fox.sql
|
116
|
+
- tests/initial-functions.sql
|
117
|
+
- tests/meta.sql
|
118
|
+
- tests/reflections.yml
|
119
|
+
- tests/schemas.sql
|
120
|
+
- tests/setup.sql
|
121
|
+
- tests/sys_portal.sql
|
122
|
+
homepage: http://www.nowhere.com/
|
123
|
+
licenses: []
|
124
|
+
metadata:
|
125
|
+
homepage_uri: http://www.nowhere.com/
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 2.6.0
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubygems_version: 3.3.7
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Gem mikras_utils
|
145
|
+
test_files: []
|