This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/master by this push:
     new 46dc0cfda [#8508] adding unique id to uploaded screenshots
46dc0cfda is described below

commit 46dc0cfda091db07f4c576150cc1cdf7e0a96f05
Author: Guillermo Cruz <[email protected]>
AuthorDate: Fri Apr 28 16:44:52 2023 -0500

    [#8508] adding unique id to uploaded screenshots
---
 Allura/allura/ext/admin/admin_main.py | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/Allura/allura/ext/admin/admin_main.py 
b/Allura/allura/ext/admin/admin_main.py
index 9dd17d062..08aec761d 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -52,6 +52,7 @@ from allura.lib.widgets.project_list import ProjectScreenshots
 
 from . import widgets as aw
 import six
+import uuid
 
 
 log = logging.getLogger(__name__)
@@ -517,6 +518,7 @@ class ProjectAdminController(BaseController):
     @require_post()
     @validate(W.screenshot_admin)
     def add_screenshot(self, screenshot=None, caption=None, **kw):
+        id = uuid.uuid1()
         require_access(c.project, 'update')
         screenshots = c.project.get_screenshots()
         if len(screenshots) >= 6:
@@ -525,18 +527,7 @@ class ProjectAdminController(BaseController):
         elif screenshot is not None and screenshot != '':
             future_bmp = False
             e_filename, e_fileext = os.path.splitext(screenshot.filename)
-            for screen in screenshots:
-                c_filename, c_fileext = os.path.splitext(screen.filename)
-                if c_fileext == '.png' and e_fileext.lower() == '.bmp' and 
e_filename == c_filename:
-                    future_bmp = True
-                    # If both filename(without ext.) equals and exiting file 
ext. is png and given file ext is bmp,
-                    # there will be two similar png files.
-
-                if screen.filename == screenshot.filename or future_bmp:
-                    screenshot.filename = re.sub(r'(.*)\.(.*)', r'\1-' + 
str(randint(1000, 9999)) + r'.\2',
-                                                 screenshot.filename)
-                    # if filename already exists append a random number
-                    break
+            screenshot.filename = f"{e_filename}-{id.hex[:8]}{e_fileext}"
             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])

Reply via email to