User Tools

Site Tools


podoc:can_access_album_sql_function

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

podoc:can_access_album_sql_function [2007/10/19 11:09] (current)
Luud created
Line 1: Line 1:
 +===== Database Function Description of "​can_access_album"​ =====
 +
 +=== Name ===
 +
 +can_access_album
 +
 +=== Description ===
 +
 +=== Purpose ===
 +
 +=== Schema ===
 +
 +<code sql>
 +CREATE OR REPLACE FUNCTION can_access_album(integer,​ integer, varchar[]) returns boolean as '
 +DECLARE
 +  res_id alias for $1;
 +  user_id alias for $2;
 +  passwd_list alias for $3;
 +  res_access integer;
 +  owns_id integer;
 +  can_access boolean;
 +  admin_type boolean;
 +  passwd varchar;
 +BEGIN
 +
 +  -- 1 == public, 2 == protected, 3 == private
 +  -- 1 == diabled, 2 == client, 3 == user, 4 == admin
 +
 +SELECT INTO res_access, owns_id, passwd access_rights,​ users, password FROM album WHERE identifier = res_id;
 +
 +IF res_access = 1 THEN
 +  RETURN true;
 +END IF;
 +
 +IF owns_id = user_id THEN
 +  RETURN true;
 +END IF;
 +
 +SELECT INTO admin_type true FROM users WHERE identifier = user_id AND type = 4;
 +IF admin_type is true THEN
 +  RETURN true;
 +END IF;
 +
 +IF res_access = 2 THEN
 +  SELECT INTO can_access true FROM album, calendar WHERE album.event = calendar.identifier AND calendar.client = user_id;
 +
 +  IF can_access is true THEN
 +     ​RETURN true;
 +  END IF;
 +
 +  select into can_access true WHERE passwd = ANY(passwd_list);​
 +  IF can_access is true THEN
 +    RETURN true;
 +  END IF;
 +END IF;
 +
 +  return false;
 +END;
 +' language '​plpgsql';​
 +</​code>​
 +
 +=== History ===
 +
 +== Used first ==
 +
 +Version 2.34
 +
 +== Used last ==
 +
 +Still in use
 +
 +== Change history ==
 +
 += Version 2.34 =
 +
 +<code sql>
 +--- Permission lookup functions!
 +
 +CREATE OR REPLACE FUNCTION can_access_album(integer,​ integer, varchar[]) returns boolean as '
 +DECLARE
 +  res_id alias for $1;
 +  user_id alias for $2;
 +  passwd_list alias for $3;
 +  res_access integer;
 +  owns_id integer;
 +  can_access boolean;
 +  admin_type boolean;
 +  passwd varchar;
 +BEGIN
 +
 +  -- 1 == public, 2 == protected, 3 == private
 +  -- 1 == diabled, 2 == client, 3 == user, 4 == admin
 +
 +SELECT INTO res_access, owns_id, passwd access_rights,​ users, password FROM album WHERE identifier = res_id;
 +
 +IF res_access = 1 THEN
 +  RETURN true;
 +END IF;
 +
 +IF owns_id = user_id THEN
 +  RETURN true;
 +END IF;
 +
 +SELECT INTO admin_type true FROM users WHERE identifier = user_id AND type = 4;
 +IF admin_type is true THEN
 +  RETURN true;
 +END IF;
 +
 +IF res_access = 2 THEN
 +  SELECT INTO can_access true FROM album, calendar WHERE album.event = calendar.identifier AND calendar.client = user_id;
 +
 +  IF can_access is true THEN
 +     ​RETURN true;
 +  END IF;
 +
 +  select into can_access true WHERE passwd = ANY(passwd_list);​
 +  IF can_access is true THEN
 +    RETURN true;
 +  END IF;
 +END IF;
 +
 +  return false;
 +END;
 +' language '​plpgsql';​
 +</​code>​
  
podoc/can_access_album_sql_function.txt ยท Last modified: 2007/10/19 11:09 by Luud