Browse Source

Refactor workspace id to allow show_deleted

Guénaël Muller 6 years ago
parent
commit
cfce407e15
1 changed files with 13 additions and 12 deletions
  1. 13 12
      backend/tracim_backend/lib/core/workspace.py

+ 13 - 12
backend/tracim_backend/lib/core/workspace.py View File

27
             session: Session,
27
             session: Session,
28
             current_user: User,
28
             current_user: User,
29
             config: CFG,
29
             config: CFG,
30
-            force_role: bool=False
30
+            force_role: bool=False,
31
+            show_deleted: bool=False,
31
     ):
32
     ):
32
         """
33
         """
33
         :param current_user: Current user of context
34
         :param current_user: Current user of context
37
         self._user = current_user
38
         self._user = current_user
38
         self._config = config
39
         self._config = config
39
         self._force_role = force_role
40
         self._force_role = force_role
41
+        self.show_deleted = show_deleted
40
 
42
 
41
     def _base_query_without_roles(self):
43
     def _base_query_without_roles(self):
42
-        return self._session.query(Workspace).filter(Workspace.is_deleted == False)
44
+        query = self._session.query(Workspace)
45
+        if not self.show_deleted:
46
+            query = query.filter(Workspace.is_deleted == False)
47
+        return query
43
 
48
 
44
     def _base_query(self):
49
     def _base_query(self):
45
         if not self._force_role and self._user.profile.id>=Group.TIM_ADMIN:
50
         if not self._force_role and self._user.profile.id>=Group.TIM_ADMIN:
46
             return self._base_query_without_roles()
51
             return self._base_query_without_roles()
47
 
52
 
48
-        return self._session.query(Workspace).\
49
-            join(Workspace.roles).\
50
-            filter(UserRoleInWorkspace.user_id == self._user.user_id).\
51
-            filter(Workspace.is_deleted == False)
53
+        query = self._base_query_without_roles()
54
+        query = query.join(Workspace.roles).\
55
+            filter(UserRoleInWorkspace.user_id == self._user.user_id)
56
+        return query
52
 
57
 
53
     def get_workspace_with_context(
58
     def get_workspace_with_context(
54
             self,
59
             self,
207
     def save(self, workspace: Workspace):
212
     def save(self, workspace: Workspace):
208
         self._session.flush()
213
         self._session.flush()
209
 
214
 
210
-    def delete_one(self, workspace_id, flush=True):
211
-        workspace = self.get_one(workspace_id)
215
+    def delete(self, workspace: Workspace, flush=True):
212
         workspace.is_deleted = True
216
         workspace.is_deleted = True
213
 
217
 
214
         if flush:
218
         if flush:
215
             self._session.flush()
219
             self._session.flush()
216
 
220
 
217
-    def restore_one(self, workspace_id, flush=True):
218
-        workspace = self._session.query(Workspace)\
219
-            .filter(Workspace.is_deleted==True)\
220
-            .filter(Workspace.workspace_id==workspace_id).one()
221
+    def undelete(self, workspace: Workspace, flush=True):
221
         workspace.is_deleted = False
222
         workspace.is_deleted = False
222
 
223
 
223
         if flush:
224
         if flush: