|
@@ -174,7 +174,7 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
|
174
|
174
|
|
175
|
175
|
@property
|
176
|
176
|
def _err_url(self):
|
177
|
|
- return tg.url('/dashboard/workspaces/{}/folders/{}/file/{}')
|
|
177
|
+ return tg.url('/workspaces/{}/folders/{}/files/{}')
|
178
|
178
|
|
179
|
179
|
@property
|
180
|
180
|
def _item_type(self):
|
|
@@ -376,19 +376,13 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
|
376
|
376
|
try:
|
377
|
377
|
api = ContentApi(tmpl_context.current_user)
|
378
|
378
|
item = api.get_one(int(item_id), self._item_type, workspace)
|
379
|
|
- label_changed = False
|
380
|
|
- if label is not None and label != item.label:
|
381
|
|
- label_changed = True
|
382
|
|
-
|
383
|
|
- if label is None:
|
384
|
|
- label = ''
|
385
|
|
-
|
386
|
|
- # TODO - D.A. - 2015-03-19
|
387
|
|
- # refactor this method in order to make code easier to understand
|
388
|
379
|
|
389
|
380
|
with new_revision(item):
|
|
381
|
+ if label:
|
|
382
|
+ # This case is the default "file title and description
|
|
383
|
+ # update" In this case the file itself is not revisionned
|
390
|
384
|
|
391
|
|
- if (comment and label) or (not comment and label_changed):
|
|
385
|
+ # Update description and label
|
392
|
386
|
updated_item = api.update_content(
|
393
|
387
|
item, label if label else item.label,
|
394
|
388
|
comment if comment else ''
|
|
@@ -401,31 +395,21 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
|
401
|
395
|
return render_invalid_integrity_chosen_path(
|
402
|
396
|
updated_item.get_label_as_file(),
|
403
|
397
|
)
|
404
|
|
-
|
405
|
398
|
api.save(updated_item, ActionDescription.EDITION)
|
406
|
|
-
|
407
|
|
- # This case is the default "file title and description
|
408
|
|
- # update" In this case the file itself is not revisionned
|
409
|
|
-
|
410
|
399
|
else:
|
411
|
400
|
# So, now we may have a comment and/or a file revision
|
412
|
|
- if comment and '' == label:
|
413
|
|
- comment_item = api.create_comment(workspace,
|
414
|
|
- item, comment,
|
415
|
|
- do_save=False)
|
416
|
|
-
|
417
|
|
- if not isinstance(file_data, FieldStorage):
|
418
|
|
- api.save(comment_item, ActionDescription.COMMENT)
|
419
|
|
- else:
|
420
|
|
- # The notification is only sent
|
421
|
|
- # if the file is NOT updated
|
422
|
|
- #
|
423
|
|
- # If the file is also updated,
|
424
|
|
- # then a 'file revision' notification will be sent.
|
425
|
|
- api.save(comment_item,
|
426
|
|
- ActionDescription.COMMENT,
|
427
|
|
- do_notify=False)
|
|
401
|
+ comment_item = None
|
|
402
|
+ file_revision = None
|
428
|
403
|
|
|
404
|
+ # INFO - G.M - 20/03/2018 - Add new comment
|
|
405
|
+ if comment:
|
|
406
|
+ comment_item = api.create_comment(
|
|
407
|
+ workspace,
|
|
408
|
+ item,
|
|
409
|
+ comment,
|
|
410
|
+ do_save=False
|
|
411
|
+ )
|
|
412
|
+ # INFO - G.M - 20/03/2018 - Add new file-revision
|
429
|
413
|
if isinstance(file_data, FieldStorage):
|
430
|
414
|
api.update_file_data(item,
|
431
|
415
|
file_data.filename,
|
|
@@ -440,8 +424,20 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
|
440
|
424
|
return render_invalid_integrity_chosen_path(
|
441
|
425
|
item.get_label_as_file(),
|
442
|
426
|
)
|
443
|
|
-
|
|
427
|
+ file_revision = True
|
|
428
|
+
|
|
429
|
+ # INFO - G.M - 20/03/2018 - Save revision/comment
|
|
430
|
+ if comment_item and file_revision:
|
|
431
|
+ api.save(
|
|
432
|
+ comment_item,
|
|
433
|
+ ActionDescription.COMMENT,
|
|
434
|
+ do_notify= False
|
|
435
|
+ )
|
|
436
|
+ api.save(item, ActionDescription.REVISION)
|
|
437
|
+ elif file_revision:
|
444
|
438
|
api.save(item, ActionDescription.REVISION)
|
|
439
|
+ elif comment_item:
|
|
440
|
+ api.save(comment_item, ActionDescription.COMMENT)
|
445
|
441
|
|
446
|
442
|
msg = _('{} updated').format(self._item_type_label)
|
447
|
443
|
tg.flash(msg, CST.STATUS_OK)
|
|
@@ -449,6 +445,14 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
|
449
|
445
|
tmpl_context.folder_id,
|
450
|
446
|
item.content_id))
|
451
|
447
|
|
|
448
|
+ except SameValueError:
|
|
449
|
+ not_updated = '{} not updated: the content did not change'
|
|
450
|
+ msg = _(not_updated).format(self._item_type_label)
|
|
451
|
+ tg.flash(msg, CST.STATUS_WARNING)
|
|
452
|
+ tg.redirect(self._err_url.format(tmpl_context.workspace_id,
|
|
453
|
+ tmpl_context.folder_id,
|
|
454
|
+ item_id))
|
|
455
|
+
|
452
|
456
|
except ValueError as e:
|
453
|
457
|
error = '{} not updated - error: {}'
|
454
|
458
|
msg = _(error).format(self._item_type_label,
|
|
@@ -459,6 +463,7 @@ class UserWorkspaceFolderFileRestController(TIMWorkspaceContentRestController):
|
459
|
463
|
item_id))
|
460
|
464
|
|
461
|
465
|
|
|
466
|
+
|
462
|
467
|
class UserWorkspaceFolderPageRestController(TIMWorkspaceContentRestController):
|
463
|
468
|
"""
|
464
|
469
|
manage a path like this: /workspaces/1/folders/XXX/pages/4
|
|
@@ -577,9 +582,11 @@ class UserWorkspaceFolderPageRestController(TIMWorkspaceContentRestController):
|
577
|
582
|
|
578
|
583
|
tg.flash(_('Page created'), CST.STATUS_OK)
|
579
|
584
|
redirect = '/workspaces/{}/folders/{}/pages/{}'
|
580
|
|
- tg.redirect(tg.url(redirect).format(tmpl_context.workspace_id,
|
581
|
|
- tmpl_context.folder_id,
|
582
|
|
- page.content_id))
|
|
585
|
+ tg.redirect(tg.url(redirect).format(
|
|
586
|
+ tmpl_context.workspace_id,
|
|
587
|
+ tmpl_context.folder_id,
|
|
588
|
+ page.content_id)
|
|
589
|
+ )
|
583
|
590
|
|
584
|
591
|
@tg.require(current_user_is_contributor())
|
585
|
592
|
@tg.expose()
|
|
@@ -606,21 +613,28 @@ class UserWorkspaceFolderPageRestController(TIMWorkspaceContentRestController):
|
606
|
613
|
tg.redirect(self._std_url.format(tmpl_context.workspace_id,
|
607
|
614
|
tmpl_context.folder_id,
|
608
|
615
|
item.content_id))
|
609
|
|
- except SameValueError as e:
|
|
616
|
+ except SameValueError:
|
610
|
617
|
not_updated = '{} not updated: the content did not change'
|
611
|
618
|
msg = _(not_updated).format(self._item_type_label)
|
612
|
619
|
tg.flash(msg, CST.STATUS_WARNING)
|
613
|
|
- tg.redirect(self._err_url.format(tmpl_context.workspace_id,
|
614
|
|
- tmpl_context.folder_id,
|
615
|
|
- item_id))
|
|
620
|
+ tg.redirect(
|
|
621
|
+ self._err_url.format(
|
|
622
|
+ tmpl_context.workspace_id,
|
|
623
|
+ tmpl_context.folder_id,
|
|
624
|
+ item_id
|
|
625
|
+ )
|
|
626
|
+ )
|
616
|
627
|
except ValueError as e:
|
617
|
628
|
not_updated = '{} not updated - error: {}'
|
618
|
629
|
msg = _(not_updated).format(self._item_type_label, str(e))
|
619
|
630
|
tg.flash(msg, CST.STATUS_ERROR)
|
620
|
|
- tg.redirect(self._err_url.format(tmpl_context.workspace_id,
|
621
|
|
- tmpl_context.folder_id,
|
622
|
|
- item_id))
|
623
|
|
-
|
|
631
|
+ tg.redirect(
|
|
632
|
+ self._err_url.format(
|
|
633
|
+ tmpl_context.workspace_id,
|
|
634
|
+ tmpl_context.folder_id,
|
|
635
|
+ item_id
|
|
636
|
+ )
|
|
637
|
+ )
|
624
|
638
|
|
625
|
639
|
class UserWorkspaceFolderThreadRestController(TIMWorkspaceContentRestController):
|
626
|
640
|
"""
|