NAME
App::Dochazka::REST::Model::Privhistory - privilege history functions
VERSION
Version 0.075
SYNOPSIS
use App::Dochazka::REST::Model::Privhistory;
...
DESCRIPTION
A description of the privhistory data model follows.
Privilege levels in the database
Type
The privilege levels themselves are defined in the privilege
enumerated type:
CREATE TYPE privilege AS ENUM ('passerby', 'inactive', 'active',
'admin')
Table
Employees are associated with privilege levels using a privhistory
table:
CREATE TABLE IF NOT EXISTS privhistory (
int_id serial PRIMARY KEY,
eid integer REFERENCES employees (eid) NOT NULL,
priv privilege NOT NULL;
effective timestamp NOT NULL,
remark text,
stamp json
);
Stored procedures
There are also two stored procedures for determining privilege levels:
priv_at_timestamp
Takes an EID and a timestamp; returns privilege level of that employee as of the timestamp. If the privilege level cannot be determined for the given timestamp, defaults to the lowest privilege level ('passerby').current_priv
Wrapper forpriv_at_timestamp
. Takes an EID and returns the current privilege level for that employee.
Privhistory in the Perl API
When an employee object is loaded (assuming the employee exists), the employee's current privilege level and schedule are included in the employee object. No additional object need be created for this. Privhistory objects are created only when an employee's privilege level changes or when an employee's privilege history is to be viewed.
In the data model, individual privhistory records are represented by "privhistory objects". All methods and functions for manipulating these objects are contained in App::Dochazka::REST::Model::Privhistory. The most important methods are:
constructor (spawn)
reset (recycles an existing object by setting it to desired state)
load (loads a single privhistory record)
insert (inserts object into database)
delete (deletes object from database)
For basic privhistory
workflow, see t/005-privhistory.t
.
EXPORTS
This module provides the following exports:
METHODS
spawn
Constructor. See Employee.pm->spawn for general comments.
reset
Instance method. Resets object, either to its primal state (no arguments) or to the state given in PARAMHASH.
Accessor methods
Basic accessor methods for all the fields of privhistory table. These functions return whatever value happens to be associated with the object, with no guarantee that it matches the database.
int_id
Accessor method.
eid
Accessor method.
priv
Accessor method.
effective
Accessor method.
remark
Accessor method.
load
Instance method. Given an EID, and, optionally, a timestamp, loads a single privhistory record into the object, rewriting whatever was there before. Returns a status object.
insert
Instance method. Attempts to INSERT a record into the 'privhistory' table. Field values are taken from the object. Returns a status object.
update
There is no 'update' method for privhistory records. Instead, delete and re-recreate.
delete
Instance method. Deletes the record. Returns status object.
FUNCTIONS
get_privhistory
Given a database handle, an EID, and an optional tsrange, return the history of privilege level changes for that employee over the given tsrange, or the entire history if no tsrange is supplied. The history is returned as a reference to an array of privhistory
objects. Returns undef if nothing is found.
AUTHOR
Nathan Cutler, <presnypreklad@gmail.com>