Bases: sqlalchemy.ext.declarative.api.Base
A class to hold permissions.
Permissions in Stalker defines what one can do or do not. A Permission instance is composed by three attributes; access, action and class_name.
Permissions for all the classes in SOM are generally created by Stalker when initializing the database.
If you created any custom classes to extend SOM you are also responsible to create the Permissions for it by calling stalker.db.register() and passing your class to it. See the stalker.db documentation for details.
Parameters: |
|
---|
Example: Let say that you want to create a Permission specifying a Group of Users are allowed to create Projects:
import transaction
from stalker import db
from stalker.db.session import DBSession, transaction
from stalker.models.auth import User, Group, Permission
# first setup the db with the default database
#
# stalker.db.__init_db__ will create all the Actions possible with the
# SOM classes automatically
#
# What is left to you is to create the permissions
setup.db()
user1 = User(login='test_user1', password='1234')
user2 = User(login='test_user2', password='1234')
group1 = Group(name='users')
group1.users = [user1, user2]
# get the permissions for the Project class
project_permissions = Permission.query .filter(Actions.access='Allow') .filter(Actions.action='Create') .filter(Actions.class_name='Project') .first()
# now we have the permission specifying the allowance of creating a
# Project
# to make group1 users able to create a Project we simply add this
# Permission to the groups permission attribute
group1.permissions.append(permission)
# and persist this information in the database
DBSession.add(group)
transaction.commit()
Methods
__init__(access, action, class_name) |
Attributes
access | returns the _access value |
action | returns the _action value |
class_name | returns the _class_name attribute value |
id | |
metadata | A collection of Table objects and their associated schema |
plural_class_name | the plural name of this class |
query | ORM-level SQL construction object. |
returns the _access value
returns the _class_name attribute value
returns the _action value
the plural name of this class