From 7003fe5658958208d6dff7dadb163ff9c92e9f82 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 27 Dec 2006 21:29:55 +1300 Subject: [PATCH] A few tweaks to make things work with the fields we just got rid of. --- dba/caldav_functions.sql | 13 +++++++++---- dba/sample-data.sql | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dba/caldav_functions.sql b/dba/caldav_functions.sql index ef5b0163..2dd3a5bd 100644 --- a/dba/caldav_functions.sql +++ b/dba/caldav_functions.sql @@ -219,6 +219,11 @@ BEGIN END; ' LANGUAGE 'plpgsql' IMMUTABLE STRICT; + +CREATE or REPLACE FUNCTION usr_is_role( INT, TEXT ) RETURNS BOOLEAN AS ' + SELECT EXISTS( SELECT 1 FROM role_member JOIN roles USING(role_no) WHERE role_member.user_no=$1 AND roles.role_name=$2 ) +' LANGUAGE 'sql' IMMUTABLE STRICT; + CREATE or REPLACE FUNCTION get_permissions( INT, INT ) RETURNS TEXT AS ' DECLARE in_from ALIAS FOR $1; @@ -236,15 +241,15 @@ BEGIN -- dbg := ''S-''; SELECT rt1.confers INTO out_confers FROM relationship r1 JOIN relationship_type rt1 USING ( rt_id ) - WHERE r1.from_user = in_from AND r1.to_user = in_to; + WHERE r1.from_user = in_from AND r1.to_user = in_to AND NOT usr_is_role(r1.to_user,''Group''); IF FOUND THEN RETURN dbg || out_confers; END IF; -- RAISE NOTICE ''No simple relationships between % and %'', in_from, in_to; - SELECT rt1.confers, rt2.confers INTO out_confers, tmp_confers FROM relationship r1 JOIN relationship_type rt1 ON ( r1.rt_id = rt1.rt_id ) - LEFT OUTER JOIN relationship r2 ON ( r1.to_user = r2.from_user ) JOIN relationship_type rt2 ON ( r2.rt_id = rt2.rt_id ) - WHERE r1.from_user = in_from AND r2.to_user = in_to; + SELECT rt1.confers, rt2.confers INTO out_confers, tmp_confers FROM relationship r1 JOIN relationship_type rt1 USING(rt_id) + JOIN relationship r2 ON r1.to_user=r2.from_user JOIN relationship_type rt2 ON r2.rt_id=rt2.rt_id + WHERE r1.from_user=in_from AND r2.to_user=in_to AND usr_is_role(r1.to_user,''Group'') AND NOT usr_is_role(r2.to_user,''Group'') AND NOT usr_is_role(r1.from_user,''Group''); IF FOUND THEN -- RAISE NOTICE ''Permissions to group % from group %'', out_confers, tmp_confers; diff --git a/dba/sample-data.sql b/dba/sample-data.sql index eade87e2..fc2e19c0 100644 --- a/dba/sample-data.sql +++ b/dba/sample-data.sql @@ -37,8 +37,8 @@ SELECT setval('usr_user_no_seq', 1000); SELECT setval('relationship_type_rt_id_seq', (SELECT 10 UNION SELECT rt_id FROM relationship_type ORDER BY 1 DESC LIMIT 1) ); -- The resources for meetings -INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 200, 100, 4 ); -INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 200, 101, 4 ); +INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 200, 100, 1 ); +INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 200, 101, 1 ); -- The people who administer meetings INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 10, 200, 1 );