|
@@ -8,9 +8,11 @@
|
8
|
8
|
CREATE FUNCTION sp_lu_get_all_user_permission(_user_id integer, OUT _permisson_name character varying, OUT val boolean) RETURNS SETOF record
|
9
|
9
|
LANGUAGE sql IMMUTABLE SECURITY DEFINER COST 10
|
10
|
10
|
AS $$
|
11
|
|
- SELECT p.name, sp_lu_get_user_permission(_user_id, p.name) FROM luticate_permissions p
|
|
11
|
+SELECT p.name, sp_lu_get_user_permission(_user_id, p.name) FROM luticate_permissions p ORDER bY p.name
|
12
|
12
|
$$;
|
13
|
13
|
|
|
14
|
+
|
|
15
|
+
|
14
|
16
|
--
|
15
|
17
|
-- Name: sp_lu_get_user_permission(integer, character varying); Type: FUNCTION; Schema: public; Owner: dev
|
16
|
18
|
--
|
|
@@ -24,18 +26,19 @@ g INT;
|
24
|
26
|
BEGIN
|
25
|
27
|
SELECT "value" INTO val FROM luticate_permissions_users WHERE "user_id" = _user_id AND "name" = _permisson_name;
|
26
|
28
|
IF val is null THEN
|
27
|
|
- SELECT array_agg("group_id") INTO groups FROM luticate_users_groups WHERE "user_id" = _user_id;
|
28
|
|
- IF groups is not null then
|
29
|
|
- FOREACH g in ARRAY groups LOOP
|
30
|
|
- SELECT "value" INTO val FROM luticate_permissions_groups WHERE "group_id" = g AND "name" = _permisson_name;
|
31
|
|
- IF val = FALSE THEN
|
32
|
|
- EXIT;
|
33
|
|
- END IF;
|
34
|
|
- END LOOP;
|
35
|
|
- END if;
|
36
|
|
- IF val is null then
|
37
|
|
- SELECT "value" INTO val FROM luticate_permissions WHERE "name" = _permisson_name;
|
38
|
|
- end if;
|
|
29
|
+ SELECT lpg."value" into val FROM luticate_permissions_groups lpg
|
|
30
|
+ INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
|
|
31
|
+ INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
|
|
32
|
+ WHERE lpg."name" = _permisson_name and lpg."value" = FALSE;
|
|
33
|
+ IF val is null then
|
|
34
|
+ SELECT lpg."value" into val FROM luticate_permissions_groups lpg
|
|
35
|
+ INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
|
|
36
|
+ INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
|
|
37
|
+ WHERE lpg."name" = _permisson_name and lpg."value" = TRUE;
|
|
38
|
+ IF val is null then
|
|
39
|
+ SELECT "value" INTO val FROM luticate_permissions WHERE "name" = _permisson_name;
|
|
40
|
+ END IF;
|
|
41
|
+ end if;
|
39
|
42
|
END IF;
|
40
|
43
|
END;
|
41
|
44
|
$$;
|
|
@@ -56,7 +59,7 @@ SET default_tablespace = '';
|
56
|
59
|
SET default_with_oids = false;
|
57
|
60
|
|
58
|
61
|
--
|
|
62
|
+-- Name: luticate_groups; Type: TABLE; Schema: public; Owner: dev; Tablespace:
|
59
|
63
|
--
|
60
|
64
|
|
61
|
65
|
CREATE TABLE luticate_groups (
|
|
@@ -64,8 +67,10 @@ CREATE TABLE luticate_groups (
|
64
|
67
|
name character varying NOT NULL
|
65
|
68
|
);
|
66
|
69
|
|
|
70
|
+
|
|
71
|
+
|
67
|
72
|
--
|
|
73
|
+-- Name: luticate_permissions; Type: TABLE; Schema: public; Owner: dev; Tablespace:
|
68
|
74
|
--
|
69
|
75
|
|
70
|
76
|
CREATE TABLE luticate_permissions (
|
|
@@ -73,8 +78,10 @@ CREATE TABLE luticate_permissions (
|
73
|
78
|
value boolean NOT NULL
|
74
|
79
|
);
|
75
|
80
|
|
|
81
|
+
|
|
82
|
+
|
76
|
83
|
--
|
|
84
|
+-- Name: luticate_permissions_groups; Type: TABLE; Schema: public; Owner: dev; Tablespace:
|
77
|
85
|
--
|
78
|
86
|
|
79
|
87
|
CREATE TABLE luticate_permissions_groups (
|
|
@@ -83,8 +90,10 @@ CREATE TABLE luticate_permissions_groups (
|
83
|
90
|
group_id integer NOT NULL
|
84
|
91
|
);
|
85
|
92
|
|
|
93
|
+
|
|
94
|
+
|
86
|
95
|
--
|
|
96
|
+-- Name: luticate_permissions_users; Type: TABLE; Schema: public; Owner: dev; Tablespace:
|
87
|
97
|
--
|
88
|
98
|
|
89
|
99
|
CREATE TABLE luticate_permissions_users (
|
|
@@ -93,6 +102,8 @@ CREATE TABLE luticate_permissions_users (
|
93
|
102
|
user_id integer NOT NULL
|
94
|
103
|
);
|
95
|
104
|
|
|
105
|
+
|
|
106
|
+
|
96
|
107
|
--
|
97
|
108
|
-- Name: luticate_users_id_seq; Type: SEQUENCE; Schema: public; Owner: dev
|
98
|
109
|
--
|
|
@@ -104,8 +115,10 @@ NO MINVALUE
|
104
|
115
|
NO MAXVALUE
|
105
|
116
|
CACHE 1;
|
106
|
117
|
|
|
118
|
+
|
|
119
|
+
|
107
|
120
|
--
|
|
121
|
+-- Name: luticate_users; Type: TABLE; Schema: public; Owner: dev; Tablespace:
|
108
|
122
|
--
|
109
|
123
|
|
110
|
124
|
CREATE TABLE luticate_users (
|
|
@@ -119,8 +132,10 @@ CREATE TABLE luticate_users (
|
119
|
132
|
lastname character varying(255) NOT NULL
|
120
|
133
|
);
|
121
|
134
|
|
|
135
|
+
|
|
136
|
+
|
122
|
137
|
--
|
|
138
|
+-- Name: luticate_users_groups; Type: TABLE; Schema: public; Owner: dev; Tablespace:
|
123
|
139
|
--
|
124
|
140
|
|
125
|
141
|
CREATE TABLE luticate_users_groups (
|
|
@@ -128,8 +143,9 @@ CREATE TABLE luticate_users_groups (
|
128
|
143
|
group_id integer NOT NULL
|
129
|
144
|
);
|
130
|
145
|
|
|
146
|
+
|
131
|
147
|
--
|
|
148
|
+-- Name: luticate_groups_name_key; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
|
132
|
149
|
--
|
133
|
150
|
|
134
|
151
|
ALTER TABLE ONLY luticate_groups
|
|
@@ -137,7 +153,7 @@ ADD CONSTRAINT luticate_groups_name_key UNIQUE (name);
|
137
|
153
|
|
138
|
154
|
|
139
|
155
|
--
|
|
156
|
+-- Name: luticate_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
|
140
|
157
|
--
|
141
|
158
|
|
142
|
159
|
ALTER TABLE ONLY luticate_groups
|
|
@@ -145,7 +161,7 @@ ADD CONSTRAINT luticate_groups_pkey PRIMARY KEY (id);
|
145
|
161
|
|
146
|
162
|
|
147
|
163
|
--
|
|
164
|
+-- Name: luticate_permissions_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
|
148
|
165
|
--
|
149
|
166
|
|
150
|
167
|
ALTER TABLE ONLY luticate_permissions
|
|
@@ -153,7 +169,7 @@ ADD CONSTRAINT luticate_permissions_pkey PRIMARY KEY (name);
|
153
|
169
|
|
154
|
170
|
|
155
|
171
|
--
|
|
172
|
+-- Name: luticate_permissions_users_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
|
156
|
173
|
--
|
157
|
174
|
|
158
|
175
|
ALTER TABLE ONLY luticate_permissions_users
|
|
@@ -161,7 +177,7 @@ ADD CONSTRAINT luticate_permissions_users_pkey PRIMARY KEY (name, user_id);
|
161
|
177
|
|
162
|
178
|
|
163
|
179
|
--
|
|
180
|
+-- Name: luticate_users_email_key; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
|
164
|
181
|
--
|
165
|
182
|
|
166
|
183
|
ALTER TABLE ONLY luticate_users
|
|
@@ -169,7 +185,7 @@ ADD CONSTRAINT luticate_users_email_key UNIQUE (email);
|
169
|
185
|
|
170
|
186
|
|
171
|
187
|
--
|
|
188
|
+-- Name: luticate_users_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
|
172
|
189
|
--
|
173
|
190
|
|
174
|
191
|
ALTER TABLE ONLY luticate_users_groups
|
|
@@ -177,7 +193,7 @@ ADD CONSTRAINT luticate_users_groups_pkey PRIMARY KEY (user_id, group_id);
|
177
|
193
|
|
178
|
194
|
|
179
|
195
|
--
|
|
196
|
+-- Name: luticate_users_pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
|
180
|
197
|
--
|
181
|
198
|
|
182
|
199
|
ALTER TABLE ONLY luticate_users
|
|
@@ -185,7 +201,7 @@ ADD CONSTRAINT luticate_users_pkey PRIMARY KEY (id);
|
185
|
201
|
|
186
|
202
|
|
187
|
203
|
--
|
|
204
|
+-- Name: luticate_users_username_key; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
|
188
|
205
|
--
|
189
|
206
|
|
190
|
207
|
ALTER TABLE ONLY luticate_users
|
|
@@ -193,7 +209,7 @@ ADD CONSTRAINT luticate_users_username_key UNIQUE (username);
|
193
|
209
|
|
194
|
210
|
|
195
|
211
|
--
|
|
212
|
+-- Name: pkey; Type: CONSTRAINT; Schema: public; Owner: dev; Tablespace:
|
196
|
213
|
--
|
197
|
214
|
|
198
|
215
|
ALTER TABLE ONLY luticate_permissions_groups
|
|
@@ -247,6 +263,7 @@ ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id)
|
247
|
263
|
ALTER TABLE ONLY luticate_users_groups
|
248
|
264
|
ADD CONSTRAINT foreign_user FOREIGN KEY (user_id) REFERENCES luticate_users(id) ON DELETE CASCADE;
|
249
|
265
|
|
|
266
|
+
|
250
|
267
|
--
|
251
|
268
|
-- PostgreSQL database dump complete
|
252
|
269
|
--
|