Module Spiff_Guard :: Class DBReader

Class DBReader



object --+
         |
        DBReader

Instance Methods
DB
__init__(self, db)
Instantiates a new DBReader.
 
debug(self, debug=True)
Enable/disable debugging.
 
set_table_prefix(self, prefix)
Define a string that is prefixed to all table names in the database.
string
get_table_prefix(self)
Returns the current database table prefix.
 
register_type(self, objtypes)
Before using any other methods you need to let Spiff Guard know what types (classes) you are using.
boolean
is_registered(self, objtype)
Checks whether the given class is already registered.
Action
get_action(self, **kwargs)
Like get_actions(), but
list[Action]
get_actions(self, offset=0, limit=0, **kwargs)
Returns all actions that match the given criteria.
Resource
get_resource(self, **kwargs)
Like get_resources(), but
boolean
has_resource(self, **kwargs)
Like get_resource(), but returns True if at least one result was found, False otherwise.
list[Resource]
get_resources(self, offset=0, limit=0, **kwargs)
Returns a list of resources that match the given criteria.
list[Resource]
get_resource_children(self, parent_id, offset=0, limit=0, **kwargs)
Returns the list of children of the given parent that match the given criteria.
list[Resource]
get_resource_parents(self, child_ids, offset=0, limit=0, **kwargs)
Returns the list of parents of the given child that also match the given criteria.
ResourcePath
get_resource_path_from_id(self, id)
Returns an object representing the "path" of an object; that is, a list of ancestors, where the first item is the root of the path and the last item is the one with the given id.
boolean
has_permission_from_id(self, actor_id, action_id, resource_id)
Check whether the actor with the given id has the permission to perform the action with the given id on the resource with the given id.
boolean
has_permission(self, actor, action, resource)
Convenience wrapper around has_permission_from_id().
list[Acl]
get_permission_list_from_id(self, actor_id, offset=0, limit=0, **kwargs)
Returns a list of ACLs that match the given criteria.
list[Acl]
get_permission_list_from_id_with_inheritance(self, offset=0, limit=0, **kwargs)
Returns a list of ACLs that match the given criteria.
datetime.datetime
get_last_permission_change(self, **kwargs)
Returns the time of the last permission change that affected any resource that matches the given argument.
list[Acl]
get_permission_list_with_inheritance(self, offset=0, limit=0, **kwargs)
Returns a list of ACLs that match the given criteria.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties

Inherited from object: __class__

Method Details

__init__(self, db)
(Constructor)

 
Instantiates a new DBReader.
Parameters:
  • db (object) - An sqlalchemy database connection.
Returns: DB
The new instance.
Overrides: object.__init__

debug(self, debug=True)

 
Enable/disable debugging.
Parameters:
  • debug (Boolean) - True to enable debugging.

set_table_prefix(self, prefix)

 
Define a string that is prefixed to all table names in the database. Default is 'guard_'.
Parameters:
  • prefix (string) - The new prefix.

get_table_prefix(self)

 
Returns the current database table prefix.
Returns: string
The current prefix.

register_type(self, objtypes)

 
Before using any other methods you need to let Spiff Guard know what types (classes) you are using. For example, before being able to retrieve a resource from the database using get_resource(), you need to register the class using this function.
Parameters:
  • objtypes (class|list[class]) - The class that you want to use with Spiff Guard.

is_registered(self, objtype)

 
Checks whether the given class is already registered.
Returns: boolean
True if the given class is registered, False otherwise.

get_action(self, **kwargs)

 
Like get_actions(), but
  • Returns None, if no match was found.
  • Returns the action, if exactly one match was found.
  • Raises an error if more than one match was found.
Parameters:
  • kwargs (dict) - For a list of allowed keys see get_actions().
Returns: Action
The action or None.

get_actions(self, offset=0, limit=0, **kwargs)

 
Returns all actions that match the given criteria.
Parameters:
  • offset (int) - The offset of the first item to be returned.
  • limit (int) - The maximum number of items that is returned.
  • kwargs (dict) - The following keys may be used:
    • id - the id of the action
    • handle - the handle of the action
    • type - the class type of the action
    All values may also be lists (logical OR).
Returns: list[Action]
The list of actions.

get_resource(self, **kwargs)

 
Like get_resources(), but
  • Returns None, if no match was found.
  • Returns the resource, if exactly one match was found.
  • Raises an error if more than one match was found.
Parameters:
  • kwargs (dict) - For a list of allowed keys see get_resources().
Returns: Resource
The resource, or None if none was found.

has_resource(self, **kwargs)

 
Like get_resource(), but returns True if at least one result was found, False otherwise. Is significantly faster than get_resource.
Parameters:
  • kwargs (dict) - For a list of allowed keys see get_resources().
Returns: boolean
True if the resource was found, False otherwise.

get_resources(self, offset=0, limit=0, **kwargs)

 
Returns a list of resources that match the given criteria.
Parameters:
  • offset (int) - The offset of the first item to be returned.
  • limit (int) - The maximum number of items that is returned.
  • kwargs (dict) - The following keys may be used: id - the id of the resource handle - the handle of the resource type - the class type of the resource attribute - a dict containing attribute/value pairs
Returns: list[Resource]
The list of resources.

get_resource_children(self, parent_id, offset=0, limit=0, **kwargs)

 
Returns the list of children of the given parent that match the given criteria.
Parameters:
  • offset (int) - The offset of the first item to be returned.
  • limit (int) - The maximum number of items that is returned.
  • kwargs (dict) - For a list of allowed keys see get_resources().
Returns: list[Resource]
The list of resources.

get_resource_parents(self, child_ids, offset=0, limit=0, **kwargs)

 
Returns the list of parents of the given child that also match the given criteria.
Parameters:
  • offset (int) - The offset of the first item to be returned.
  • limit (int) - The maximum number of items that is returned.
  • kwargs (dict) - For a list of allowed keys see get_resources().
Returns: list[Resource]
The list of resources.

get_resource_path_from_id(self, id)

 
Returns an object representing the "path" of an object; that is, a list of ancestors, where the first item is the root of the path and the last item is the one with the given id.
Returns: ResourcePath
The path to the item with the given id.

has_permission_from_id(self, actor_id, action_id, resource_id)

 
Check whether the actor with the given id has the permission to perform the action with the given id on the resource with the given id.
Parameters:
  • actor_id (int) - The id of the resource that performs the action.
  • action_id (int) - The id of the action that is performed.
  • resource_id (int) - The id of the resource on which the action is performed.
Returns: boolean
True if the permission is granted, False otherwise.

has_permission(self, actor, action, resource)

 
Convenience wrapper around has_permission_from_id().
Parameters:
  • actor (Actor) - The resource that performs the action.
  • action (int) - The action that is performed.
  • resource (int) - The resource on which the action is performed.
Returns: boolean
True if the permission is granted, False otherwise.

get_permission_list_from_id(self, actor_id, offset=0, limit=0, **kwargs)

 

Returns a list of ACLs that match the given criteria. The function ignores inheritance, so that ACLs are only returned if they were defined specificly for the requested resource.

Allowed argument keywords include: action_id, resource_id, permit, action_type and resource_type. All keywords are optional; if no keywords are given all ACLs for the given actor_id are returned.
Parameters:
  • offset (int) - The offset of the first item to be returned.
  • limit (int) - The maximum number of items that is returned.
  • kwargs (dict) - The search criteria.
Returns: list[Acl]
The list of ACLs.

get_permission_list_from_id_with_inheritance(self, offset=0, limit=0, **kwargs)

 

Returns a list of ACLs that match the given criteria. The function honors inheritance, so that ACLs are returned even if they were defined for a parent of the requested resource.

This function is expensive and should be used with care. You might want to consider using get_permission_list_from_id() instead.

Allowed argument keywords include: actor_id, action_id, resource_id, permit, actor_type, action_type and resource_type. All arguments are optional; if no arguments are given all ACLs are returned.
Parameters:
  • offset (int) - The offset of the first item to be returned.
  • limit (int) - The maximum number of items that is returned.
  • kwargs (dict) - The search criteria.
Returns: list[Acl]
The list of ACLs.

get_last_permission_change(self, **kwargs)

 

Returns the time of the last permission change that affected any resource that matches the given argument.

Allowed argument keywords include: actor_id, action_id, resource_id, permit, actor_type, action_type and resource_type. All arguments are optional; if no arguments are given all ACLs are returned.
Parameters:
  • kwargs (dict) - The search criteria.
Returns: datetime.datetime
The latest ACL change.

get_permission_list_with_inheritance(self, offset=0, limit=0, **kwargs)

 
Returns a list of ACLs that match the given criteria. Allowed argument keywords include: actor, action, resource, permit, actor_type, action_type and resource_type. All arguments are optional.
Parameters:
  • offset (int) - The offset of the first item to be returned.
  • limit (int) - The maximum number of items that is returned.
  • kwargs (dict) - The search criteria.
Returns: list[Acl]
The list of ACLs.