|
1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
from tracim.lib.core.content import ContentApi |
|
4
|
|
|
from tracim.lib.core.group import GroupApi |
|
5
|
|
|
from tracim.lib.core.user import UserApi |
|
6
|
|
|
from tracim.lib.core.userworkspace import RoleApi |
|
7
|
|
|
from tracim.lib.core.workspace import WorkspaceApi |
|
8
|
|
|
from tracim.models import Content |
|
9
|
|
|
from tracim.models import User |
|
10
|
|
|
from tracim.models.auth import Group |
|
11
|
|
|
from tracim.models.data import UserRoleInWorkspace |
|
12
|
|
|
from tracim.models.data import Workspace |
|
13
|
|
|
#from tracim.tests import BaseTestThread |
|
14
|
|
|
from tracim.tests import DefaultTest |
|
15
|
|
|
from tracim.tests import eq_ |
|
16
|
|
|
|
|
17
|
|
|
class TestThread(DefaultTest): |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
def test_children(self): |
|
|
|
|
|
|
20
|
|
|
admin = self.session.query(User).filter( |
|
21
|
|
|
User.email == '[email protected]' |
|
22
|
|
|
).one() |
|
23
|
|
|
self._create_thread_and_test( |
|
24
|
|
|
workspace_name='workspace_1', |
|
25
|
|
|
folder_name='folder_1', |
|
26
|
|
|
thread_name='thread_1', |
|
27
|
|
|
user=admin |
|
28
|
|
|
) |
|
29
|
|
|
workspace = self.session.query(Workspace).filter( |
|
30
|
|
|
Workspace.label == 'workspace_1' |
|
31
|
|
|
).one() |
|
32
|
|
|
content_api = ContentApi( |
|
33
|
|
|
session=self.session, |
|
34
|
|
|
current_user=admin, |
|
35
|
|
|
config=self.app_config, |
|
36
|
|
|
) |
|
37
|
|
|
folder = content_api.get_canonical_query().filter( |
|
38
|
|
|
Content.label == 'folder_1' |
|
39
|
|
|
).one() |
|
40
|
|
|
eq_([folder, ], list(workspace.get_valid_children())) |
|
41
|
|
|
|
|
42
|
|
|
def test_get_notifiable_roles(self): |
|
|
|
|
|
|
43
|
|
|
admin = self.session.query(User) \ |
|
44
|
|
|
.filter(User.email == '[email protected]').one() |
|
45
|
|
|
wapi = WorkspaceApi( |
|
46
|
|
|
session=self.session, |
|
47
|
|
|
current_user=admin, |
|
48
|
|
|
) |
|
49
|
|
|
w = wapi.create_workspace(label='workspace w', save_now=True) |
|
|
|
|
|
|
50
|
|
|
uapi = UserApi( |
|
51
|
|
|
session=self.session, |
|
52
|
|
|
current_user=admin, |
|
53
|
|
|
config=self.config |
|
54
|
|
|
) |
|
55
|
|
|
u = uapi.create_user(email='[email protected]', save_now=True) |
|
|
|
|
|
|
56
|
|
|
eq_([], wapi.get_notifiable_roles(workspace=w)) |
|
57
|
|
|
rapi = RoleApi( |
|
58
|
|
|
session=self.session, |
|
59
|
|
|
current_user=admin, |
|
60
|
|
|
) |
|
61
|
|
|
r = rapi.create_one(u, w, UserRoleInWorkspace.READER, with_notif=True) |
|
|
|
|
|
|
62
|
|
|
eq_([r, ], wapi.get_notifiable_roles(workspace=w)) |
|
63
|
|
|
u.is_active = False |
|
64
|
|
|
eq_([], wapi.get_notifiable_roles(workspace=w)) |
|
65
|
|
|
|
|
66
|
|
|
def test_unit__get_all_manageable(self): |
|
|
|
|
|
|
67
|
|
|
admin = self.session.query(User) \ |
|
68
|
|
|
.filter(User.email == '[email protected]').one() |
|
69
|
|
|
uapi = UserApi( |
|
70
|
|
|
session=self.session, |
|
71
|
|
|
current_user=admin, |
|
72
|
|
|
config=self.config, |
|
73
|
|
|
) |
|
74
|
|
|
# Checks a case without workspaces. |
|
75
|
|
|
wapi = WorkspaceApi( |
|
76
|
|
|
session=self.session, |
|
77
|
|
|
current_user=admin, |
|
78
|
|
|
) |
|
79
|
|
|
eq_([], wapi.get_all_manageable()) |
|
80
|
|
|
# Checks an admin gets all workspaces. |
|
81
|
|
|
w4 = wapi.create_workspace(label='w4') |
|
|
|
|
|
|
82
|
|
|
w3 = wapi.create_workspace(label='w3') |
|
|
|
|
|
|
83
|
|
|
w2 = wapi.create_workspace(label='w2') |
|
|
|
|
|
|
84
|
|
|
w1 = wapi.create_workspace(label='w1') |
|
|
|
|
|
|
85
|
|
|
eq_([w1, w2, w3, w4], wapi.get_all_manageable()) |
|
86
|
|
|
# Checks a regular user gets none workspace. |
|
87
|
|
|
gapi = GroupApi( |
|
88
|
|
|
session=self.session, |
|
89
|
|
|
current_user=None, |
|
90
|
|
|
) |
|
91
|
|
|
u = uapi.create_user('[email protected]', [gapi.get_one(Group.TIM_USER)], True) |
|
|
|
|
|
|
92
|
|
|
wapi = WorkspaceApi( |
|
93
|
|
|
session=self.session, |
|
94
|
|
|
current_user=u |
|
95
|
|
|
) |
|
96
|
|
|
rapi = RoleApi( |
|
97
|
|
|
session=self.session, |
|
98
|
|
|
current_user=u |
|
99
|
|
|
) |
|
100
|
|
|
rapi.create_one(u, w4, UserRoleInWorkspace.READER, False) |
|
101
|
|
|
rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, False) |
|
102
|
|
|
rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, False) |
|
103
|
|
|
rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, False) |
|
104
|
|
|
eq_([], wapi.get_all_manageable()) |
|
105
|
|
|
# Checks a manager gets only its own workspaces. |
|
106
|
|
|
u.groups.append(gapi.get_one(Group.TIM_MANAGER)) |
|
107
|
|
|
rapi.delete_one(u.user_id, w2.workspace_id) |
|
108
|
|
|
rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, False) |
|
109
|
|
|
eq_([w1, w2], wapi.get_all_manageable()) |
|
110
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.