projectal.entities.user

 1from projectal import api
 2from projectal.entity import Entity
 3from projectal.linkers import *
 4
 5
 6class User(Entity, AccessPolicyLinker, PermissionLinker, NoteLinker, TagLinker):
 7    """
 8    Implementation of the [User](https://projectal.com/docs/latest/#tag/User) API.
 9    """
10    _path = 'user'
11    _name = 'user'
12    _links = [AccessPolicyLinker, PermissionLinker, NoteLinker, TagLinker]
13
14    def register(self):
15        url = '/api/user/registration/{}'.format(self['uuId'])
16        return api.post(url)
17
18    def set_password(self, password, token_id):
19        url = '/auth/register/password'
20        payload = {
21            'password': password,
22            'confirm': password,
23            'tokenId': token_id
24        }
25        api.post(url, payload=payload)
26        return True
27
28    @classmethod
29    def current_user_permissions(cls):
30        """
31        Get the authenticated user's permissions as a list.
32        """
33        return api.get('/api/user/permissions')['permissions']
34
35    def link_permission(self, permissions):
36        self.__permission(self, permissions, 'add')
37
38    def unlink_permission(self, permissions):
39        self.__permission(self, permissions, 'delete')
40
41    @classmethod
42    def __permission(cls, from_user, to_permissions, operation):
43        if isinstance(to_permissions, dict):
44            to_permissions = [to_permissions]
45
46        url = '/api/user/permission/{}'.format(operation)
47        payload = [{
48            'uuId': from_user['uuId'],
49            'permissionList': to_permissions
50        }]
51        api.post(url, payload=payload)
52        return True
53
54    @classmethod
55    def current_user_details(cls):
56        """Get some details about the authenticated user."""
57        return api.get('/api/user/details')
58
59    @classmethod
60    def get_permissions(cls, user):
61        """Get the permissions assigned to a specific User entity."""
62        url = '/api/user/get/{}/permissions'.format(user['uuId'])
63        return api.get(url)['data']
 7class User(Entity, AccessPolicyLinker, PermissionLinker, NoteLinker, TagLinker):
 8    """
 9    Implementation of the [User](https://projectal.com/docs/latest/#tag/User) API.
10    """
11    _path = 'user'
12    _name = 'user'
13    _links = [AccessPolicyLinker, PermissionLinker, NoteLinker, TagLinker]
14
15    def register(self):
16        url = '/api/user/registration/{}'.format(self['uuId'])
17        return api.post(url)
18
19    def set_password(self, password, token_id):
20        url = '/auth/register/password'
21        payload = {
22            'password': password,
23            'confirm': password,
24            'tokenId': token_id
25        }
26        api.post(url, payload=payload)
27        return True
28
29    @classmethod
30    def current_user_permissions(cls):
31        """
32        Get the authenticated user's permissions as a list.
33        """
34        return api.get('/api/user/permissions')['permissions']
35
36    def link_permission(self, permissions):
37        self.__permission(self, permissions, 'add')
38
39    def unlink_permission(self, permissions):
40        self.__permission(self, permissions, 'delete')
41
42    @classmethod
43    def __permission(cls, from_user, to_permissions, operation):
44        if isinstance(to_permissions, dict):
45            to_permissions = [to_permissions]
46
47        url = '/api/user/permission/{}'.format(operation)
48        payload = [{
49            'uuId': from_user['uuId'],
50            'permissionList': to_permissions
51        }]
52        api.post(url, payload=payload)
53        return True
54
55    @classmethod
56    def current_user_details(cls):
57        """Get some details about the authenticated user."""
58        return api.get('/api/user/details')
59
60    @classmethod
61    def get_permissions(cls, user):
62        """Get the permissions assigned to a specific User entity."""
63        url = '/api/user/get/{}/permissions'.format(user['uuId'])
64        return api.get(url)['data']

Implementation of the User API.

def register(self):
15    def register(self):
16        url = '/api/user/registration/{}'.format(self['uuId'])
17        return api.post(url)
def set_password(self, password, token_id):
19    def set_password(self, password, token_id):
20        url = '/auth/register/password'
21        payload = {
22            'password': password,
23            'confirm': password,
24            'tokenId': token_id
25        }
26        api.post(url, payload=payload)
27        return True
@classmethod
def current_user_permissions(cls):
29    @classmethod
30    def current_user_permissions(cls):
31        """
32        Get the authenticated user's permissions as a list.
33        """
34        return api.get('/api/user/permissions')['permissions']

Get the authenticated user's permissions as a list.

@classmethod
def current_user_details(cls):
55    @classmethod
56    def current_user_details(cls):
57        """Get some details about the authenticated user."""
58        return api.get('/api/user/details')

Get some details about the authenticated user.

@classmethod
def get_permissions(cls, user):
60    @classmethod
61    def get_permissions(cls, user):
62        """Get the permissions assigned to a specific User entity."""
63        url = '/api/user/get/{}/permissions'.format(user['uuId'])
64        return api.get(url)['data']

Get the permissions assigned to a specific User entity.