|
@@ -36,7 +36,8 @@ logger = logging.getLogger()
|
36
|
36
|
|
37
|
37
|
class ManageActions(object):
|
38
|
38
|
"""
|
39
|
|
- This object is used to encapsulate all Deletion/Archiving related method as to not duplicate too much code
|
|
39
|
+ This object is used to encapsulate all Deletion/Archiving related
|
|
40
|
+ method as to not duplicate too much code
|
40
|
41
|
"""
|
41
|
42
|
def __init__(self, action_type: str, api: ContentApi, content: Content):
|
42
|
43
|
self.content_api = api
|
|
@@ -49,57 +50,14 @@ class ManageActions(object):
|
49
|
50
|
ActionDescription.UNDELETION: self.content_api.undelete
|
50
|
51
|
}
|
51
|
52
|
|
52
|
|
- self._to_name = {
|
53
|
|
- ActionDescription.ARCHIVING: 'archived',
|
54
|
|
- ActionDescription.DELETION: 'deleted'
|
55
|
|
- }
|
56
|
|
-
|
57
|
53
|
self._type = action_type
|
58
|
|
- self._new_name = self.make_name()
|
59
|
54
|
|
60
|
55
|
def action(self):
|
61
|
|
- try:
|
62
|
|
- # When undeleting/unarchiving we except a content with the new name to not exist, thus if we
|
63
|
|
- # don't get an error and the database request send back a result, we stop the action
|
64
|
|
- self.content_api.get_one_by_label_and_parent(self._new_name, self.content.parent)
|
65
|
|
- raise DAVError(HTTP_FORBIDDEN)
|
66
|
|
- except NoResultFound:
|
67
|
|
- with new_revision(self.content):
|
68
|
|
- self.content_api.update_content(self.content, self._new_name)
|
69
|
|
- self._actions[self._type](self.content)
|
70
|
|
- self.content_api.save(self.content, self._type)
|
71
|
|
-
|
72
|
|
- transaction.commit()
|
73
|
|
-
|
74
|
|
- def make_name(self) -> str:
|
75
|
|
- """
|
76
|
|
- Will create the new name, either by adding '- deleted the [date]' after the name when archiving/deleting or
|
77
|
|
- removing this string when undeleting/unarchiving
|
78
|
|
- """
|
79
|
|
- new_name = self.content.get_label_as_file()
|
80
|
|
- extension = ''
|
81
|
|
-
|
82
|
|
- # if the content has no label, the last .ext is important
|
83
|
|
- # thus we want to rename a file from 'file.txt' to 'file - deleted... .txt' and not 'file.txt - deleted...'
|
84
|
|
- is_file_name = self.content.label == ''
|
85
|
|
- if is_file_name:
|
86
|
|
- search = re.search(r'(\.[^.]+)$', new_name)
|
87
|
|
- if search:
|
88
|
|
- extension = search.group(0)
|
89
|
|
- new_name = re.sub(r'(\.[^.]+)$', '', new_name)
|
90
|
|
-
|
91
|
|
- if self._type in [ActionDescription.ARCHIVING, ActionDescription.DELETION]:
|
92
|
|
- new_name += ' - %s the %s' % (self._to_name[self._type], datetime.now().strftime('%d-%m-%Y at %H_%M'))
|
93
|
|
- else:
|
94
|
|
- new_name = re.sub(
|
95
|
|
- r'( - (%s|%s) the .*)$' % (self._to_name[ActionDescription.DELETION], self._to_name[ActionDescription.ARCHIVING]),
|
96
|
|
- '',
|
97
|
|
- new_name
|
98
|
|
- )
|
99
|
|
-
|
100
|
|
- new_name += extension
|
|
56
|
+ with new_revision(self.content):
|
|
57
|
+ self._actions[self._type](self.content)
|
|
58
|
+ self.content_api.save(self.content, self._type)
|
101
|
59
|
|
102
|
|
- return new_name
|
|
60
|
+ transaction.commit()
|
103
|
61
|
|
104
|
62
|
|
105
|
63
|
class Root(DAVCollection):
|