|
@@ -0,0 +1,572 @@
|
|
1
|
+
|
|
2
|
+import typing
|
|
3
|
+
|
|
4
|
+import transaction
|
|
5
|
+from depot.manager import DepotManager
|
|
6
|
+from preview_generator.exception import UnavailablePreviewType
|
|
7
|
+from pyramid.config import Configurator
|
|
8
|
+from pyramid.response import FileResponse, FileIter
|
|
9
|
+
|
|
10
|
+try:
|
|
11
|
+ from http import HTTPStatus
|
|
12
|
+except ImportError:
|
|
13
|
+ from http import client as HTTPStatus
|
|
14
|
+
|
|
15
|
+from tracim import TracimRequest
|
|
16
|
+from tracim.extensions import hapic
|
|
17
|
+from tracim.lib.core.content import ContentApi
|
|
18
|
+from tracim.views.controllers import Controller
|
|
19
|
+from tracim.views.core_api.schemas import FileContentSchema
|
|
20
|
+from tracim.views.core_api.schemas import AllowedJpgPreviewDimSchema
|
|
21
|
+from tracim.views.core_api.schemas import ContentPreviewSizedPathSchema
|
|
22
|
+from tracim.views.core_api.schemas import RevisionPreviewSizedPathSchema
|
|
23
|
+from tracim.views.core_api.schemas import PageQuerySchema
|
|
24
|
+from tracim.views.core_api.schemas import WorkspaceAndContentRevisionIdPathSchema
|
|
25
|
+from tracim.views.core_api.schemas import FileRevisionSchema
|
|
26
|
+from tracim.views.core_api.schemas import SetContentStatusSchema
|
|
27
|
+from tracim.views.core_api.schemas import FileContentModifySchema
|
|
28
|
+from tracim.views.core_api.schemas import WorkspaceAndContentIdPathSchema
|
|
29
|
+from tracim.views.core_api.schemas import NoContentSchema
|
|
30
|
+from tracim.lib.utils.authorization import require_content_types
|
|
31
|
+from tracim.lib.utils.authorization import require_workspace_role
|
|
32
|
+from tracim.models.data import UserRoleInWorkspace
|
|
33
|
+from tracim.models.context_models import ContentInContext
|
|
34
|
+from tracim.models.context_models import RevisionInContext
|
|
35
|
+from tracim.models.contents import ContentTypeLegacy as ContentType
|
|
36
|
+from tracim.models.contents import file_type
|
|
37
|
+from tracim.models.revision_protection import new_revision
|
|
38
|
+from tracim.exceptions import EmptyLabelNotAllowed
|
|
39
|
+from tracim.exceptions import PageOfPreviewNotFound
|
|
40
|
+from tracim.exceptions import PreviewDimNotAllowed
|
|
41
|
+
|
|
42
|
+FILE_ENDPOINTS_TAG = 'Files'
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+class FileController(Controller):
|
|
46
|
+ """
|
|
47
|
+ Endpoints for File Content
|
|
48
|
+ """
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
52
|
+ @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
|
|
53
|
+ @require_content_types([file_type])
|
|
54
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
55
|
+
|
|
56
|
+ @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)
|
|
57
|
+ def upload_file(self, context, request: TracimRequest, hapic_data=None):
|
|
58
|
+ """
|
|
59
|
+ Upload a new version of raw file of content. This will create a new
|
|
60
|
+ revision.
|
|
61
|
+ """
|
|
62
|
+ app_config = request.registry.settings['CFG']
|
|
63
|
+ api = ContentApi(
|
|
64
|
+ current_user=request.current_user,
|
|
65
|
+ session=request.dbsession,
|
|
66
|
+ config=app_config,
|
|
67
|
+ )
|
|
68
|
+ content = api.get_one(
|
|
69
|
+ hapic_data.path.content_id,
|
|
70
|
+ content_type=ContentType.Any
|
|
71
|
+ )
|
|
72
|
+ file = request.POST['files']
|
|
73
|
+ with new_revision(
|
|
74
|
+ session=request.dbsession,
|
|
75
|
+ tm=transaction.manager,
|
|
76
|
+ content=content
|
|
77
|
+ ):
|
|
78
|
+ api.update_file_data(
|
|
79
|
+ content,
|
|
80
|
+ new_filename=file.filename,
|
|
81
|
+ new_mimetype=file.type,
|
|
82
|
+ new_content=file.file,
|
|
83
|
+ )
|
|
84
|
+
|
|
85
|
+ return
|
|
86
|
+
|
|
87
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
88
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
89
|
+ @require_content_types([file_type])
|
|
90
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
91
|
+ @hapic.output_file([])
|
|
92
|
+ def download_file(self, context, request: TracimRequest, hapic_data=None):
|
|
93
|
+ """
|
|
94
|
+ Download raw file of last revision of content.
|
|
95
|
+ """
|
|
96
|
+ app_config = request.registry.settings['CFG']
|
|
97
|
+ api = ContentApi(
|
|
98
|
+ current_user=request.current_user,
|
|
99
|
+ session=request.dbsession,
|
|
100
|
+ config=app_config,
|
|
101
|
+ )
|
|
102
|
+ content = api.get_one(
|
|
103
|
+ hapic_data.path.content_id,
|
|
104
|
+ content_type=ContentType.Any
|
|
105
|
+ )
|
|
106
|
+ file = DepotManager.get().get(content.depot_file)
|
|
107
|
+ response = request.response
|
|
108
|
+ response.content_type = file.content_type
|
|
109
|
+ response.app_iter = FileIter(file)
|
|
110
|
+ return response
|
|
111
|
+
|
|
112
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
113
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
114
|
+ @require_content_types([file_type])
|
|
115
|
+ @hapic.input_path(WorkspaceAndContentRevisionIdPathSchema())
|
|
116
|
+ @hapic.output_file([])
|
|
117
|
+ def download_revisions_file(self, context, request: TracimRequest, hapic_data=None):
|
|
118
|
+ """
|
|
119
|
+ Download raw file for specific revision of content.
|
|
120
|
+ """
|
|
121
|
+ app_config = request.registry.settings['CFG']
|
|
122
|
+ api = ContentApi(
|
|
123
|
+ current_user=request.current_user,
|
|
124
|
+ session=request.dbsession,
|
|
125
|
+ config=app_config,
|
|
126
|
+ )
|
|
127
|
+ content = api.get_one(
|
|
128
|
+ hapic_data.path.content_id,
|
|
129
|
+ content_type=ContentType.Any
|
|
130
|
+ )
|
|
131
|
+ revision = api.get_one_revision(
|
|
132
|
+ revision_id=hapic_data.path.revision_id,
|
|
133
|
+ content=content
|
|
134
|
+ )
|
|
135
|
+ file = DepotManager.get().get(revision.depot_file)
|
|
136
|
+ response = request.response
|
|
137
|
+ response.content_type = file.content_type
|
|
138
|
+ response.app_iter = FileIter(file)
|
|
139
|
+ return response
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
144
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
145
|
+ @require_content_types([file_type])
|
|
146
|
+ @hapic.handle_exception(UnavailablePreviewType, HTTPStatus.BAD_REQUEST)
|
|
147
|
+ @hapic.handle_exception(PageOfPreviewNotFound, HTTPStatus.BAD_REQUEST)
|
|
148
|
+ @hapic.input_query(PageQuerySchema())
|
|
149
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
150
|
+ @hapic.output_file([])
|
|
151
|
+ def preview_pdf(self, context, request: TracimRequest, hapic_data=None):
|
|
152
|
+ """
|
|
153
|
+ Obtain a specific page pdf preview of last revision of content.
|
|
154
|
+ """
|
|
155
|
+ app_config = request.registry.settings['CFG']
|
|
156
|
+ api = ContentApi(
|
|
157
|
+ current_user=request.current_user,
|
|
158
|
+ session=request.dbsession,
|
|
159
|
+ config=app_config,
|
|
160
|
+ )
|
|
161
|
+ content = api.get_one(
|
|
162
|
+ hapic_data.path.content_id,
|
|
163
|
+ content_type=ContentType.Any
|
|
164
|
+ )
|
|
165
|
+ pdf_preview_path = api.get_pdf_preview_path(
|
|
166
|
+ content.content_id,
|
|
167
|
+ content.revision_id,
|
|
168
|
+ page=hapic_data.query.page
|
|
169
|
+ )
|
|
170
|
+ return FileResponse(pdf_preview_path)
|
|
171
|
+
|
|
172
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
173
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
174
|
+ @require_content_types([file_type])
|
|
175
|
+ @hapic.handle_exception(UnavailablePreviewType, HTTPStatus.BAD_REQUEST)
|
|
176
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
177
|
+ @hapic.output_file([])
|
|
178
|
+ def preview_pdf_full(self, context, request: TracimRequest, hapic_data=None):
|
|
179
|
+ """
|
|
180
|
+ Obtain a full pdf preview (all page) of last revision of content.
|
|
181
|
+ """
|
|
182
|
+ app_config = request.registry.settings['CFG']
|
|
183
|
+ api = ContentApi(
|
|
184
|
+ current_user=request.current_user,
|
|
185
|
+ session=request.dbsession,
|
|
186
|
+ config=app_config,
|
|
187
|
+ )
|
|
188
|
+ content = api.get_one(
|
|
189
|
+ hapic_data.path.content_id,
|
|
190
|
+ content_type=ContentType.Any
|
|
191
|
+ )
|
|
192
|
+ pdf_preview_path = api.get_full_pdf_preview_path(content.revision_id)
|
|
193
|
+ return FileResponse(pdf_preview_path)
|
|
194
|
+
|
|
195
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
196
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
197
|
+ @require_content_types([file_type])
|
|
198
|
+ @hapic.handle_exception(UnavailablePreviewType, HTTPStatus.BAD_REQUEST)
|
|
199
|
+ @hapic.input_path(WorkspaceAndContentRevisionIdPathSchema())
|
|
200
|
+ @hapic.input_query(PageQuerySchema())
|
|
201
|
+ @hapic.output_file([])
|
|
202
|
+ def preview_pdf_revision(self, context, request: TracimRequest, hapic_data=None):
|
|
203
|
+ """
|
|
204
|
+ Obtain a specific page pdf preview of a specific revision of content.
|
|
205
|
+ """
|
|
206
|
+ app_config = request.registry.settings['CFG']
|
|
207
|
+ api = ContentApi(
|
|
208
|
+ current_user=request.current_user,
|
|
209
|
+ session=request.dbsession,
|
|
210
|
+ config=app_config,
|
|
211
|
+ )
|
|
212
|
+ content = api.get_one(
|
|
213
|
+ hapic_data.path.content_id,
|
|
214
|
+ content_type=ContentType.Any
|
|
215
|
+ )
|
|
216
|
+ revision = api.get_one_revision(
|
|
217
|
+ revision_id=hapic_data.path.revision_id,
|
|
218
|
+ content=content
|
|
219
|
+ )
|
|
220
|
+ pdf_preview_path = api.get_pdf_preview_path(
|
|
221
|
+ revision.content_id,
|
|
222
|
+ revision.revision_id,
|
|
223
|
+ page=hapic_data.query.page
|
|
224
|
+ )
|
|
225
|
+ return FileResponse(pdf_preview_path)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
229
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
230
|
+ @require_content_types([file_type])
|
|
231
|
+ @hapic.handle_exception(PageOfPreviewNotFound, HTTPStatus.BAD_REQUEST)
|
|
232
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
233
|
+ @hapic.input_query(PageQuerySchema())
|
|
234
|
+ @hapic.output_file([])
|
|
235
|
+ def preview_jpg(self, context, request: TracimRequest, hapic_data=None):
|
|
236
|
+ """
|
|
237
|
+ Obtain normally sied jpg preview of last revision of content.
|
|
238
|
+ """
|
|
239
|
+ app_config = request.registry.settings['CFG']
|
|
240
|
+ api = ContentApi(
|
|
241
|
+ current_user=request.current_user,
|
|
242
|
+ session=request.dbsession,
|
|
243
|
+ config=app_config,
|
|
244
|
+ )
|
|
245
|
+ content = api.get_one(
|
|
246
|
+ hapic_data.path.content_id,
|
|
247
|
+ content_type=ContentType.Any
|
|
248
|
+ )
|
|
249
|
+ allowed_dim = api.get_jpg_preview_allowed_dim()
|
|
250
|
+ jpg_preview_path = api.get_jpg_preview_path(
|
|
251
|
+ content_id=content.content_id,
|
|
252
|
+ revision_id=content.revision_id,
|
|
253
|
+ page=hapic_data.query.page,
|
|
254
|
+ width=allowed_dim.dimensions[0].width,
|
|
255
|
+ height=allowed_dim.dimensions[0].height,
|
|
256
|
+ )
|
|
257
|
+ return FileResponse(jpg_preview_path)
|
|
258
|
+
|
|
259
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
260
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
261
|
+ @require_content_types([file_type])
|
|
262
|
+ @hapic.handle_exception(PageOfPreviewNotFound, HTTPStatus.BAD_REQUEST)
|
|
263
|
+ @hapic.handle_exception(PreviewDimNotAllowed, HTTPStatus.BAD_REQUEST)
|
|
264
|
+ @hapic.input_query(PageQuerySchema())
|
|
265
|
+ @hapic.input_path(ContentPreviewSizedPathSchema())
|
|
266
|
+ @hapic.output_file([])
|
|
267
|
+ def sized_preview_jpg(self, context, request: TracimRequest, hapic_data=None):
|
|
268
|
+ """
|
|
269
|
+ Obtain resized jpg preview of last revision of content.
|
|
270
|
+ """
|
|
271
|
+ app_config = request.registry.settings['CFG']
|
|
272
|
+ api = ContentApi(
|
|
273
|
+ current_user=request.current_user,
|
|
274
|
+ session=request.dbsession,
|
|
275
|
+ config=app_config,
|
|
276
|
+ )
|
|
277
|
+ content = api.get_one(
|
|
278
|
+ hapic_data.path.content_id,
|
|
279
|
+ content_type=ContentType.Any
|
|
280
|
+ )
|
|
281
|
+ jpg_preview_path = api.get_jpg_preview_path(
|
|
282
|
+ content_id=content.content_id,
|
|
283
|
+ revision_id=content.revision_id,
|
|
284
|
+ page=hapic_data.query.page,
|
|
285
|
+ height=hapic_data.path.height,
|
|
286
|
+ width=hapic_data.path.width,
|
|
287
|
+ )
|
|
288
|
+ return FileResponse(jpg_preview_path)
|
|
289
|
+
|
|
290
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
291
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
292
|
+ @require_content_types([file_type])
|
|
293
|
+ @hapic.handle_exception(PageOfPreviewNotFound, HTTPStatus.BAD_REQUEST)
|
|
294
|
+ @hapic.handle_exception(PreviewDimNotAllowed, HTTPStatus.BAD_REQUEST)
|
|
295
|
+ @hapic.input_path(RevisionPreviewSizedPathSchema())
|
|
296
|
+ @hapic.input_query(PageQuerySchema())
|
|
297
|
+ @hapic.output_file([])
|
|
298
|
+ def sized_preview_jpg_revision(self, context, request: TracimRequest, hapic_data=None):
|
|
299
|
+ """
|
|
300
|
+ Obtain resized jpg preview of a specific revision of content.
|
|
301
|
+ """
|
|
302
|
+ app_config = request.registry.settings['CFG']
|
|
303
|
+ api = ContentApi(
|
|
304
|
+ current_user=request.current_user,
|
|
305
|
+ session=request.dbsession,
|
|
306
|
+ config=app_config,
|
|
307
|
+ )
|
|
308
|
+ content = api.get_one(
|
|
309
|
+ hapic_data.path.content_id,
|
|
310
|
+ content_type=ContentType.Any
|
|
311
|
+ )
|
|
312
|
+ revision = api.get_one_revision(
|
|
313
|
+ revision_id=hapic_data.path.revision_id,
|
|
314
|
+ content=content
|
|
315
|
+ )
|
|
316
|
+ jpg_preview_path = api.get_jpg_preview_path(
|
|
317
|
+ content_id=content.content_id,
|
|
318
|
+ revision_id=revision.revision_id,
|
|
319
|
+ page=hapic_data.query.page,
|
|
320
|
+ height=hapic_data.path.height,
|
|
321
|
+ width=hapic_data.path.width,
|
|
322
|
+ )
|
|
323
|
+ return FileResponse(jpg_preview_path)
|
|
324
|
+
|
|
325
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
326
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
327
|
+ @require_content_types([file_type])
|
|
328
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
329
|
+ @hapic.output_body(AllowedJpgPreviewDimSchema())
|
|
330
|
+ def allowed_dim_preview_jpg(self, context, request: TracimRequest, hapic_data=None):
|
|
331
|
+ """
|
|
332
|
+ Get allowed dimensions of jpg preview. If restricted is true,
|
|
333
|
+ only those dimensions are strictly accepted.
|
|
334
|
+ """
|
|
335
|
+ app_config = request.registry.settings['CFG']
|
|
336
|
+ api = ContentApi(
|
|
337
|
+ current_user=request.current_user,
|
|
338
|
+ session=request.dbsession,
|
|
339
|
+ config=app_config,
|
|
340
|
+ )
|
|
341
|
+ return api.get_jpg_preview_allowed_dim()
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
345
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
346
|
+ @require_content_types([file_type])
|
|
347
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
348
|
+ @hapic.output_body(FileContentSchema())
|
|
349
|
+ def get_file_infos(self, context, request: TracimRequest, hapic_data=None) -> ContentInContext:
|
|
350
|
+ """
|
|
351
|
+ Get thread content
|
|
352
|
+ """
|
|
353
|
+ app_config = request.registry.settings['CFG']
|
|
354
|
+ api = ContentApi(
|
|
355
|
+ current_user=request.current_user,
|
|
356
|
+ session=request.dbsession,
|
|
357
|
+ config=app_config,
|
|
358
|
+ )
|
|
359
|
+ content = api.get_one(
|
|
360
|
+ hapic_data.path.content_id,
|
|
361
|
+ content_type=ContentType.Any
|
|
362
|
+ )
|
|
363
|
+ return api.get_content_in_context(content)
|
|
364
|
+
|
|
365
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
366
|
+ @hapic.handle_exception(EmptyLabelNotAllowed, HTTPStatus.BAD_REQUEST)
|
|
367
|
+ @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
|
|
368
|
+ @require_content_types([file_type])
|
|
369
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
370
|
+ @hapic.input_body(FileContentModifySchema())
|
|
371
|
+ @hapic.output_body(FileContentSchema())
|
|
372
|
+ def update_file_info(self, context, request: TracimRequest, hapic_data=None) -> ContentInContext:
|
|
373
|
+ """
|
|
374
|
+ update thread
|
|
375
|
+ """
|
|
376
|
+ app_config = request.registry.settings['CFG']
|
|
377
|
+ api = ContentApi(
|
|
378
|
+ current_user=request.current_user,
|
|
379
|
+ session=request.dbsession,
|
|
380
|
+ config=app_config,
|
|
381
|
+ )
|
|
382
|
+ content = api.get_one(
|
|
383
|
+ hapic_data.path.content_id,
|
|
384
|
+ content_type=ContentType.Any
|
|
385
|
+ )
|
|
386
|
+ with new_revision(
|
|
387
|
+ session=request.dbsession,
|
|
388
|
+ tm=transaction.manager,
|
|
389
|
+ content=content
|
|
390
|
+ ):
|
|
391
|
+ api.update_content(
|
|
392
|
+ item=content,
|
|
393
|
+ new_label=hapic_data.body.label,
|
|
394
|
+ new_content=hapic_data.body.raw_content,
|
|
395
|
+
|
|
396
|
+ )
|
|
397
|
+ api.save(content)
|
|
398
|
+ return api.get_content_in_context(content)
|
|
399
|
+
|
|
400
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
401
|
+ @require_workspace_role(UserRoleInWorkspace.READER)
|
|
402
|
+ @require_content_types([file_type])
|
|
403
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
404
|
+ @hapic.output_body(FileRevisionSchema(many=True))
|
|
405
|
+ def get_file_revisions(
|
|
406
|
+ self,
|
|
407
|
+ context,
|
|
408
|
+ request: TracimRequest,
|
|
409
|
+ hapic_data=None
|
|
410
|
+ ) -> typing.List[RevisionInContext]:
|
|
411
|
+ """
|
|
412
|
+ get file revisions
|
|
413
|
+ """
|
|
414
|
+ app_config = request.registry.settings['CFG']
|
|
415
|
+ api = ContentApi(
|
|
416
|
+ current_user=request.current_user,
|
|
417
|
+ session=request.dbsession,
|
|
418
|
+ config=app_config,
|
|
419
|
+ )
|
|
420
|
+ content = api.get_one(
|
|
421
|
+ hapic_data.path.content_id,
|
|
422
|
+ content_type=ContentType.Any
|
|
423
|
+ )
|
|
424
|
+ revisions = content.revisions
|
|
425
|
+ return [
|
|
426
|
+ api.get_revision_in_context(revision)
|
|
427
|
+ for revision in revisions
|
|
428
|
+ ]
|
|
429
|
+
|
|
430
|
+ @hapic.with_api_doc(tags=[FILE_ENDPOINTS_TAG])
|
|
431
|
+ @hapic.handle_exception(EmptyLabelNotAllowed, HTTPStatus.BAD_REQUEST)
|
|
432
|
+ @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
|
|
433
|
+ @require_content_types([file_type])
|
|
434
|
+ @hapic.input_path(WorkspaceAndContentIdPathSchema())
|
|
435
|
+ @hapic.input_body(SetContentStatusSchema())
|
|
436
|
+ @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)
|
|
437
|
+ def set_file_status(self, context, request: TracimRequest, hapic_data=None) -> None:
|
|
438
|
+ """
|
|
439
|
+ set file status
|
|
440
|
+ """
|
|
441
|
+ app_config = request.registry.settings['CFG']
|
|
442
|
+ api = ContentApi(
|
|
443
|
+ current_user=request.current_user,
|
|
444
|
+ session=request.dbsession,
|
|
445
|
+ config=app_config,
|
|
446
|
+ )
|
|
447
|
+ content = api.get_one(
|
|
448
|
+ hapic_data.path.content_id,
|
|
449
|
+ content_type=ContentType.Any
|
|
450
|
+ )
|
|
451
|
+ with new_revision(
|
|
452
|
+ session=request.dbsession,
|
|
453
|
+ tm=transaction.manager,
|
|
454
|
+ content=content
|
|
455
|
+ ):
|
|
456
|
+ api.set_status(
|
|
457
|
+ content,
|
|
458
|
+ hapic_data.body.status,
|
|
459
|
+ )
|
|
460
|
+ api.save(content)
|
|
461
|
+ return
|
|
462
|
+
|
|
463
|
+ def bind(self, configurator: Configurator) -> None:
|
|
464
|
+ """
|
|
465
|
+ Add route to configurator.
|
|
466
|
+ """
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+ configurator.add_route(
|
|
471
|
+ 'file_info',
|
|
472
|
+ '/workspaces/{workspace_id}/files/{content_id}',
|
|
473
|
+ request_method='GET'
|
|
474
|
+ )
|
|
475
|
+ configurator.add_view(self.get_file_infos, route_name='file_info')
|
|
476
|
+
|
|
477
|
+ configurator.add_route(
|
|
478
|
+ 'update_file_info',
|
|
479
|
+ '/workspaces/{workspace_id}/files/{content_id}',
|
|
480
|
+ request_method='PUT'
|
|
481
|
+ )
|
|
482
|
+ configurator.add_view(self.update_file_info, route_name='update_file_info')
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+ configurator.add_route(
|
|
487
|
+ 'upload_file',
|
|
488
|
+ '/workspaces/{workspace_id}/files/{content_id}/raw',
|
|
489
|
+ request_method='PUT'
|
|
490
|
+ )
|
|
491
|
+ configurator.add_view(self.upload_file, route_name='upload_file')
|
|
492
|
+
|
|
493
|
+ configurator.add_route(
|
|
494
|
+ 'download_file',
|
|
495
|
+ '/workspaces/{workspace_id}/files/{content_id}/raw',
|
|
496
|
+ request_method='GET'
|
|
497
|
+ )
|
|
498
|
+ configurator.add_view(self.download_file, route_name='download_file')
|
|
499
|
+
|
|
500
|
+ configurator.add_route(
|
|
501
|
+ 'download_revision',
|
|
502
|
+ '/workspaces/{workspace_id}/files/{content_id}/revisions/{revision_id}/raw',
|
|
503
|
+ request_method='GET'
|
|
504
|
+ )
|
|
505
|
+ configurator.add_view(self.download_revisions_file, route_name='download_revision')
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+ configurator.add_route(
|
|
510
|
+ 'preview_pdf_full',
|
|
511
|
+ '/workspaces/{workspace_id}/files/{content_id}/preview/pdf/full',
|
|
512
|
+ request_method='GET'
|
|
513
|
+ )
|
|
514
|
+ configurator.add_view(self.preview_pdf_full, route_name='preview_pdf_full')
|
|
515
|
+
|
|
516
|
+ configurator.add_route(
|
|
517
|
+ 'preview_pdf',
|
|
518
|
+ '/workspaces/{workspace_id}/files/{content_id}/preview/pdf',
|
|
519
|
+ request_method='GET'
|
|
520
|
+ )
|
|
521
|
+ configurator.add_view(self.preview_pdf, route_name='preview_pdf')
|
|
522
|
+
|
|
523
|
+ configurator.add_route(
|
|
524
|
+ 'allowed_dim_preview_jpg',
|
|
525
|
+ '/workspaces/{workspace_id}/files/{content_id}/preview/jpg/allowed_dims',
|
|
526
|
+ request_method='GET'
|
|
527
|
+ )
|
|
528
|
+ configurator.add_view(self.allowed_dim_preview_jpg, route_name='allowed_dim_preview_jpg')
|
|
529
|
+
|
|
530
|
+ configurator.add_route(
|
|
531
|
+ 'preview_jpg',
|
|
532
|
+ '/workspaces/{workspace_id}/files/{content_id}/preview/jpg',
|
|
533
|
+ request_method='GET'
|
|
534
|
+ )
|
|
535
|
+ configurator.add_view(self.preview_jpg, route_name='preview_jpg')
|
|
536
|
+
|
|
537
|
+ configurator.add_route(
|
|
538
|
+ 'sized_preview_jpg',
|
|
539
|
+ '/workspaces/{workspace_id}/files/{content_id}/preview/jpg/{width}x{height}',
|
|
540
|
+ request_method='GET'
|
|
541
|
+ )
|
|
542
|
+ configurator.add_view(self.sized_preview_jpg, route_name='sized_preview_jpg')
|
|
543
|
+
|
|
544
|
+ configurator.add_route(
|
|
545
|
+ 'sized_preview_jpg_revision',
|
|
546
|
+ '/workspaces/{workspace_id}/files/{content_id}/revisions/{revision_id}/preview/jpg/{width}x{height}',
|
|
547
|
+ request_method='GET'
|
|
548
|
+ )
|
|
549
|
+ configurator.add_view(self.sized_preview_jpg_revision, route_name='sized_preview_jpg_revision')
|
|
550
|
+
|
|
551
|
+ configurator.add_route(
|
|
552
|
+ 'preview_pdf_revision',
|
|
553
|
+ '/workspaces/{workspace_id}/files/{content_id}/revisions/{revision_id}/preview/pdf',
|
|
554
|
+ request_method='GET'
|
|
555
|
+ )
|
|
556
|
+ configurator.add_view(self.preview_pdf_revision, route_name='preview_pdf_revision')
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+ configurator.add_route(
|
|
560
|
+ 'file_revisions',
|
|
561
|
+ '/workspaces/{workspace_id}/files/{content_id}/revisions',
|
|
562
|
+ request_method='GET'
|
|
563
|
+ )
|
|
564
|
+ configurator.add_view(self.get_file_revisions, route_name='file_revisions')
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+ configurator.add_route(
|
|
568
|
+ 'set_file_status',
|
|
569
|
+ '/workspaces/{workspace_id}/files/{content_id}/status',
|
|
570
|
+ request_method='PUT'
|
|
571
|
+ )
|
|
572
|
+ configurator.add_view(self.set_file_status, route_name='set_file_status')
|