Services¶
UserService¶
-
class
ziggurat_foundations.models.services.user.
UserService
¶ -
classmethod
by_email
(email, db_session=None)¶ fetch user object by email
Parameters: - email –
- db_session –
Returns:
-
classmethod
by_email_and_username
(email, user_name, db_session=None)¶ fetch user object by email and username
Parameters: - email –
- user_name –
- db_session –
Returns:
-
classmethod
by_id
(user_id, db_session=None)¶ fetch user by user id
Parameters: - user_id –
- db_session –
Returns:
-
classmethod
by_user_name
(user_name, db_session=None)¶ fetch user by user name
Parameters: - user_name –
- db_session –
Returns:
-
classmethod
by_user_name_and_security_code
(user_name, security_code, db_session=None)¶ fetch user objects by user name and security code
Parameters: - user_name –
- security_code –
- db_session –
Returns:
-
classmethod
by_user_names
(user_names, db_session=None)¶ fetch user objects by user names
Parameters: - user_names –
- db_session –
Returns:
-
classmethod
check_password
(instance, raw_password, enable_hash_migration=True)¶ checks string with users password hash using password manager
Parameters: - instance –
- raw_password –
- enable_hash_migration – if legacy hashes should be migrated
Returns:
-
classmethod
generate_random_pass
(chars=7)¶ generates random string of fixed length
Parameters: chars – Returns:
-
static
generate_random_string
(chars=7)¶ Parameters: chars – Returns:
-
classmethod
get
(user_id, db_session=None)¶ Fetch row using primary key - will use existing object in session if already present
Parameters: - user_id –
- db_session –
Returns:
-
classmethod
gravatar_url
(instance, default=u'mm', **kwargs)¶ returns user gravatar url
Parameters: - instance –
- default –
- kwargs –
Returns:
-
classmethod
groups_with_resources
(instance)¶ Returns a list of groups users belongs to with eager loaded resources owned by those groups
Parameters: instance – Returns:
-
classmethod
permissions
(instance, db_session=None)¶ - returns all non-resource permissions based on what groups user
- belongs and directly set ones for this user
Parameters: - instance –
- db_session –
Returns:
-
classmethod
regenerate_security_code
(instance)¶ generates new security code
Parameters: instance – Returns:
-
classmethod
resources_with_perms
(instance, perms, resource_ids=None, resource_types=None, db_session=None)¶ - returns all resources that user has perms for
- (note that at least one perm needs to be met)
Parameters: - instance –
- perms –
- resource_ids – restricts the search to specific resources
- resource_types –
- db_session –
Returns:
-
classmethod
resources_with_possible_perms
(instance, resource_ids=None, resource_types=None, db_session=None)¶ returns list of permissions and resources for this user
Parameters: - instance –
- resource_ids – restricts the search to specific resources
- resource_types – restricts the search to specific resource types
- db_session –
Returns:
-
classmethod
set_password
(instance, raw_password)¶ sets new password on a user using password manager
Parameters: - instance –
- raw_password –
Returns:
-
classmethod
user_names_like
(user_name, db_session=None)¶ fetch users with similar names using LIKE clause
Parameters: - user_name –
- db_session –
Returns:
-
classmethod
users_for_perms
(perm_names, db_session=None)¶ return users hat have one of given permissions
Parameters: - perm_names –
- db_session –
Returns:
-
classmethod
ExternalIdentityService¶
-
class
ziggurat_foundations.models.services.external_identity.
ExternalIdentityService
¶ -
classmethod
by_external_id_and_provider
(external_id, provider_name, db_session=None)¶ Returns ExternalIdentity instance based on search params
Parameters: - external_id –
- provider_name –
- db_session –
Returns: ExternalIdentity
-
classmethod
get
(external_id, local_user_id, provider_name, db_session=None)¶ Fetch row using primary key - will use existing object in session if already present
Parameters: - external_id –
- local_user_id –
- provider_name –
- db_session –
Returns:
-
classmethod
user_by_external_id_and_provider
(external_id, provider_name, db_session=None)¶ Returns User instance based on search params
Parameters: - external_id –
- provider_name –
- db_session –
Returns: User
-
classmethod
GroupService¶
-
class
ziggurat_foundations.models.services.group.
GroupService
¶ -
classmethod
by_group_name
(group_name, db_session=None)¶ fetch group by name
Parameters: - group_name –
- db_session –
Returns:
-
classmethod
get
(group_id, db_session=None)¶ Fetch row using primary key - will use existing object in session if already present
Parameters: - group_id –
- db_session –
Returns:
-
classmethod
get_user_paginator
(instance, page=1, item_count=None, items_per_page=50, user_ids=None, GET_params=None)¶ returns paginator over users belonging to the group
Parameters: - instance –
- page –
- item_count –
- items_per_page –
- user_ids –
- GET_params –
Returns:
-
classmethod
resources_with_possible_perms
(instance, perm_names=None, resource_ids=None, resource_types=None, db_session=None)¶ - returns list of permissions and resources for this group,
- resource_ids restricts the search to specific resources
Parameters: - instance –
- perm_names –
- resource_ids –
- resource_types –
- db_session –
Returns:
-
classmethod
GroupPermissionService¶
-
class
ziggurat_foundations.models.services.group_permission.
GroupPermissionService
¶ -
classmethod
by_group_and_perm
(group_id, perm_name, db_session=None)¶ return by by_user_and_perm and permission name
Parameters: - group_id –
- perm_name –
- db_session –
Returns:
-
classmethod
get
(group_id, perm_name, db_session=None)¶ Fetch row using primary key - will use existing object in session if already present
Parameters: - group_id –
- perm_name –
- db_session –
Returns:
-
classmethod
UserPermissionService¶
-
class
ziggurat_foundations.models.services.user_permission.
UserPermissionService
¶ -
classmethod
by_user_and_perm
(user_id, perm_name, db_session=None)¶ return by user and permission name
Parameters: - user_id –
- perm_name –
- db_session –
Returns:
-
classmethod
get
(user_id, perm_name, db_session=None)¶ Fetch row using primary key - will use existing object in session if already present
Parameters: - user_id –
- perm_name –
- db_session –
Returns:
-
classmethod
UserResourcePermissionService¶
-
class
ziggurat_foundations.models.services.user_resource_permission.
UserResourcePermissionService
¶ -
classmethod
by_resource_user_and_perm
(user_id, perm_name, resource_id, db_session=None)¶ return all instances by user name, perm name and resource id
Parameters: - user_id –
- perm_name –
- resource_id –
- db_session –
Returns:
-
classmethod
get
(user_id, resource_id, perm_name, db_session=None)¶ Fetch row using primary key - will use existing object in session if already present
Parameters: - user_id –
- resource_id –
- perm_name –
- db_session –
Returns:
-
classmethod
ResourceService¶
-
class
ziggurat_foundations.models.services.resource.
ResourceService
¶ -
classmethod
by_resource_id
(resource_id, db_session=None)¶ fetch the resouce by id
Parameters: - resource_id –
- db_session –
Returns:
-
classmethod
direct_perms_for_user
(instance, user, db_session=None)¶ - returns permissions that given user has for this resource
- without ones inherited from groups that user belongs to
Parameters: - instance –
- user –
- db_session –
Returns:
-
classmethod
get
(resource_id, db_session=None)¶ Fetch row using primary key - will use existing object in session if already present
Parameters: - resource_id –
- db_session –
Returns:
-
classmethod
group_perms_for_user
(instance, user, db_session=None)¶ - returns permissions that given user has for this resource
- that are inherited from groups
Parameters: - instance –
- user –
- db_session –
Returns:
-
classmethod
groups_for_perm
(instance, perm_name, group_ids=None, limit_group_permissions=False, db_session=None)¶ return PermissionTuples for groups that have given permission for the resource, perm_name is __any_permission__ then users with any permission will be listed
Parameters: - instance –
- perm_name –
- group_ids – limits the permissions to specific group ids
- limit_group_permissions – should be used if we do not want to have
user objects returned for group permissions, this might cause performance issues for big groups :param db_session: :return:
-
classmethod
lock_resource_for_update
(resource_id, db_session)¶ Selects resource for update - locking access for other transactions
Parameters: - resource_id –
- db_session –
Returns:
-
classmethod
perm_by_group_and_perm_name
(resource_id, group_id, perm_name, db_session=None)¶ fetch permissions by group and permission name
Parameters: - resource_id –
- group_id –
- perm_name –
- db_session –
Returns:
-
classmethod
perms_for_user
(instance, user, db_session=None)¶ - returns all permissions that given user has for this resource
- from groups and directly set ones too
Parameters: - instance –
- user –
- db_session –
Returns:
-
classmethod
users_for_perm
(instance, perm_name, user_ids=None, group_ids=None, limit_group_permissions=False, skip_group_perms=False, db_session=None)¶ return PermissionTuples for users AND groups that have given permission for the resource, perm_name is __any_permission__ then users with any permission will be listed
Parameters: - instance –
- perm_name –
- user_ids – limits the permissions to specific user ids
- group_ids – limits the permissions to specific group ids
- limit_group_permissions – should be used if we do not want to have
user objects returned for group permissions, this might cause performance issues for big groups :param skip_group_perms: do not attach group permissions to the resultset :param db_session: :return:
-
classmethod
ResourceTreeService¶
-
class
ziggurat_foundations.models.services.resource_tree.
ResourceTreeService
(service_cls)¶ -
build_subtree_strut
(result, *args, **kwargs)¶ Returns a dictionary in form of {node:Resource, children:{node_id: Resource}}
Parameters: result – Returns:
-
check_node_parent
(resource_id, new_parent_id, db_session=None, *args, **kwargs)¶ Checks if parent destination is valid for node
Parameters: - resource_id –
- new_parent_id –
- db_session –
Returns:
-
check_node_position
(parent_id, position, on_same_branch, db_session=None, *args, **kwargs)¶ Checks if node position for given parent is valid, raises exception if this is not the case
Parameters: - parent_id –
- position –
- on_same_branch – indicates that we are checking same branch
- db_session –
Returns:
-
count_children
(resource_id, db_session=None, *args, **kwargs)¶ Counts children of resource node
Parameters: - resource_id –
- db_session –
Returns:
-
delete_branch
(resource_id=None, db_session=None, *args, **kwargs)¶ This deletes whole branch with children starting from resource_id
Parameters: - resource_id –
- db_session –
Returns:
-
from_parent_deeper
(parent_id=None, limit_depth=1000000, db_session=None, *args, **kwargs)¶ This returns you subtree of ordered objects relative to the start parent_id (currently only implemented in postgresql)
Parameters: - resource_id –
- limit_depth –
- db_session –
Returns:
-
from_resource_deeper
(resource_id=None, limit_depth=1000000, db_session=None, *args, **kwargs)¶ This returns you subtree of ordered objects relative to the start resource_id (currently only implemented in postgresql)
Parameters: - resource_id –
- limit_depth –
- db_session –
Returns:
-
move_to_position
(resource_id, to_position, new_parent_id=<ziggurat_foundations.utils.NOOP object>, db_session=None, *args, **kwargs)¶ Moves node to new location in the tree
Parameters: - resource_id – resource to move
- to_position – new position
- new_parent_id – new parent id
- db_session –
Returns:
-
path_upper
(object_id, limit_depth=1000000, db_session=None, *args, **kwargs)¶ - This returns you path to root node starting from object_id
- currently only for postgresql
Parameters: - object_id –
- limit_depth –
- db_session –
Returns:
-
set_position
(resource_id, to_position, db_session=None, *args, **kwargs)¶ Sets node position for new node in the tree
Parameters: - resource_id – resource to move
- to_position – new position
- db_session –
:return:def count_children(cls, resource_id, db_session=None):
-
shift_ordering_down
(parent_id, position, db_session=None, *args, **kwargs)¶ Shifts ordering to “close gaps” after node deletion or being moved to another branch, begins the shift from given position
Parameters: - parent_id –
- position –
- db_session –
Returns:
-
shift_ordering_up
(parent_id, position, db_session=None, *args, **kwargs)¶ Shifts ordering to “open a gap” for node insertion, begins the shift from given position
Parameters: - parent_id –
- position –
- db_session –
Returns:
-
ResourceTreeServicePostgreSQL¶
-
class
ziggurat_foundations.models.services.resource_tree_postgres.
ResourceTreeServicePostgreSQL
¶ -
classmethod
build_subtree_strut
(result, *args, **kwargs)¶ Returns a dictionary in form of {node:Resource, children:{node_id: Resource}}
Parameters: result – Returns:
-
classmethod
check_node_parent
(resource_id, new_parent_id, db_session=None, *args, **kwargs)¶ Checks if parent destination is valid for node
Parameters: - resource_id –
- new_parent_id –
- db_session –
Returns:
-
classmethod
check_node_position
(parent_id, position, on_same_branch, db_session=None, *args, **kwargs)¶ Checks if node position for given parent is valid, raises exception if this is not the case
Parameters: - parent_id –
- position –
- on_same_branch – indicates that we are checking same branch
- db_session –
Returns:
-
classmethod
count_children
(resource_id, db_session=None, *args, **kwargs)¶ Counts children of resource node
Parameters: - resource_id –
- db_session –
Returns:
-
classmethod
delete_branch
(resource_id=None, db_session=None, *args, **kwargs)¶ This deletes whole branch with children starting from resource_id
Parameters: - resource_id –
- db_session –
Returns:
-
classmethod
from_parent_deeper
(parent_id=None, limit_depth=1000000, db_session=None, *args, **kwargs)¶ This returns you subtree of ordered objects relative to the start parent_id (currently only implemented in postgresql)
Parameters: - resource_id –
- limit_depth –
- db_session –
Returns:
-
classmethod
from_resource_deeper
(resource_id=None, limit_depth=1000000, db_session=None, *args, **kwargs)¶ This returns you subtree of ordered objects relative to the start resource_id (currently only implemented in postgresql)
Parameters: - resource_id –
- limit_depth –
- db_session –
Returns:
-
classmethod
move_to_position
(resource_id, to_position, new_parent_id=<ziggurat_foundations.utils.NOOP object>, db_session=None, *args, **kwargs)¶ Moves node to new location in the tree
Parameters: - resource_id – resource to move
- to_position – new position
- new_parent_id – new parent id
- db_session –
Returns:
-
classmethod
path_upper
(object_id, limit_depth=1000000, db_session=None, *args, **kwargs)¶ - This returns you path to root node starting from object_id
- currently only for postgresql
Parameters: - object_id –
- limit_depth –
- db_session –
Returns:
-
classmethod
set_position
(resource_id, to_position, db_session=None, *args, **kwargs)¶ Sets node position for new node in the tree
Parameters: - resource_id – resource to move
- to_position – new position
- db_session –
:return:def count_children(cls, resource_id, db_session=None):
-
classmethod
shift_ordering_down
(parent_id, position, db_session=None, *args, **kwargs)¶ Shifts ordering to “close gaps” after node deletion or being moved to another branch, begins the shift from given position
Parameters: - parent_id –
- position –
- db_session –
Returns:
-
classmethod
shift_ordering_up
(parent_id, position, db_session=None, *args, **kwargs)¶ Shifts ordering to “open a gap” for node insertion, begins the shift from given position
Parameters: - parent_id –
- position –
- db_session –
Returns:
-
classmethod