You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by gc...@apache.org on 2022/09/02 17:43:07 UTC
[allura] 06/06: [#8458] auditlog: record screenshots add/update/delete/reorder
This is an automated email from the ASF dual-hosted git repository.
gcruz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 24a300e1fa535e5ea63bd081a7dd5f72b546cff8
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Thu Sep 1 15:11:25 2022 +0000
[#8458] auditlog: record screenshots add/update/delete/reorder
---
Allura/allura/ext/admin/admin_main.py | 19 ++++++++++++++-----
Allura/allura/tests/functional/test_admin.py | 2 +-
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index f3466d943..d40d9b9b0 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -489,7 +489,8 @@ class ProjectAdminController(BaseController):
screenshot.filename = re.sub(r'(.*)\.(.*)', r'\1-' + str(randint(1000,9999)) + r'.\2', screenshot.filename)
# if filename already exists append a random number
break
- M.AuditLog.log('add screenshot')
+ M.AuditLog.log('screenshots: added screenshot {} with caption "{}"'.format(
+ screenshot.filename, caption))
sort = 1 + max([ss.sort or 0 for ss in screenshots] or [0])
M.ProjectFile.save_image(
screenshot.filename, screenshot.file, content_type=screenshot.type,
@@ -515,9 +516,13 @@ class ProjectAdminController(BaseController):
``kw`` is a mapping of (screenshot._id, sort_order) pairs.
"""
- for s in c.project.get_screenshots():
+ screenshots = c.project.get_screenshots()
+ for s in screenshots:
if str(s._id) in kw:
s.sort = int(kw[str(s._id)])
+ M.AuditLog.log('screenshots: reordered screenshots {}'.format(
+ ", ".join(s.filename for s in sorted(screenshots, key=lambda s: s.sort))
+ ))
g.post_event('project_updated')
@expose()
@@ -525,7 +530,8 @@ class ProjectAdminController(BaseController):
def delete_screenshot(self, id=None, **kw):
require_access(c.project, 'update')
if id is not None and id != '':
- M.AuditLog.log('remove screenshot')
+ screenshot = M.ProjectFile.query.get(project_id=c.project._id, _id=ObjectId(id))
+ M.AuditLog.log('screenshots: deleted screenshot {}'.format(screenshot.filename))
M.ProjectFile.query.remove(
dict(project_id=c.project._id, _id=ObjectId(id)))
g.post_event('project_updated')
@@ -536,8 +542,11 @@ class ProjectAdminController(BaseController):
def edit_screenshot(self, id=None, caption=None, **kw):
require_access(c.project, 'update')
if id is not None and id != '':
- M.ProjectFile.query.get(
- project_id=c.project._id, _id=ObjectId(id)).caption = caption
+ screenshot = M.ProjectFile.query.get(
+ project_id=c.project._id, _id=ObjectId(id))
+ screenshot.caption = caption
+ M.AuditLog.log('screenshots: updated screenshot {} with new caption "{}"'.format(
+ screenshot.filename, screenshot.caption))
g.post_event('project_updated')
redirect('screenshots')
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 8237bf332..96138ffea 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -405,7 +405,7 @@ class TestProjectAdmin(TestController):
upload = ('screenshot', file_name, file_data)
self.app.get('/admin/')
- with audits('add screenshot'):
+ with audits('screenshots: added screenshot {}'.format(file_name)):
self.app.post('/admin/add_screenshot', params=dict(
caption='test me'),
upload_files=[upload])