|
@@ -27,7 +27,8 @@ class WorkspaceApi(object):
|
27
|
27
|
session: Session,
|
28
|
28
|
current_user: User,
|
29
|
29
|
config: CFG,
|
30
|
|
- force_role: bool=False
|
|
30
|
+ force_role: bool=False,
|
|
31
|
+ show_deleted: bool=False,
|
31
|
32
|
):
|
32
|
33
|
"""
|
33
|
34
|
:param current_user: Current user of context
|
|
@@ -37,18 +38,22 @@ class WorkspaceApi(object):
|
37
|
38
|
self._user = current_user
|
38
|
39
|
self._config = config
|
39
|
40
|
self._force_role = force_role
|
|
41
|
+ self.show_deleted = show_deleted
|
40
|
42
|
|
41
|
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
|
49
|
def _base_query(self):
|
45
|
50
|
if not self._force_role and self._user.profile.id>=Group.TIM_ADMIN:
|
46
|
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
|
58
|
def get_workspace_with_context(
|
54
|
59
|
self,
|
|
@@ -207,17 +212,13 @@ class WorkspaceApi(object):
|
207
|
212
|
def save(self, workspace: Workspace):
|
208
|
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
|
216
|
workspace.is_deleted = True
|
213
|
217
|
|
214
|
218
|
if flush:
|
215
|
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
|
222
|
workspace.is_deleted = False
|
222
|
223
|
|
223
|
224
|
if flush:
|