Browse Source

fixed sql script

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
baa9edbb87
1 changed files with 39 additions and 44 deletions
  1. 39
    44
      sql/struct_init.sql

+ 39
- 44
sql/struct_init.sql View File

@@ -1,52 +1,6 @@
1 1
 --
2 2
 -- PostgreSQL database dump
3 3
 --
4
---
5
---
6
-
7
-CREATE FUNCTION sp_lu_get_all_user_permission(_user_id integer, OUT _permisson_name character varying, OUT val boolean) RETURNS SETOF record
8
-    LANGUAGE sql IMMUTABLE SECURITY DEFINER COST 10
9
-    AS $$
10
-SELECT p.name, sp_lu_get_user_permission(_user_id, p.name) FROM luticate_permissions p ORDER bY p.name
11
-$$;
12
-
13
-
14
---
15
---
16
-
17
-CREATE FUNCTION sp_lu_get_user_permission(_user_id integer, _permisson_name character varying, OUT val boolean) RETURNS boolean
18
-    LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER COST 10
19
-    AS $$
20
-DECLARE
21
-    groups int[];
22
-    g INT;
23
-BEGIN
24
-    SELECT "value" INTO val FROM luticate_permissions_users WHERE "user_id" = _user_id AND "name" = _permisson_name;
25
-    IF val is null THEN
26
-        SELECT lpg."value" into val FROM luticate_permissions_groups lpg
27
-            INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
28
-            INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
29
-        WHERE lpg."name" = _permisson_name and lpg."value" = FALSE;
30
-        IF val is null then
31
-            SELECT lpg."value" into val FROM luticate_permissions_groups lpg
32
-                INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
33
-                INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
34
-            WHERE lpg."name" = _permisson_name and lpg."value" = TRUE;
35
-            IF val is null then
36
-                SELECT "value" INTO val FROM luticate_permissions WHERE "name" = _permisson_name;
37
-            END IF;
38
-        end if;
39
-    END IF;
40
-END;
41
-$$;
42
-
43
-
44
-SET default_tablespace = '';
45
-
46
-SET default_with_oids = false;
47
-
48 4
 --
49 5
 -- Name: camera_types; Type: TABLE; Schema: public; Owner: dev; Tablespace: 
50 6
 --
@@ -690,6 +644,45 @@ ALTER TABLE ONLY sensors
690 644
 ALTER TABLE ONLY sensors
691 645
     ADD CONSTRAINT sensors_sensor_type_id_fkey FOREIGN KEY (sensor_type_id) REFERENCES sensor_types(id) ON DELETE CASCADE;
692 646
 
647
+--
648
+-- Name: sp_lu_get_user_permission(integer, character varying); Type: FUNCTION; Schema: public; Owner: dev
649
+--
650
+
651
+CREATE FUNCTION sp_lu_get_user_permission(_user_id integer, _permisson_name character varying, OUT val boolean) RETURNS boolean
652
+LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER COST 10
653
+AS $$
654
+DECLARE
655
+    groups int[];
656
+    g INT;
657
+BEGIN
658
+    SELECT "value" INTO val FROM luticate_permissions_users WHERE "user_id" = _user_id AND "name" = _permisson_name;
659
+    IF val is null THEN
660
+        SELECT lpg."value" into val FROM luticate_permissions_groups lpg
661
+            INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
662
+            INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
663
+        WHERE lpg."name" = _permisson_name and lpg."value" = FALSE;
664
+        IF val is null then
665
+            SELECT lpg."value" into val FROM luticate_permissions_groups lpg
666
+                INNER JOIN luticate_groups lg ON lg."id" = lpg."group_id"
667
+                INNER JOIN luticate_users_groups lug ON lug."user_id" = _user_id AND lug."group_id" = lg."id"
668
+            WHERE lpg."name" = _permisson_name and lpg."value" = TRUE;
669
+            IF val is null then
670
+                SELECT "value" INTO val FROM luticate_permissions WHERE "name" = _permisson_name;
671
+            END IF;
672
+        end if;
673
+    END IF;
674
+END;
675
+$$;
676
+
677
+--
678
+-- Name: sp_lu_get_all_user_permission(integer); Type: FUNCTION; Schema: public; Owner: dev
679
+--
680
+
681
+CREATE FUNCTION sp_lu_get_all_user_permission(_user_id integer, OUT _permisson_name character varying, OUT val boolean) RETURNS SETOF record
682
+LANGUAGE sql IMMUTABLE SECURITY DEFINER COST 10
683
+AS $$
684
+SELECT p.name, sp_lu_get_user_permission(_user_id, p.name) FROM luticate_permissions p ORDER bY p.name
685
+$$;
693 686
 
694 687
 --
695 688
 -- Name: public; Type: ACL; Schema: -; Owner: postgres

Loading…
Cancel
Save