Browse Source

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

Bastien Sevajol (Algoo) 8 years ago
parent
commit
8de2760c1d

+ 5 - 10
tracim/tracim/fixtures/content.py View File

19
         bob = self._session.query(model.User) \
19
         bob = self._session.query(model.User) \
20
             .filter(model.User.email == 'bob@fsf.local') \
20
             .filter(model.User.email == 'bob@fsf.local') \
21
             .one()
21
             .one()
22
-        workspace_api = WorkspaceApi(admin)
22
+        admin_workspace_api = WorkspaceApi(admin)
23
+        bob_workspace_api = WorkspaceApi(bob)
23
         content_api = ContentApi(admin)
24
         content_api = ContentApi(admin)
24
         role_api = RoleApi(admin)
25
         role_api = RoleApi(admin)
25
 
26
 
26
         # Workspaces
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
         # Workspaces roles
32
         # Workspaces roles
32
         role_api.create_one(
33
         role_api.create_one(
35
             role_level=UserRoleInWorkspace.CONTENT_MANAGER,
36
             role_level=UserRoleInWorkspace.CONTENT_MANAGER,
36
             with_notif=False,
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
         # Folders
40
         # Folders
46
         w1f1 = content_api.create(
41
         w1f1 = content_api.create(

+ 4 - 1
tracim/tracim/lib/webdav/sql_resources.py View File

109
         super(Root, self).__init__(path, environ)
109
         super(Root, self).__init__(path, environ)
110
 
110
 
111
         self.user = UserApi(None).get_one_by_email(environ['http_authenticator.username'])
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
     def __repr__(self) -> str:
117
     def __repr__(self) -> str:
115
         return '<DAVCollection: Root>'
118
         return '<DAVCollection: Root>'

+ 7 - 2
tracim/tracim/lib/workspace.py View File

16
 
16
 
17
 class WorkspaceApi(object):
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
         self._user = current_user
24
         self._user = current_user
25
+        self._force_role = force_role
21
 
26
 
22
     def _base_query_without_roles(self):
27
     def _base_query_without_roles(self):
23
         return DBSession.query(Workspace).filter(Workspace.is_deleted==False)
28
         return DBSession.query(Workspace).filter(Workspace.is_deleted==False)
24
 
29
 
25
     def _base_query(self):
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
             return self._base_query_without_roles()
32
             return self._base_query_without_roles()
28
 
33
 
29
         return DBSession.query(Workspace).\
34
         return DBSession.query(Workspace).\

+ 30 - 1
tracim/tracim/tests/library/test_webdav.py View File

79
         ok_(root, msg='Path / should return a Root instance')
79
         ok_(root, msg='Path / should return a Root instance')
80
         ok_(isinstance(root, Root))
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
         provider = self._get_provider()
83
         provider = self._get_provider()
84
         root = provider.getResourceInst(
84
         root = provider.getResourceInst(
85
             '/',
85
             '/',
108
             workspaces_names,
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
     def test_unit__list_workspace_folders__ok(self):
140
     def test_unit__list_workspace_folders__ok(self):
112
         provider = self._get_provider()
141
         provider = self._get_provider()
113
         w1 = provider.getResourceInst(
142
         w1 = provider.getResourceInst(