Bric::Util::Priv(3p)

NAME
Bric::Util::Priv - Individual Privileges

VERSION
$LastChangedRevision$

DATE
$LastChangedDate: 2006-03-18 01:26:34 +0100 (Sat, 18 Mar 2006) $

SYNOPSIS
  use Bric::Util::Priv;
  use Bric::Util::Priv::Parts::Const qw(:all);

  my $priv = Bric::Util::Priv->new($init);
  $priv = Bric::Util::Priv->lookup($params);
  my @privs = Bric::Util::Priv->list($params);
  my $privs_href = Bric::Util::Priv->href($params);
  my @priv_ids = Bric:::Util::Priv->list_ids($params);
  my $acl = Bric::Util::Priv->get_acl($user);
  my $vals_href = Bric::Util::Priv->vals_href;
  my $meths = Bric::Util::Priv->my_meths;
  my @meths = Bric::Util::Priv->my_meths(1);

  my $grp = $priv->get_usr_grp;
  my $grp_id = $priv->get_usr_grp_id;
  my $obj = $priv->get_obj_grp;
  my $obj_id = $priv->get_obj_grp_id;
  my $value = $priv->get_value;
  $priv = $priv->set_value(READ);
  $priv = $priv->del;
  $priv = $priv->save;

DESCRIPTION
Objects of the Bric::Util::Priv class represent single privileges granted to a user or user group. The idea is to be able to manage individual privileges in an object-oriented fashion. Thus, this class will be used by the interface of Bric::Biz::Person::User and Bric::Util::Grp::User.

INTERFACE

  Constructors

my $priv = Bric::Util::Priv->new($init)
    Creates a new privilege for a user or group. Expects a single anonymous hash argument consisting of the following keys:

    •   usr_grp - The Bric::Util::Grp::User object or ID for which to set the privilege. Required.

    •   obj_grp - The Bric::Util::Grp object or ID for whose members the privilege is granted. Required.

    •   value - The privilege to grant to the user or group. Required. Must be one of the following constants (which may be imported by "use Bric::Util::Priv::Parts::Const qw(:all)":

        •   READ => 1

        •   EDIT => 2

        •   RECALL => 3

        •   CREATE => 4

        •   PUBLISH => 5

        •   DENY => 255

    Throws:

    •   Must pass user group and object group.

    •   Incorrect number of args to Bric::_set().

    •   Bric::set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

my $priv = Bric::Util::Priv->lookup({ id => $id })
    Looks up and instantiates a Bric::Util::Priv object based on the Bric::Util::Priv object ID passed. If $id is not found in the database, lookup() returns undef.

    Throws:

    •   Too many Bric::Util::Priv objects found.

    •   Unable to prepare SQL statement.

    •   Unable to connect to database.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: If $id is found, populates the new Bric::Util::Priv object with data from the database before returning it.

    Notes: NONE.

(@privs || $privs_aref) = Bric::Util::Priv->list($params)
    Returns a list or anonymous array of Bric::Util::Priv objects. Supported search keys include:

    id  permission ID. May use "ANY" for a list of possible values.

    usr_grp_id
        A Bric::Util::Grp::User object ID to which privileges have been granted. May use "ANY" for a list of possible values.

    obj_grp_id
        A Bric::Util::Grp object ID for which privileges have been granted. May use "ANY" for a list of possible values.

    value
        A privilege value. This could return a *lot* of records, so you're probably not going to want to do this. May use "ANY" for a list of possible values.

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: NONE.

my $privs_href = Bric::Util::Priv->href($parms)
    Works the same as list(), with the same arguments, except it returns a hash or hashref of Bric::Util::Priv objects, where the keys are the contact IDs, and the values are the contact objects.

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: Populates each Bric::Util::Priv object with data from the database before returning them all.

    Notes: NONE.

  Destructors

$priv->DESTROY
    Dummy method to prevent wasting time trying to AUTOLOAD DESTROY.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

  Public Class Methods

(@priv_ids || $priv_ids_aref) = Bric::Util::Priv->list_ids($params)
    Returns a list or anonymous array of Bric::Util::Priv objects. Interface is the same as for list() above.

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: NONE.

my $acl = Bric::Util::Priv->get_acl($user)
    Returns an access control list of privilege settings for a given user. A description of the ACL's data structure will go here soon. Bric::Util::Priv will also handle caching that data structure.

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: Support for parent groups is not yet supported. Thus, if a user is in a group that does not have a permission set, and that group has a parent where the permission is set, that permission will not be included in the ACL. This inheritance of permissions will be implemented in the future, and at that time the permissions of child groups will override the permissions of their parents.

my $mtime = Bric::Util::Priv->get_acl_mtime($user)
    Returns the last modified time for the privileges set for groups of which $user is a member.

    Throws:

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: NONE.

my $vals_href = Bric::Util::Priv->vals_href
my $vals_aref = Bric::Util::Priv->vals_aref
    Returns an anonymous hash or anonymous array of the possible values for a privilege object. The vals_href() method returns an anonymous array in which the privilege values are the keys and their corresponding names are the values:

        { &READ    => 'READ',
          &EDIT    => 'EDIT',
          &RECALL  => 'RECALL',
          &CREATE  => 'CREATE',
          &PUBLISH => 'PUBLISH',
          &DENY    => 'DENY'
        }

    The vals_aref() method returns an anonymous array of anonymous arrays. The first value of each embedded anonymous array is the privilege value, whereas the second value is the name for that value:

        [ [ &READ    => 'READ'    ],
          [ &EDIT    => 'EDIT'    ],
          [ &RECALL  => 'RECALL'  ],
          [ &CREATE  => 'CREATE'  ],
          [ &PUBLISH => 'PUBLISH' ],
          [ &DENY    => 'DENY'    ]
        ]

    Throws: NONE.

    Side Effects: Use Bric::Util::Priv::Pargs::Const internally to import the value constants.

    Notes: NONE.

$meths = Bric::Util::Priv->my_meths
(@meths || $meths_aref) = Bric::Util::Priv->my_meths(TRUE)
my (@meths || $meths_aref) = Bric::Util::Priv->my_meths(0, TRUE)
    Returns an anonymous hash of introspection data for this object. If called with a true argument, it will return an ordered list or anonymous array of introspection data. If a second true argument is passed instead of a first, then a list or anonymous array of introspection data will be returned for properties that uniquely identify an object (excluding "id", which is assumed).

    Each hash key is the name of a property or attribute of the object. The value for a hash key is another anonymous hash containing the following keys:

    name
        The name of the property or attribute. Is the same as the hash key when an anonymous hash is returned.

    disp
        The display name of the property or attribute.

    get_meth
        A reference to the method that will retrieve the value of the property or attribute.

    get_args
        An anonymous array of arguments to pass to a call to get_meth in order to retrieve the value of the property or attribute.

    set_meth
        A reference to the method that will set the value of the property or attribute.

    set_args
        An anonymous array of arguments to pass to a call to set_meth in order to set the value of the property or attribute.

    type
        The type of value the property or attribute contains. There are only three types:

        short
        date
        blob
    len If the value is a 'short' value, this hash key contains the length of the field.

    search
        The property is searchable via the list() and list_ids() methods.

    req The property or attribute is required.

    props
        An anonymous hash of properties used to display the property or attribute. Possible keys include:

        type
            The display field type. Possible values are

            text
            textarea
            password
            hidden
            radio
            checkbox
            select
        length
            The Length, in letters, to display a text or password field.

        maxlength
            The maximum length of the property or value - usually defined by the SQL DDL.

    rows
        The number of rows to format in a textarea field.

    cols
        The number of columns to format in a textarea field.

    vals
        An anonymous hash of key/value pairs reprsenting the values and display names to use in a select list.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

  Public Instance Methods

my $id = $priv->get_id
    Returns the ID of the Bric::Util::Priv object.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: READ access for field 'id' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: If the Bric::Util::Priv object has been instantiated via the new() constructor and has not yet been "save"d, the object will not yet have an ID, so this method call will return undef.

my $usr_grp = $priv->get_usr_grp
    Returns the Bric::Util::Grp::User object to which the privilege has been granted.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Too many Bric::Util::Grp::User objects found.

    •   Unable to prepare SQL statement.

    •   Unable to connect to database.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: Calls Bric::Util::Grp::User->new internally.

    Notes: NONE.

my $usr_grp_id = $priv->get_usr_grp_id
    Returns the ID of the Bric::Util::Grp::User object to which the privilege has been granted.

    Throws:

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: READ access for field 'usr_grp_id' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $obj_grp = $priv->get_obj_grp
    Returns the group object for whose members the privilege has been granted.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Too many Bric::Util::Grp objects found.

    •   Unable to prepare SQL statement.

    •   Unable to connect to database.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: Calls Bric::Util::Grp->new internally.

    Notes: NONE.

my $obj_grp_id = $priv->get_obj_grp_id
    Returns the ID of the group object for whose members the privilege has been granted.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: READ access for field 'obj_grp_id' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $mtime = $priv->get_mtime
my $mtime = $priv->get_mtime($format)
    Returns the time the privilege was last modified. Pass in a strftime formatting string to get the time back in that format.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Unable to unpack date.

    •   Unable to format date.

    Side Effects: NONE.

    Notes: NONE.

my $value = $priv->get_value
    Returns the privilege setting for this Bric::Util::Priv object. Returns a value corresponding to the constants defined above for new(). "use Bric::Util::Priv::Parts::Const qw(:all)" for convenience constants.

    Throws:

    •   Bad AUTOLOAD method format.

    •   Cannot AUTOLOAD private methods.

    •   Access denied: READ access for field 'value' required.

    •   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

$self = $priv->set_value($value)
    Sets the privilege value for this Bric::Util::Priv object. The value must be equivalent to one of the privileges exported by Bric::Util::Priv::Parts::Const.

    Throws:

    •   Not a valid privilege value.

    •   Incorrect number of args to _set.

    •   Bric::_set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $priv->del
    Deletes the privilege. The privilege won't actually be deleted until $priv->save is called.

    Throws:

    •   Incorrect number of args to _set.

    •   Bric::_set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

$self = $priv->save
    Saves the privilege to the database.

    Throws:

    •   Bric::_get() - Problems retrieving fields.

    •   Unable to connect to database.

    •   Unable to prepare SQL statement.

    •   Unable to execute SQL statement.

    •   Unable to select row.

    •   Incorrect number of args to _set.

    •   Bric::_set() - Problems setting fields.

    Side Effects: NONE.

    Notes: NONE.

PRIVATE

  Private Class Methods
NONE.

  Private Instance Methods
NONE.

  Private Functions

my $privs_aref = &$get_em( $pkg, $search_href )
my $privs_ids_aref = &$get_em( $pkg, $search_href, 1 )
    Function used by lookup() and list() to return a list of Bric::Util::Priv objects or, if called with an optional third argument, returns a list of Bric::Util::Priv object IDs (used by list_ids()).

    Throws:

    •   Unable to prepare SQL statement.

    •   Unable to connect to database.

    •   Unable to select column into arrayref.

    •   Unable to execute SQL statement.

    •   Unable to bind to columns to statement handle.

    •   Unable to fetch row from statement handle.

    Side Effects: NONE.

    Notes: NONE.

NOTES
NONE.

AUTHOR
David Wheeler <david@justatheory.com>

SEE ALSO
Bric, Bric::Biz::Person, Bric::Biz::Person::User, Bric::Util::Grp::User