stalker.models.auth.Permission

Inheritance diagram of stalker.models.auth.Permission
class stalker.models.auth.Permission(access, action, class_name)[source]

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:
  • access (str) – An Enum value which can have the one of the values of Allow or Deny.
  • action (str) – An Enum value from the list [‘Create’, ‘Read’, ‘Update’, ‘Delete’, ‘List’]. Can not be None. The list can be changed from stalker.config.Config.default_actions.
  • class_name (str) – The name of the class that this action is applied to. Can not be None or an empty string.

Example: Let say that you want to create a Permission specifying a Group of Users are allowed to create Projects:

from stalker import db
from stalker import db
from stalker.models.auth import User, Group, Permission

# first setup the db with the default database
#
# stalker.db.init() will create all the Actions possible with the
# SOM classes automatically
#
# What is left to you is to create the permissions
db.setup()

user1 = User(
    name='Test User',
    login='test_user1',
    password='1234',
    email='testuser1@test.com'
)
user2 = User(
    name='Test User',
    login='test_user2',
    password='1234',
    email='testuser2@test.com'
)

group1 = Group(name='users')
group1.users = [user1, user2]

# get the permissions for the Project class
project_permissions = Permission.query          .filter(Permission.access='Allow')          .filter(Permission.action='Create')          .filter(Permission.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)
DBSession.commit()
__init__(access, action, class_name)

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
plural_class_name the plural name of this class
query
access

returns the _access value

class_name

returns the _class_name attribute value

action

returns the _action value

plural_class_name

the plural name of this class