Name

Bric::Util::Priv - Individual Privileges

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:

Throws:

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:

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:

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:

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:

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. An ACL is simply a hash reference with all keys but one being object group IDs for groups to which the user has been granted permission, where the value for each key is the relevant permission. One key is not a group ID, but "mtime", and it stands for that most recent time any of the permissions was modified. It is used for expiring an ACL.

Throws:

Side Effects: NONE.

Notes: Support for parent groups is not 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 may 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:

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:

Side Effects: NONE.

Notes: If the Bric::Util::Priv object has been instantiated via the new() constructor and has not yet been saved, 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:

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:

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:

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:

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:

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:

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:

Side Effects: NONE.

Notes: NONE.

$self = $priv->del

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

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $priv->save

Saves the privilege to the database.

Throws:

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:

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