|
@@ -2,12 +2,14 @@
|
2
|
2
|
from nose.tools import eq_
|
3
|
3
|
|
4
|
4
|
from tracim.lib.content import ContentApi
|
|
5
|
+from tracim.lib.group import GroupApi
|
5
|
6
|
from tracim.lib.user import UserApi
|
6
|
7
|
from tracim.lib.userworkspace import RoleApi
|
7
|
8
|
from tracim.lib.workspace import WorkspaceApi
|
8
|
9
|
from tracim.model import Content
|
9
|
10
|
from tracim.model import DBSession
|
10
|
11
|
from tracim.model import User
|
|
12
|
+from tracim.model.auth import Group
|
11
|
13
|
from tracim.model.data import UserRoleInWorkspace
|
12
|
14
|
from tracim.model.data import Workspace
|
13
|
15
|
from tracim.tests import BaseTestThread
|
|
@@ -41,3 +43,33 @@ class TestThread(BaseTestThread, TestStandard):
|
41
|
43
|
eq_([r, ], wapi.get_notifiable_roles(workspace=w))
|
42
|
44
|
u.is_active = False
|
43
|
45
|
eq_([], wapi.get_notifiable_roles(workspace=w))
|
|
46
|
+
|
|
47
|
+ def test_unit__get_all_admin_for_user(self):
|
|
48
|
+ admin = DBSession.query(User) \
|
|
49
|
+ .filter(User.email == 'admin@admin.admin').one()
|
|
50
|
+ uapi = UserApi(admin)
|
|
51
|
+ # Checks a case without workspaces.
|
|
52
|
+ wapi = WorkspaceApi(current_user=admin)
|
|
53
|
+ eq_([], wapi.get_all_manageable_for_user(user=admin))
|
|
54
|
+ # Checks an admin gets all workspaces.
|
|
55
|
+ w4 = wapi.create_workspace(label='w4')
|
|
56
|
+ w3 = wapi.create_workspace(label='w3')
|
|
57
|
+ w2 = wapi.create_workspace(label='w2')
|
|
58
|
+ w1 = wapi.create_workspace(label='w1')
|
|
59
|
+ eq_([w1, w2, w3, w4], wapi.get_all_manageable_for_user(user=admin))
|
|
60
|
+ # Checks a regular user gets none workspace.
|
|
61
|
+ gapi = GroupApi(None)
|
|
62
|
+ u = uapi.create_user('u.s@e.r', [gapi.get_one(Group.TIM_USER)], True)
|
|
63
|
+ wapi = WorkspaceApi(current_user=u)
|
|
64
|
+ rapi = RoleApi(current_user=u)
|
|
65
|
+ off = 'off'
|
|
66
|
+ rapi.create_one(u, w4, UserRoleInWorkspace.READER, off)
|
|
67
|
+ rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, off)
|
|
68
|
+ rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, off)
|
|
69
|
+ rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, off)
|
|
70
|
+ eq_([], wapi.get_all_manageable_for_user(user=u))
|
|
71
|
+ # Checks a manager gets only its own workspaces.
|
|
72
|
+ u.groups.append(gapi.get_one(Group.TIM_MANAGER))
|
|
73
|
+ rapi.delete_one(u.user_id, w2.workspace_id)
|
|
74
|
+ rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, off)
|
|
75
|
+ eq_([w1, w2], wapi.get_all_manageable_for_user(user=u))
|