User Tools

Site Tools


podoc:can_access_photo_sql_function

Database Function Description of "can_access_photo"

Name

can_access_photo

Description

Purpose

Schema

CREATE OR REPLACE FUNCTION can_access_photo(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;
BEGIN
 
  -- 1 == public, 2 == protected, 3 == private
  -- 1 == diabled, 2 == client, 3 == user, 4 == admin
 
SELECT INTO res_access, owns_id access_rights, users FROM photo 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 photo, folder, calendar WHERE folder.identifier = photo.folder AND folder.event = calendar.identifier AND calendar.client = user_id;
  IF can_access is true THEN
    RETURN true;
  END IF;
 
  SELECT INTO can_access true FROM photo, folder WHERE photo.identifier = res_id AND photo.folder = folder.identifier AND folder.password = ANY(passwd_list);
  IF can_access is true THEN
    RETURN true;
  END IF;
 
  SELECT INTO can_access true FROM album_content, album, calendar WHERE album_content.photo = res_id AND album.identifier = album_content.album AND album.event = calendar.identifier AND calendar.client = user_id;
  IF can_access is true THEN
    RETURN true;
  END IF;
 
  SELECT INTO can_access true FROM album, album_content WHERE album_content.photo = res_id AND album_content.album = album.identifier AND album.password = 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_photo(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;
BEGIN
 
  -- 1 == public, 2 == protected, 3 == private
  -- 1 == diabled, 2 == client, 3 == user, 4 == admin
 
SELECT INTO res_access, owns_id access_rights, users FROM photo 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 photo, folder, calendar WHERE folder.identifier = photo.folder AND folder.event = calendar.identifier AND calendar.client = user_id;
  IF can_access is true THEN
    RETURN true;
  END IF;
 
  SELECT INTO can_access true FROM photo, folder WHERE photo.identifier = res_id AND photo.folder = folder.identifier AND folder.password = ANY(passwd_list);
  IF can_access is true THEN
    RETURN true;
  END IF;
 
  SELECT INTO can_access true FROM album_content, album, calendar WHERE album_content.photo = res_id AND album.identifier = album_content.album AND album.event = calendar.identifier AND calendar.client = user_id;
  IF can_access is true THEN
    RETURN true;
  END IF;
 
  SELECT INTO can_access true FROM album, album_content WHERE album_content.photo = res_id AND album_content.album = album.identifier AND album.password = ANY(passwd_list);
  IF can_access is true THEN
    RETURN true;
  END IF;
 
END IF;
 
  return false;
END;
' LANGUAGE 'plpgsql';
podoc/can_access_photo_sql_function.txt · Last modified: 2007/10/19 15:10 by Luud