vispa.models package

Submodules

vispa.models.group module

class vispa.models.group.Group_User_Assoc(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

The Group_User_Assoc object is a association object representing the membership of a user in a group. In addition to the membership itself, it has a status flag, which indicates, whether the membership is confirmed or not.

CONFIRMED = 0
UNCONFIRMED = 1
group_id
status
user
user_id
class vispa.models.group.Group_Group_Assoc(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

The Group_Group_Assoc object is a association object representing the membership of one group in another, called child group and parnet group. In addition to the membership itself, it has a status flag, which indicates whether the membership is confirmed or not.

CONFIRMED = 0
UNCONFIRMED = 1
child_group
child_group_id
parent_group_id
status
class vispa.models.group.Group(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

A group is a collection of users and other groups. Every group has an id, a unique name and a creation timestamp. Furthermore there is a privacy integer as follows:

0 - public: the group and its members can be seen by everyone and everyone can join 1 - protected: the group is visible, members only for other members, joining via request to group manager 2 - private: group and members are invisible, joining via password

A group is organized by managers, who can edit the name, privacy etc. as well as the memberships of users and group. Additionally, the managers can join the group into a parentgroup.

ACTIVE = 1
DELETED = 2
INACTIVE = 0
PRIVATE = 2
PROTECTED = 1
PUBLIC = 0
add_child_group(session, child_group, confirmed=1)

Add child group to parent group. Loops in groups are permitted. The necessary Group_Group_Assoc object is added to the database.

Parameters:
  • session – current session of database
  • child_group (Group) – concerning child group
Raises:

TypeError of child_group is not instance of Group

Raises:

Exception if a loop is detected

Raises:

Exception if child_group is already in the group

add_manager(user)

Add manager to group.

Parameters:user (User) – user which has to be added
Raises:TypeError if user is not instance of User
Raises:Exception if user is already manager of the group‚
add_user(session, user, confirmed=1)

Add user to group. The necessary Group_User_Assoc object is added to the database. By default, the membership is unconfirmed.

Parameters:
  • session – current session of database
  • user (User) – user which has to be added
Raises:

TypeError if user is not instance of User

Raises:

Exception if user already in group

static all(session)

Get all groups.

Parameters:session – current session of database
Returns:list of all Group objects
child_groups
confirm_child_group(child_group)

Confirm a child group in a private parent group.

Parameters:child_group (Group) – concerning child group
Raises:TypeError of child_group is not instance of Group
Raises:Exception if child_group is not in the group
confirm_user(user)

Confirm a user in a private group.

Parameters:user (User) – concerning user
Raises:TypeError if user is not instance of User
Raises:Exception if user not in group
created
delete()

Delete group. Internally, the delete flag is set, its not deleted from the database.

static get(session, group)

Get a group by name or id. If the group parameter is an instance of Group, it is directly returned.

Parameters:
  • session – current session of database
  • group – name or id to look for. if group is instance of Group, group is returned
Returns:

Group

Raises:

Exception if group parameter invalid or no group can be found

static get_by_id(session, gid)

Get a group by its id.

Parameters:
  • session – current session of database
  • gid – id to look for
Returns:

Group or None if inexistent

static get_by_name(session, name)

Get a group by its name.

Parameters:
  • session – current session of database
  • name – name to look for
Returns:

Group or None if inexistent

get_child_groups(recursion_depth=-1)

Get child groups of a parent group. This function works as get_users regarding the recursion depth.

Parameters:recursion_depth – number of steps for recursion
Returns:Set of Group_Group_Assoc objects
get_managers()

Get managers of the group.

Returns:list of User objects, which are managers of the group
static get_or_create_by_name(session, name, privacy=0, password='')

Get a group by name or create it as public group, if it does not exists.

Parameters:
  • session – current session of database
  • name – name of the group
Returns:

Group

Raises:

Exception if no group with name exists and either name or privacy are invalid

get_parent_groups(recursion_depth=-1)

Get parent groups (confirmed and unconfirmed) of a child group. This function works as get_child_groups but in opposite direction. The recursion is only done for confirmed memberships.

Parameters:recursion_depth – number of steps for recursion
Returns:Set of Group_Group_Assoc objects
get_projects()

Returns active projects of the group and all (confirmed) parent groups.

Returns:Set of Project_Group_Assoc objects
get_users(recursion_depth=-1)

Get all users of the group. The recursion depth for the child groups can be given as additional argument. E.g. 0 is only the group itself, 1 also includes all direct child groups. -1 belongs to infinite recursion depth. Notice: since loops in groups are permitted, there is only a finite number of recusions for a finite number of groups.

Parameters:recursion_depth – number of recursions for child groups
Returns:Set of Group_User_Assoc objects
id
managers
name
password
privacy
remove_child_group(session, child_group)

Remove child group from parent group. The concerning Group_Group_Assoc object is deleted form the database.

Parameters:
  • session – current session of database
  • child_group (Group) – concerning child group
Raises:

TypeError of child_group is not instance of Group

Raises:

Exception if child_group is not in the group

remove_manager(manager)

Remove manager from group.

Parameters:manager (User) – manager which has to be removed
Raises:TypeError if manager is not instance of User
Raises:Exception if manager is not manager of the group
remove_user(session, user)

Remove user from group. The concerning Group_User_Assoc object is deleted from the database.

Parameters:
  • session – current session of database
  • user (User) – user which has to be removed
Raises:

TypeError if user is not instance of User

Raises:

Exception if user not in group

rename(session, newname)

Rename group.

Parameters:
  • session – current session of database, used to validate new name
  • newname – new name of the group
Raises:

Exception if newname is invalid or already exitent

set_password(password)

Set the password of a group.

Parameters:password – new password
Raises:Exception if password is invalid
set_privacy(privacy)

Set privacy of group.

Parameters:privacy – new privacy of the group (0, 1, or 2)
Raises:Exception if privacy is invalid
set_status(status)

Set status of group.

Parameters:status – new status of the group, either 0 for inactive or 1 for active
Raises:Exception if status is invalid
status
users

vispa.models.jsondata module

class vispa.models.jsondata.JSONData(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

get_info_data()
static get_item(db, user_id, key, workspace_id, create=False)
static get_value(db, user_id, key, workspace_id)
static get_values_by_key(db, user_id, key=None)
id
key
static set_value(db, user_id, key, workspace_id, value)
timestamp
user_id
value
workspace_id

vispa.models.project module

class vispa.models.project.Project_User_Assoc(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

The Project_User_Assoc object is an association object, which connects a project and a user. It has a many-to-many relationship to roles, which gives the user roles inside the project. For the association table, the project and the user id are used.

get_permissions()

Get the permissions of this Project User connection.

Returns:Set of Permission objects
project_id
roles
user
user_id
class vispa.models.project.Project_Group_Assoc(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

The Project_Group_Assoc object is an association object, which connects a project and a group. It has a many-to-many relationship to roles, which gives the group roles inside the project. For the association table, the project and the group id are used.

get_permissions()

Get the permissions of this Project Group connection.

Returns:Set of Permission objects
group
group_id
project_id
roles
class vispa.models.project.Project(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

A project connects users and groups to some content (ProjectItems) and also assigns permissions to them via roles. Permissions can be e.g. read and write rights on the content.

ACTIVE = 1
DELETED = 2
INACTIVE = 0
add_group(session, group)

Adds group to project without any roles. The necessary Project_Group_Assoc object is added to the database.

Parameters:
  • session – current session of database
  • group (Group) – concerning group
Raises:

TypeError if group is not instance of Group

add_manager(user)

Adds new manager to project.

Parameters:user (User) – concerning user
Raises:TypeError if user is not instance of User
add_roles_to_group(group, roles)

Add role to group.

Parameters:
  • group (Group) – concerning group
  • roles (list of Role objects) – list of roles
Raises:

TypeError if type if group or roles is invalid

Raises:

Exception if group not in project

add_roles_to_user(user, roles)

Add role to a user.

Parameters:
  • user (User) – concerning user
  • roles (list of Role objects) – list of roles
Raises:

TypeError if type if user or roles is invalid

Raises:

Exception if user not in project

add_user(session, user)

Adds user to project without any roles.

Parameters:
  • session – current session of database
  • user (User) – concerning user
Raises:

TypeError if user is not instance of User

Raises:

Exception if user already in project

static all(session)

Returns all existing projects.

Parameters:session – current session of database
Returns:list of Project objects
static create(session, name)

Create new project.

Parameters:
  • session – current session of database
  • name – name of the project
Raises:

Exception if name is invalid or project with same name already exists

created
delete()

Delete project. Internally, the delete flag is set, its not really deleted.

static get(session, project)

Get a project by name. If the project parameter is an instance of Project, it is directly returned.

Parameters:
  • session – current session of database
  • project – name to look for. If project is instance of Project it is directly returned
Returns:

Project object

Raises:

Exception if project parameter is invalid or no project can be found

static get_by_id(session, gid)

Get a project by its id.

Parameters:
  • session – current session of database
  • gid – given id, which is looked for
Returns:

Project object or None if inexistent

static get_by_name(session, name)

Get a project by its name.

Parameters:
  • session – current session of database
  • name – name which is looked for
Returns:

Project object or None if inexistent

get_groups()

Get groups of project.

Returns:list of Project_Group_Assoc objects
get_items(itemtype=None)

Get ProjectItems.

Parameters:itemtype – optional selector on the item type
Returns:list of ProjectItem objects
get_managers()

Get managers of project.

Returns:list of User objects
static get_or_create_by_name(session, name)

Get or create a project by its name.

Parameters:
  • session – current session of database
  • name – name of the project
Returns:

Project

get_roles_of_group(group)

Return roles of group.

Parameters:group (Group) – concerning group
Returns:list of Role objects
Raises:TypeError if group is not instance of Group
Raises:Exception if group not in project
get_roles_of_user(user)

Return roles of user.

Parameters:user (User) – concerning user
Returns:list of Role objects
Raises:TypeError if user is not instance of User
Raises:Exception if user not in project
get_users()

Returns users of project.

Returns:list of Project_User_Assoc objects
groups
has_group(group)

Check if group is already in project.

Parameters:group (Group) – concerning group
Returns:bool whether group is in project
Raises:TypeError if group is not instance of Group
id
items
managers
name
remove_group(session, group)

Removes group from Project.

Parameters:
  • session – current session of database
  • group (Group) – concerning group
Raises:

TypeError if group is not instance of Group

Raises:

Exception if group is not in project

remove_manager(manager)

Removes manager from Project.

Parameters:manager (User) – concerning manager
Raises:TypeError if manager is not instance of User
Raises:Exception if manager is not manager of project
remove_user(session, user)

Removes user from Project. The concerning Project_User_Assoc is deleted from the database.

Parameters:
  • session – current session of database
  • user (User) – concerning user
Raises:

TypeError if user is not instance of User

Raises:

Exception if user not in project

rename(session, newname)

Rename project.

Parameters:
  • session – current session of database, used to validate new name
  • newname – new name of the project
Raises:

Exception if newname is invalid or project with newname already exists

set_roles_of_group(group, roles)

Sets the roles of a group in a project.

Parameters:
  • group (Group) – concerning group
  • roles (list of Role objects) – list of roles
Raises:

TypeError if type if group or roles is invalid

Raises:

Exception if group not in project

set_roles_of_user(user, roles)

Sets the roles of a user in a project.

Parameters:
  • user (User) – concerning user
  • roles (list of Role objects) – list of roles
Raises:

TypeError if type if user or roles is invalid

Raises:

Exception if user not in project

set_status(status)

Set status of project.

Parameters:status – new status of the project, either 0 for inactive or 1 for active
Raises:Exception if status is invalid
status
users
class vispa.models.project.ProjectItem(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

A project item represents the actual content of a project. It is simply an object consisting of a type (e.g. file) and its content (e.g. the path of the file)

content
static create(session, project, itemtype, content)

Create an project item. The item is added to the database.

Parameters:
  • session – current session of database
  • project – project of the new item
  • itemtype – type of the item
  • content – content of the item
delete(session)

Delete the item. It is removed from the database.

Parameters:session – current session of database
static get(session, item)

Get a ProjectItem by its id. If the item is already a ProjectItem object, it is directly returned.

Parameters:
  • session – current session of database
  • item – id to look for. if type of item is ProjectItem, item is returned
Returs:

ProjectItem

Raises:

Exception if item is invalid or no item can be found

static get_by_id(session, gid)

Get a ProjectItem by its id.

Parameters:
  • session – current session of database
  • gid – given id, which is looked for
Returns:

ProjectItem or None if inexistent

get_project()

Get the project of the item.

Returns:Project
id
itemtype
project_id
set_content(content)

Set the content of the item.

Parameters:content – new content

vispa.models.role module

class vispa.models.role.Permission(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

A Permission object is self-explanatory a permission for a user. It is only characerized by its name, which explains its meaning.

static all(session)

Get all existing permissions.

Parameters:session – current session of database
Returns:list of Permission objects
static create(session, name)

Create new permission.

Parameters:
  • session – current session of database
  • name – name of the permission
Raises:

Exception if name is invalid or already in use

created
delete(session)

Delete permission. It is also deleted from the database.

Parameters:session – current session of database
static get(session, permission)

Get a permissionby name. If permission is already a Permission object, it is directly returned.

Parameters:
  • session – current session of database
  • permission – name to look for. if type of permission is Permission, it is returned
Returns:

Permission

Raises:

Exception if permission parameter is invalid or no permission can be found

static get_by_id(session, gid)

Get a permission by its id.

Parameters:
  • session – current session of database
  • gid – given id, which is looked for
Returns:

Permission or None

static get_by_name(session, name)

Get a permission by its name.

Parameters:
  • session – current session of database
  • name – given name, which is looked for
Returns:

Permission or None

static get_or_create_by_name(session, name)

Get or create a permission by name.

Parameters:
  • session – current session of database
  • name – name of the permission
Returns:

Permission

id
name
rename(session, newname)

Rename Permission.

Parameters:
  • session – current session of database
  • newname – new name of the permission
Raises:

Exception if newname is already in use

class vispa.models.role.Role(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

A Role is a collection of permissions (Permission objects).

add_permissions(permissions)

Add a list of permissions to the role.

Parameters:permissions (list of Permission objects) – list of permissions
Raises:TypeError if type of permissions is invalid
static all(session)

Get all existing permissions.

Parameters:session – current session of database
Returns:list of Role objects
static create(session, name)

Create new role.

Parameters:
  • session – current session of database
  • name – name of the role
Raises:

Exception if name is invalid or already in use

created
delete(session)

Delete role. It is also deleted from the database.

Parameters:session – current session of database
static get(session, role)

Get a role by name. If role is already a Role object, it is directly returned.

Parameters:
  • session – current session of database
  • role – name to look for. if type of role is Role, role is returned
Returns:

Role

Raises:

Exception if role parameter is invalid or no role can be found

static get_by_id(session, gid)

Get a role by its id.

Parameters:
  • session – current session of database
  • gid – given id, which is looked for
Returns:

Role or None

static get_by_name(session, name)

Get a role by its name.

Parameters:
  • session – current session of database
  • name – given name, which is looked for
Returns:

Role or None

static get_or_create_by_name(session, name)

Get or create a role by name.

Parameters:
  • session – current session of database
  • name – name of the role
Returns:

Role

id
name
permissions
rename(session, newname)

Rename role.

Parameters:
  • session – current session of database
  • newname – new name of the role
Raises:

Exception if newname is already in use

set_permissions(permissions)

Sets the permissions of a role.

Parameters:permissions (list of Permission objects) – list of permissions
Raises:TypeError if type of permissions is invalid

vispa.models.user module

class vispa.models.user.User(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

ACTIVE = 1
FORBIDDEN_NAMES = ['data', 'guest', 'global', 'user', 'delete', 'select', 'insert', 'update', 'drop']
INACTIVE = 0
MIN_PW_LENGTH = 8
NAME_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-+'
NAME_LENGTH = [6, 30]
PASSWORD_RESET_DELAY = 30
active()
static all(session)
created
email
static forgot_password(db, name_or_mail)
static generate_hash(length=10)
static get(session, user)
static get_by_email(session, email)
static get_by_hash(session, hash)
static get_by_id(session, uid)
static get_by_name(session, name)
get_groups()

Get groups of a user. Only active groups are returned.

Returns:list of Group_User_Assoc objects
get_managed_groups()

Get managed groups of the user. Only not deleted groups are returned.

Returns:list of Group objects
get_managed_projects()

Get managed projects of the user.

Returns:list of Project objects
get_managed_workgroups()

Get managed workgroups of the user.

Returns:list of Workgroup objects
static get_or_create_by_name(session, name, **kwargs)
get_permissions(project)

Get permissions of the user in the given project.

Parameters:project (Project) – concerning project
Returns:list of Permission objects
Raises:TypeError if project is not instance of Project
Raises:Exception if user not in project
get_projects()

Get active projects of the user.

Returns:Set of Project_User_Assoc objects, Set of Project_Group_Assoc objects
get_roles(project)

Get roles of the user in the given project.

Parameters:project (Project) – concerning project
Returns:list of Role objects
Raises:TypeError if project is not instance of Project
Raises:Exception if user not in project
get_workgroups()

Get workgroups of the user.

Returns:list of Workgroup objects
static guest_login(session)
has_permission(permissions, project)

Check if the user has the given permissions in the given project

Parameters:
  • permission (Permission or list of Permission) – permission or list of permissions to be checked
  • project (Project) – concerning project
Returns:

bool is all permissions are present

Raises:

TypeError if project is not instance of Project

Raises:

Exception if user not in project

hash
id
static is_active(session, uid)
is_in_workgroup(workgroup)

Check if the user is in the workgroup, either user or manager.

Parameters:workgroup (Workgroup) – concerning workgroup
Returns:bool whether user is manager or user of workgroup
Raises:TypeError if workgrop is not instance of Workgroup
last_password_reset
last_request
static login(session, username, password)
name
password
static register(session, name, email)
static send_registration_mail(name, email, hash)
serveradmin
static set_password(db, hash, password)
status
static update_last_request(session, uid)

vispa.models.workgroup module

class vispa.models.workgroup.Workgroup(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

A workgroup is a lighter version of a project. It only contains users, no groups, and there is no explicit management of roles and permission, which means, all users have the same rights. The memberships are organized by managers.

add_manager(user)

Add manager to workgroup.

Parameters:user (User) – user which has to be added as manager
Raises:TypeError if user is not instance of User
Raises:Exception if user is already manager of workgroup
add_user(user)

Add user to workgroup.

Parameters:user (User) – user which has to be added
Raises:TypeError if user is not instance of User
Raises:Exception if user is already in workgroup
static all(session)

Get all existing workgroups.

Parameters:session – current session of database
Returns:list of Workgroup objects
static create(session, name)

Create new workgroup.

Parameters:
  • session – current session of database
  • name – name of the workgroup
Raises:

Exception if parameter name is invalid or already in use

created
delete(session)

Delete workgroup. It is also deleted from the database.

Parameters:session – current session of database
static get(session, workgroup)

Returns workgroup, whichs name or id is given. If the parameter workgroup is already an instance of Workroup it is directly returned.

Parameters:
  • session – current session of database
  • workgroup – name or id to look for. If workgroup is instance of Workroup, it is directly returned
Returns:

Workgroup

Raises:

Exception if parameter workgroup is invalid of no workgroup can be found

static get_by_id(session, gid)

Get a workgroup by its id.

Parameters:session – current session of database
Para gid:id, which is looked for
Returns:Workgroup or None
static get_by_name(session, name)

Get a workgroup by its name.

Parameters:session – current session of database
Para name:name, which is looked for
Returns:Workgroup or None
get_items(itemtype=None)

Get WorkgroupItem.

Parameters:itemtype – optional selector on the item type
Returns:list of WorkgroupItem objects
get_managers()

Get managers of workgroup.

Returns:list of User objects
get_users()

Get users of the workgroup.

Returns:list of User objects
id
items
managers
name
remove_manager(manager)

Remove manager from workgroup.

Parameters:manager (User) – manager which has to be removed
Raises:TypeError if manager is not instance of User
Raises:Exception if manager is not manager of workgroup
remove_user(user)

Remove user from workgroup.

Parameters:user (User) – user which has to be removed
Raises:TypeError if user is not instance of User
Raises:Exception if user is not in workgroup
rename(session, newname)

Rename workgroup.

Parameters:
  • session – current session of database
  • newname – new name of the workgroup
Raises:

Exception if newname is already in use

users
class vispa.models.workgroup.WorkgroupItem(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

A workgroup item represents the actual content of a workgroup. It is simply an object consisting of a type (e.g. file) and its content (e.g. the path of the file)

content
static create(session, workgroup, itemtype, content)

Create an workgroup item. The item is added to the database.

Parameters:
  • session – current session of database
  • workgroup – workgroup of the new item
  • itemtype – type of the item
  • content – content of the item
delete(session)

Delete the item. It is also deleted from the database.

Parameters:session – current session of database
static get(session, item)

Returns item, whichs id given. If the parameter item is an instance of WorkgroupItem object, it is directly returned.

Parameters:
  • session – current session of database
  • item – id to look for. If item is an instance of WorkgroupItem, item is directly returned
Returns:

WorkgroupItem

Raises:

Exception if parameter item is invalid or no WorkgroupItem can be found

static get_by_id(session, gid)

Get a workgroup item by its id.

Parameters:
  • session – current session of database
  • gid – given id, which is looked for
Returns:

WorkgroupItem or None

get_workgroup()

Get the workgroup of the item.

Returns:Workgroup
id
itemtype
set_content(content)

Set the content of the item.

Parameters:content – new content
workgroup_id

vispa.models.workspace module

class vispa.models.workspace.Workspace(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Base

KEYS = ['id', 'user_id', 'name', 'host', 'login', 'command', 'created', 'auto_connect', 'key']
static add(db, user, name, host, login, key=None, command=None, add=True)
auto_connect
can_edit(user)
command
created
static get_by_id(db, id)
static get_user_workspace_count(db, user)
static get_user_workspaces(db, user)
has_access(user)
host
id
is_valid()
key
login
login_credentials
make_dict(keys=None)
name
static remove(db, id)
static update(db, id, **kwargs)
user_id

Module contents