 $$ LANGUAGE plpgsql;
 CREATE TRIGGER grants_modified AFTER INSERT OR UPDATE ON grants
     FOR EACH ROW EXECUTE PROCEDURE grants_modified();
-
-
-
--- An expanded list of the grants this principal has access to
-CREATE or REPLACE FUNCTION g_has_proxy_access_to( INT8, INT ) RETURNS SETOF grants AS $$
-  SELECT $1, by_collection, by_principal,
-         (CASE WHEN by_collection IS NULL THEN pprivs($1,by_principal,$2)
-               ELSE path_privs($1,(SELECT dav_name FROM collection WHERE collection_id = by_collection),$2)
-           END) AS privileges,
-         coalesce((principal.type_id=3), FALSE) AS is_group
-    FROM (
-      SELECT by_principal, by_collection FROM grants
-           WHERE to_principal IN (SELECT $1 UNION SELECT expand_memberships($1,$2))
-             AND (privileges & 5::BIT(24)) != 0::BIT(24)
-             AND by_principal != $1
-         UNION
-      SELECT principal_id AS by_principal, NULL::INT8 FROM principal
-           WHERE (default_privileges & 5::BIT(24)) != 0::BIT(24)
-             AND principal_id != $1
-    ) subquery LEFT JOIN principal ON (subquery.by_principal = principal_id);
-$$ LANGUAGE 'SQL' STABLE STRICT;
-
-
--- A list of the principals who can proxy to this principal
-CREATE or REPLACE FUNCTION g_grants_proxy_access_from( INT8, INT ) RETURNS SETOF grants AS $$
-  SELECT DISTINCT ON (grants.by_principal) by_principal, NULL::INT8, $1 AS to_principal, pprivs(by_principal,$1,$2), (principal.type_id=3) AS is_group
-    FROM grants JOIN principal ON (by_principal = principal_id)
-   WHERE by_collection IS NULL AND by_principal != $1
-     AND by_principal IN (SELECT $1 UNION SELECT expand_members(g2.to_principal,$2) FROM grants g2 WHERE g2.by_principal = $1)
-   ;
-$$ LANGUAGE 'SQL' STABLE STRICT;
-
 
 
 

$$ LANGUAGE 'plpgsql' STABLE STRICT;


-- CREATE or REPLACE FUNCTION get_permissions( INT, INT ) RETURNS TEXT AS $$
--   SELECT bits_to_legacy_privilege(user_privileges( $1, $2 ));
-- $$ LANGUAGE 'sql' IMMUTABLE STRICT;

-- List a user's memberships as a text string
CREATE or REPLACE FUNCTION is_member_of_list( INT8 ) RETURNS TEXT AS $$
DECLARE

LANGUAGE 'PlPgSQL' IMMUTABLE STRICT;


-- Expanded group memberships out to some depth
CREATE or REPLACE FUNCTION expand_memberships( INT8, INT ) RETURNS SETOF INT8 AS $$
  SELECT group_id FROM group_member WHERE member_id = $1
