User Tools

Site Tools


podoc:can_access_album_sql_function

Database Function Description of "can_access_album"

Name

can_access_album

Description

Purpose

Schema

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';

History

Used first

Version 2.34

Used last

Still in use

Change history

= Version 2.34 =

--- 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';
podoc/can_access_album_sql_function.txt · Last modified: 2007/10/19 11:09 by Luud