Pārlūkot izejas kodu

Use current user in WorkspaceApi.get_all_manageable

Adrien Panay 7 gadus atpakaļ
vecāks
revīzija
e4c82cfc3f

+ 1 - 1
tracim/tracim/controllers/admin/workspace.py Parādīt failu

@@ -159,7 +159,7 @@ class WorkspaceRestController(TIMRestController, BaseController):
159 159
     def get_all(self, *args, **kw):
160 160
         user = tmpl_context.current_user
161 161
         workspace_api_controller = WorkspaceApi(user)
162
-        workspaces = workspace_api_controller.get_all_manageable_for_user(user)
162
+        workspaces = workspace_api_controller.get_all_manageable()
163 163
         current_user_content = Context(CTX.CURRENT_USER).toDict(user)
164 164
         fake_api = Context(CTX.ADMIN_WORKSPACE) \
165 165
             .toDict(

+ 9 - 9
tracim/tracim/lib/workspace.py Parādīt failu

@@ -1,16 +1,16 @@
1 1
 # -*- coding: utf-8 -*-
2
-import transaction
2
+import typing
3 3
 
4 4
 from sqlalchemy.orm import Query
5 5
 from tg.i18n import ugettext as _
6
-from typing import List
6
+import transaction
7 7
 
8 8
 from tracim.lib.userworkspace import RoleApi
9
+from tracim.model import DBSession
9 10
 from tracim.model.auth import Group
10 11
 from tracim.model.auth import User
11
-from tracim.model.data import Workspace
12 12
 from tracim.model.data import UserRoleInWorkspace
13
-from tracim.model import DBSession
13
+from tracim.model.data import Workspace
14 14
 
15 15
 __author__ = 'damien'
16 16
 
@@ -102,12 +102,12 @@ class WorkspaceApi(object):
102 102
         workspaces.sort(key=lambda workspace: workspace.label.lower())
103 103
         return workspaces
104 104
 
105
-    def get_all_manageable_for_user(self, user: User) -> List[Workspace]:
106
-        """Get all workspaces the given user has manager rights on."""
107
-        workspaces = []
108
-        if user.profile.id == Group.TIM_ADMIN:
105
+    def get_all_manageable(self) -> typing.List[Workspace]:
106
+        """Get all workspaces the current user has manager rights on."""
107
+        workspaces = []  # type: typing.List[Workspace]
108
+        if self._user.profile.id == Group.TIM_ADMIN:
109 109
             workspaces = self._base_query().order_by(Workspace.label).all()
110
-        elif user.profile.id == Group.TIM_MANAGER:
110
+        elif self._user.profile.id == Group.TIM_MANAGER:
111 111
             workspaces = self._base_query() \
112 112
                 .filter(
113 113
                     UserRoleInWorkspace.role ==

+ 5 - 5
tracim/tracim/tests/library/test_workspace.py Parādīt failu

@@ -44,19 +44,19 @@ class TestThread(BaseTestThread, TestStandard):
44 44
         u.is_active = False
45 45
         eq_([], wapi.get_notifiable_roles(workspace=w))
46 46
 
47
-    def test_unit__get_all_admin_for_user(self):
47
+    def test_unit__get_all_manageable(self):
48 48
         admin = DBSession.query(User) \
49 49
             .filter(User.email == 'admin@admin.admin').one()
50 50
         uapi = UserApi(admin)
51 51
         # Checks a case without workspaces.
52 52
         wapi = WorkspaceApi(current_user=admin)
53
-        eq_([], wapi.get_all_manageable_for_user(user=admin))
53
+        eq_([], wapi.get_all_manageable())
54 54
         # Checks an admin gets all workspaces.
55 55
         w4 = wapi.create_workspace(label='w4')
56 56
         w3 = wapi.create_workspace(label='w3')
57 57
         w2 = wapi.create_workspace(label='w2')
58 58
         w1 = wapi.create_workspace(label='w1')
59
-        eq_([w1, w2, w3, w4], wapi.get_all_manageable_for_user(user=admin))
59
+        eq_([w1, w2, w3, w4], wapi.get_all_manageable())
60 60
         # Checks a regular user gets none workspace.
61 61
         gapi = GroupApi(None)
62 62
         u = uapi.create_user('u.s@e.r', [gapi.get_one(Group.TIM_USER)], True)
@@ -67,9 +67,9 @@ class TestThread(BaseTestThread, TestStandard):
67 67
         rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, off)
68 68
         rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, off)
69 69
         rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, off)
70
-        eq_([], wapi.get_all_manageable_for_user(user=u))
70
+        eq_([], wapi.get_all_manageable())
71 71
         # Checks a manager gets only its own workspaces.
72 72
         u.groups.append(gapi.get_one(Group.TIM_MANAGER))
73 73
         rapi.delete_one(u.user_id, w2.workspace_id)
74 74
         rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, off)
75
-        eq_([w1, w2], wapi.get_all_manageable_for_user(user=u))
75
+        eq_([w1, w2], wapi.get_all_manageable())