|
@@ -642,3 +642,118 @@ class UserWorkspaceFolderRestController(TIMRestControllerWithBreadcrumb):
|
642
|
642
|
next_url = self.url(int(folder_id))
|
643
|
643
|
|
644
|
644
|
tg.redirect(next_url)
|
|
645
|
+
|
|
646
|
+ @property
|
|
647
|
+ def _std_url(self):
|
|
648
|
+ return tg.url('/workspaces/{}/folders/{}')
|
|
649
|
+
|
|
650
|
+ @property
|
|
651
|
+ def _parent_url(self):
|
|
652
|
+ return tg.url('/workspaces/{}')
|
|
653
|
+
|
|
654
|
+ @property
|
|
655
|
+ def _item_type_label(self):
|
|
656
|
+ return _('Folder')
|
|
657
|
+
|
|
658
|
+ @property
|
|
659
|
+ def _item_type(self):
|
|
660
|
+ return ContentType.Folder
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+ @tg.require(current_user_is_content_manager())
|
|
664
|
+ @tg.expose()
|
|
665
|
+ def put_archive(self, item_id):
|
|
666
|
+ # TODO - CHECK RIGHTS
|
|
667
|
+ item_id = int(item_id)
|
|
668
|
+ content_api = ContentApi(tmpl_context.current_user)
|
|
669
|
+ item = content_api.get_one(item_id, self._item_type, tmpl_context.workspace)
|
|
670
|
+
|
|
671
|
+ try:
|
|
672
|
+ next_url = self._parent_url.format(item.workspace_id, item.parent_id)
|
|
673
|
+ undo_url = self._std_url.format(item.workspace_id, item.content_id)+'/put_archive_undo'
|
|
674
|
+ msg = _('{} archived. <a class="alert-link" href="{}">Cancel action</a>').format(self._item_type_label, undo_url)
|
|
675
|
+
|
|
676
|
+ content_api.archive(item)
|
|
677
|
+ content_api.save(item, ActionDescription.ARCHIVING)
|
|
678
|
+
|
|
679
|
+ tg.flash(msg, CST.STATUS_OK, no_escape=True) # TODO allow to come back
|
|
680
|
+ tg.redirect(next_url)
|
|
681
|
+ except ValueError as e:
|
|
682
|
+ next_url = self._std_url.format(item.workspace_id, item.parent_id, item.content_id)
|
|
683
|
+ msg = _('{} not archived: {}').format(self._item_type_label, str(e))
|
|
684
|
+ tg.flash(msg, CST.STATUS_ERROR)
|
|
685
|
+ tg.redirect(next_url)
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+ @tg.require(current_user_is_content_manager())
|
|
689
|
+ @tg.expose()
|
|
690
|
+ def put_archive_undo(self, item_id):
|
|
691
|
+ print('AGAGA')
|
|
692
|
+ # TODO - CHECK RIGHTS
|
|
693
|
+ item_id = int(item_id)
|
|
694
|
+ content_api = ContentApi(tmpl_context.current_user, True, True) # Here we do not filter deleted items
|
|
695
|
+ item = content_api.get_one(item_id, self._item_type, tmpl_context.workspace)
|
|
696
|
+ try:
|
|
697
|
+ next_url = self._std_url.format(item.workspace_id, item.content_id)
|
|
698
|
+ msg = _('{} unarchived.').format(self._item_type_label)
|
|
699
|
+ content_api.unarchive(item)
|
|
700
|
+ content_api.save(item, ActionDescription.UNARCHIVING)
|
|
701
|
+
|
|
702
|
+ tg.flash(msg, CST.STATUS_OK)
|
|
703
|
+ tg.redirect(next_url )
|
|
704
|
+
|
|
705
|
+ except ValueError as e:
|
|
706
|
+ msg = _('{} not un-archived: {}').format(self._item_type_label, str(e))
|
|
707
|
+ next_url = self._std_url.format(item.workspace_id, item.content_id)
|
|
708
|
+ # We still use std url because the item has not been archived
|
|
709
|
+ tg.flash(msg, CST.STATUS_ERROR)
|
|
710
|
+ tg.redirect(next_url)
|
|
711
|
+
|
|
712
|
+ @tg.require(current_user_is_content_manager())
|
|
713
|
+ @tg.expose()
|
|
714
|
+ def put_delete(self, item_id):
|
|
715
|
+ # TODO - CHECK RIGHTS
|
|
716
|
+ item_id = int(item_id)
|
|
717
|
+ content_api = ContentApi(tmpl_context.current_user)
|
|
718
|
+ item = content_api.get_one(item_id, self._item_type, tmpl_context.workspace)
|
|
719
|
+ try:
|
|
720
|
+
|
|
721
|
+ next_url = self._parent_url.format(item.workspace_id, item.parent_id)
|
|
722
|
+ undo_url = self._std_url.format(item.workspace_id, item.content_id)+'/put_delete_undo'
|
|
723
|
+ msg = _('{} deleted. <a class="alert-link" href="{}">Cancel action</a>').format(self._item_type_label, undo_url)
|
|
724
|
+ content_api.delete(item)
|
|
725
|
+ content_api.save(item, ActionDescription.DELETION)
|
|
726
|
+
|
|
727
|
+ tg.flash(msg, CST.STATUS_OK, no_escape=True)
|
|
728
|
+ tg.redirect(next_url)
|
|
729
|
+
|
|
730
|
+ except ValueError as e:
|
|
731
|
+ back_url = self._std_url.format(item.workspace_id, item.content_id)
|
|
732
|
+ msg = _('{} not deleted: {}').format(self._item_type_label, str(e))
|
|
733
|
+ tg.flash(msg, CST.STATUS_ERROR)
|
|
734
|
+ tg.redirect(back_url)
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+ @tg.require(current_user_is_content_manager())
|
|
738
|
+ @tg.expose()
|
|
739
|
+ def put_delete_undo(self, item_id):
|
|
740
|
+ # TODO - CHECK RIGHTS
|
|
741
|
+
|
|
742
|
+ item_id = int(item_id)
|
|
743
|
+ content_api = ContentApi(tmpl_context.current_user, True, True) # Here we do not filter deleted items
|
|
744
|
+ item = content_api.get_one(item_id, self._item_type, tmpl_context.workspace)
|
|
745
|
+ try:
|
|
746
|
+ next_url = self._std_url.format(item.workspace_id, item.content_id)
|
|
747
|
+ msg = _('{} undeleted.').format(self._item_type_label)
|
|
748
|
+ content_api.undelete(item)
|
|
749
|
+ content_api.save(item, ActionDescription.UNDELETION)
|
|
750
|
+
|
|
751
|
+ tg.flash(msg, CST.STATUS_OK)
|
|
752
|
+ tg.redirect(next_url)
|
|
753
|
+
|
|
754
|
+ except ValueError as e:
|
|
755
|
+ logger.debug(self, 'Exception: {}'.format(e.__str__))
|
|
756
|
+ back_url = self._parent_url.format(item.workspace_id, item.parent_id)
|
|
757
|
+ msg = _('{} not un-deleted: {}').format(self._item_type_label, str(e))
|
|
758
|
+ tg.flash(msg, CST.STATUS_ERROR)
|
|
759
|
+ tg.redirect(back_url)
|