From 3f3804cd430f8df7b900acb5b1948e64ee413647 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Mon, 11 Dec 2006 12:37:07 +1300 Subject: [PATCH] Enhanced permissions calculation which now supports the idea of bind/unbind and 'all'. --- dba/caldav_functions.sql | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/dba/caldav_functions.sql b/dba/caldav_functions.sql index 481e6918..9c6b6f23 100644 --- a/dba/caldav_functions.sql +++ b/dba/caldav_functions.sql @@ -225,7 +225,9 @@ DECLARE in_to ALIAS FOR $2; out_confers TEXT; tmp_confers TEXT; + tmp_txt TEXT; dbg TEXT DEFAULT ''''; + counter INT; BEGIN -- Self can always have full access IF in_from = in_to THEN @@ -251,10 +253,22 @@ BEGIN IF out_confers = tmp_confers THEN RETURN dbg || out_confers; ELSE - IF length( out_confers ) < length( tmp_confers ) THEN + IF tmp_confers ~* ''A'' AND NOT tmp_confers ~* ''BRWU'' THEN + -- Ensure that A is expanded to all privs + tmp_confers := tmp_confers || ''BRWU''; + END IF; + IF (SELECT substring(setting,1,3)::numeric >= 8.1 FROM pg_settings WHERE name = ''server_version'') THEN + -- PostgreSQL 8.1 or later. regexp_replace exists! + out_confers := regexp_replace( out_confers, ''([^'' || tmp_confers || '']*)'', '''' ); RETURN dbg || out_confers; ELSE - RETURN dbg || tmp_confers; + tmp_txt = ''''; + FOR counter IN 1 .. length(tmp_confers) LOOP + IF out_confers ~* substring(tmp_confers,counter,1) THEN + tmp_txt := tmp_txt || substring(tmp_confers,counter,1); + END IF; + END LOOP; + RETURN dbg || tmp_txt; END IF; END IF; END IF;