This is an automated email from the ASF dual-hosted git repository. gcruz pushed a commit to branch gc/8508 in repository https://gitbox.apache.org/repos/asf/allura.git
commit 269ba7abc6e4f6db8c937434537e830c03605d87 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 +++------------ Allura/allura/model/project.py | 4 ++++ Allura/allura/templates/widgets/project_screenshots.html | 2 +- 3 files changed, 8 insertions(+), 13 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]) diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py index e6ff5af2e..9d90bea39 100644 --- a/Allura/allura/model/project.py +++ b/Allura/allura/model/project.py @@ -94,6 +94,10 @@ class ProjectFile(File): caption = FieldProperty(str) sort = FieldProperty(int) + @LazyProperty + def screenshot_timestamp(self): + return timegm(self._id.generation_time.timetuple()) + class ProjectCategory(MappedClass): diff --git a/Allura/allura/templates/widgets/project_screenshots.html b/Allura/allura/templates/widgets/project_screenshots.html index 5aa5059d2..a595b5baf 100644 --- a/Allura/allura/templates/widgets/project_screenshots.html +++ b/Allura/allura/templates/widgets/project_screenshots.html @@ -25,7 +25,7 @@ {% for ss in screenshots %} <div data-ss-id="{{ ss._id }}" class="screenshot"> <div class="image"> - <a class="lightbox" href="{{project.url()}}screenshot/{{h.urlquote(ss.filename)}}" ><img src="{{project.url()}}screenshot/{{h.urlquote(ss.filename)}}/thumb" alt="Screenshot thumbnail"/></a> + <a class="lightbox" href="{{project.url()}}screenshot/{{h.urlquote(ss.filename)}}" ><img src="{{project.url()}}screenshot/{{h.urlquote(ss.filename)}}/thumb?{{ ss.screenshot_timestamp }}" alt="Screenshot thumbnail"/></a> {% if not edit %} <br> {{ss.caption}}
