Kaynağa Gözat

Closes #189: All workspaces are listed in webdav for super admin

Bastien Sevajol (Algoo) 7 yıl önce
ebeveyn
işleme
8de2760c1d

+ 5 - 10
tracim/tracim/fixtures/content.py Dosyayı Görüntüle

@@ -19,14 +19,15 @@ class Content(Fixture):
19 19
         bob = self._session.query(model.User) \
20 20
             .filter(model.User.email == 'bob@fsf.local') \
21 21
             .one()
22
-        workspace_api = WorkspaceApi(admin)
22
+        admin_workspace_api = WorkspaceApi(admin)
23
+        bob_workspace_api = WorkspaceApi(bob)
23 24
         content_api = ContentApi(admin)
24 25
         role_api = RoleApi(admin)
25 26
 
26 27
         # Workspaces
27
-        w1 = workspace_api.create_workspace('w1', save_now=True)
28
-        w2 = workspace_api.create_workspace('w2', save_now=True)
29
-        w3 = workspace_api.create_workspace('w3', save_now=True)
28
+        w1 = admin_workspace_api.create_workspace('w1', save_now=True)
29
+        w2 = bob_workspace_api.create_workspace('w2', save_now=True)
30
+        w3 = admin_workspace_api.create_workspace('w3', save_now=True)
30 31
 
31 32
         # Workspaces roles
32 33
         role_api.create_one(
@@ -35,12 +36,6 @@ class Content(Fixture):
35 36
             role_level=UserRoleInWorkspace.CONTENT_MANAGER,
36 37
             with_notif=False,
37 38
         )
38
-        role_api.create_one(
39
-            user=bob,
40
-            workspace=w2,
41
-            role_level=UserRoleInWorkspace.CONTENT_MANAGER,
42
-            with_notif=False,
43
-        )
44 39
 
45 40
         # Folders
46 41
         w1f1 = content_api.create(

+ 4 - 1
tracim/tracim/lib/webdav/sql_resources.py Dosyayı Görüntüle

@@ -109,7 +109,10 @@ class Root(DAVCollection):
109 109
         super(Root, self).__init__(path, environ)
110 110
 
111 111
         self.user = UserApi(None).get_one_by_email(environ['http_authenticator.username'])
112
-        self.workspace_api = WorkspaceApi(self.user)
112
+        # TODO BS 20170221: Web interface should list all workspace to. We
113
+        # disable it here for moment. When web interface will be updated to
114
+        # list all workspace, change this here to.
115
+        self.workspace_api = WorkspaceApi(self.user, force_role=True)
113 116
 
114 117
     def __repr__(self) -> str:
115 118
         return '<DAVCollection: Root>'

+ 7 - 2
tracim/tracim/lib/workspace.py Dosyayı Görüntüle

@@ -16,14 +16,19 @@ __author__ = 'damien'
16 16
 
17 17
 class WorkspaceApi(object):
18 18
 
19
-    def __init__(self, current_user: User):
19
+    def __init__(self, current_user: User, force_role: bool=False):
20
+        """
21
+        :param current_user: Current user of context
22
+        :param force_role: If True, app role in queries even if admin
23
+        """
20 24
         self._user = current_user
25
+        self._force_role = force_role
21 26
 
22 27
     def _base_query_without_roles(self):
23 28
         return DBSession.query(Workspace).filter(Workspace.is_deleted==False)
24 29
 
25 30
     def _base_query(self):
26
-        if self._user.profile.id>=Group.TIM_ADMIN:
31
+        if not self._force_role and self._user.profile.id>=Group.TIM_ADMIN:
27 32
             return self._base_query_without_roles()
28 33
 
29 34
         return DBSession.query(Workspace).\

+ 30 - 1
tracim/tracim/tests/library/test_webdav.py Dosyayı Görüntüle

@@ -79,7 +79,7 @@ class TestWebDav(TestStandard):
79 79
         ok_(root, msg='Path / should return a Root instance')
80 80
         ok_(isinstance(root, Root))
81 81
 
82
-    def test_unit__list_workspaces_with_admin__ok(self):
82
+    def test_unit__list_workspaces_with_user__ok(self):
83 83
         provider = self._get_provider()
84 84
         root = provider.getResourceInst(
85 85
             '/',
@@ -108,6 +108,35 @@ class TestWebDav(TestStandard):
108 108
             workspaces_names,
109 109
         ))
110 110
 
111
+    def test_unit__list_workspaces_with_admin__ok(self):
112
+        provider = self._get_provider()
113
+        root = provider.getResourceInst(
114
+            '/',
115
+            self._get_environ(
116
+                provider,
117
+                'admin@admin.admin',
118
+            )
119
+        )
120
+        ok_(root, msg='Path / should return a Root instance')
121
+        ok_(isinstance(root, Root), msg='Path / should return a Root instance')
122
+
123
+        children = root.getMemberList()
124
+        eq_(
125
+            2,
126
+            len(children),
127
+            msg='Root should return 2 workspaces instead {0}'.format(
128
+                len(children),
129
+            )
130
+        )
131
+
132
+        workspaces_names = [w.name for w in children]
133
+        ok_('w1' in workspaces_names, msg='w1 should be in names ({0})'.format(
134
+            workspaces_names,
135
+        ))
136
+        ok_('w3' in workspaces_names, msg='w3 should be in names ({0})'.format(
137
+            workspaces_names,
138
+        ))
139
+
111 140
     def test_unit__list_workspace_folders__ok(self):
112 141
         provider = self._get_provider()
113 142
         w1 = provider.getResourceInst(