Module Spiff_Guard :: Class DB

Class DB



object --+    
         |    
  DBReader --+
             |
            DB

Extends the DBReader class with methods for manipulating the database.

Instance Methods
Boolean
install(self)
Installs (or upgrades) database tables.
Boolean
uninstall(self)
Drops all tables from the database.
Boolean
clear_database(self)
Drops the content of any database table used by this library.
Boolean
add_action(self, actions)
Inserts the given action into the database.
Boolean
save_action(self, actions)
Updates the given actions in the database.
int
delete_action(self, actions)
Convenience wrapper around delete_action_from_match().
int
delete_action_from_match(self, **kwargs)
Deletes all actions that match the given criteria from the database.
Boolean
add_resource(self, parent_id, resources)
Inserts the given resources into the database, under the parent with the given id.
Boolean
save_resource(self, resources)
Updates the given resources in the database.
int
delete_resource(self, resources)
Convenience wrapper around delete_resource_from_match().
int
delete_resource_from_match(self, **kwargs)
Deletes all resources that match the given criteria, including their children.
Boolean
delete_permission_from_id(self, actor_id, action_id, resource_id)
Deletes the ACL with the given id from the database.
Boolean
delete_permission(self, actor, action, resource)
Convenience wrapper around delete_permission_from_id().
Boolean
set_permission_from_id(self, actor_list, action_list, resource_list, permit)
Defines whether or not the given actors may perform the given actions on the given resources.
Boolean
set_permission(self, actor, action, resource, permit)
Convenience wrapper around set_permission_from_id().
Boolean
grant_from_id(self, actor_list, action_list, resource_list)
Convenience wrapper around set_permission_from_id().
Boolean
grant(self, actor, action, resource)
Convenience wrapper around set_permission().
Boolean
deny_from_id(self, actor_list, action_list, resource_list)
Convenience wrapper around set_permission_from_id().
Boolean
deny(self, actor, action, resource)
Convenience wrapper around set_permission().

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

    Inherited from DBReader
DB
__init__(self, db)
Instantiates a new DBReader.
 
debug(self, debug=True)
Enable/disable debugging.
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.
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_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.
list[Acl]
get_permission_list_with_inheritance(self, offset=0, limit=0, **kwargs)
Returns a list of ACLs that match the given criteria.
Resource
get_resource(self, **kwargs)
Like get_resources(), but
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.
list[Resource]
get_resources(self, offset=0, limit=0, **kwargs)
Returns a list of resources that match the given criteria.
string
get_table_prefix(self)
Returns the current database table prefix.
boolean
has_permission(self, actor, action, resource)
Convenience wrapper around has_permission_from_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_resource(self, **kwargs)
Like get_resource(), but returns True if at least one result was found, False otherwise.
boolean
is_registered(self, objtype)
Checks whether the given class is already registered.
 
register_type(self, objtypes)
Before using any other methods you need to let Spiff Guard know what types (classes) you are using.
 
set_table_prefix(self, prefix)
Define a string that is prefixed to all table names in the database.
Properties

Inherited from object: __class__

Method Details

install(self)

 
Installs (or upgrades) database tables.
Returns: Boolean
True on success, False otherwise.

uninstall(self)

 
Drops all tables from the database. Use with care.
Returns: Boolean
True on success, False otherwise.

clear_database(self)

 

Drops the content of any database table used by this library. Use with care.

Wipes out everything, including types, actions, resources and acls.
Returns: Boolean
True on success, False otherwise.

add_action(self, actions)

 
Inserts the given action into the database.
Parameters:
  • actions (Action|list[Action]) - The actions to be added.
Returns: Boolean
True on success, False otherwise.

save_action(self, actions)

 
Updates the given actions in the database. Does nothing if the action doesn't exist.
Parameters:
  • actions (Action|list[Action]) - The action to be saved.
Returns: Boolean
True on success, False otherwise.

delete_action(self, actions)

 
Convenience wrapper around delete_action_from_match().
Parameters:
  • actions (Action|list[Action]) - The actions to be removed.
Returns: int
The number of deleted actions.

delete_action_from_match(self, **kwargs)

 
Deletes all actions that match the given criteria from the database. All ACLs associated with the action are removed.
Parameters:
  • 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
    All values may also be lists (logical OR).
Returns: int
The number of deleted actions.

add_resource(self, parent_id, resources)

 
Inserts the given resources into the database, under the parent with the given id.
Parameters:
  • parent_id (int|Resource) - The id of the resource under which the new resource is added, or an instance of a Resource.
  • resources (Resource|list[Resource]) - The resource that is added.
Returns: Boolean
True on success, False otherwise.

save_resource(self, resources)

 
Updates the given resources in the database. Does nothing to any resource that does not yet exist.
Parameters:
  • resources (Resource|list[Resource]) - The resource that is saved.
Returns: Boolean
True on success, False otherwise.

delete_resource(self, resources)

 
Convenience wrapper around delete_resource_from_match().
Parameters:
  • resources (Resource|list[Resource]) - The resource that is deleted.
Returns: int
The number of deleted resources.

delete_resource_from_match(self, **kwargs)

 
Deletes all resources that match the given criteria, including their children.
Parameters:
  • kwargs (dict) - For a list of allowed keys see get_resources().
Returns: int
The number of deleted resources.

delete_permission_from_id(self, actor_id, action_id, resource_id)

 
Deletes the ACL with the given id from the database.
Parameters:
  • actor_id (int) - The id of the actor whose ACL is to be deleted.
  • action_id (int) - The id of the action whose ACL is to be deleted.
  • resource_id (int) - The id of the resource whose ACL is to be deleted.
Returns: Boolean
True if the ACL existed, False otherwise.

delete_permission(self, actor, action, resource)

 
Convenience wrapper around delete_permission_from_id().
Parameters:
  • actor (int) - The actor whose ACL is to be deleted.
  • action (int) - The action whose ACL is to be deleted.
  • resource (int) - The resource whose ACL is to be deleted.
Returns: Boolean
True if the ACL existed, False otherwise.

set_permission_from_id(self, actor_list, action_list, resource_list, permit)

 
Defines whether or not the given actors may perform the given actions on the given resources.
Parameters:
  • actor_list (list[Actor]) - A list containing actors.
  • action_list (list[Action]) - A list containing actions.
  • resource_list (list[Resource]) - A list containing resources.
  • permit (boolean) - True to permit the given actions, False to deny them.
Returns: Boolean
True on success, False otherwise.

set_permission(self, actor, action, resource, permit)

 
Convenience wrapper around set_permission_from_id().
Parameters:
  • actor (Actor) - The actor whose permissions should be changed.
  • action (Action) - The action to permit or deny.
  • resource (Resource) - The resource on which a permission should be defined.
  • permit (boolean) - True to permit the given action, False to deny it.
Returns: Boolean
True on success, False otherwise.

grant_from_id(self, actor_list, action_list, resource_list)

 
Convenience wrapper around set_permission_from_id().
Parameters:
  • actor_list (list[Actor]) - A list containing actors.
  • action_list (list[Action]) - A list containing actions.
  • resource_list (list[Resource]) - A list containing resources.
Returns: Boolean
True on success, False otherwise.

grant(self, actor, action, resource)

 
Convenience wrapper around set_permission().
Parameters:
  • actor (Actor) - The actor whose permissions should be changed.
  • action (Action) - The action to permit.
  • resource (Resource) - The resource on which a permission should be defined.
Returns: Boolean
True on success, False otherwise.

deny_from_id(self, actor_list, action_list, resource_list)

 
Convenience wrapper around set_permission_from_id().
Parameters:
  • actor_list (list[Actor]) - A list containing actors.
  • action_list (list[Action]) - A list containing actions.
  • resource_list (list[Resource]) - A list containing resources.
Returns: Boolean
True on success, False otherwise.

deny(self, actor, action, resource)

 
Convenience wrapper around set_permission().
Parameters:
  • actor (Actor) - The actor whose permissions should be changed.
  • action (Action) - The action to deny.
  • resource (Resource) - The resource on which a permission should be defined.
Returns: Boolean
True on success, False otherwise.