You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2021/10/15 16:08:43 UTC

[allura] branch master updated (c68a5ff -> 04f14f1)

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

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


    from c68a5ff  Use default correctly in User.get_tool_data
     new 24f5b49  updated the flash message if the picture upload raises an exception
     new 04f14f1  Log more details about image failures

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Allura/allura/controllers/project.py  |  8 ++++++--
 Allura/allura/ext/admin/admin_main.py | 14 +++++++++++---
 Allura/allura/model/filesystem.py     |  2 +-
 Allura/allura/model/project.py        | 25 ++++++++++++++-----------
 4 files changed, 32 insertions(+), 17 deletions(-)

[allura] 01/02: updated the flash message if the picture upload raises an exception

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 24f5b496ff21a2e91e476b8db352018b89b4762d
Author: Guillermo Cruz <gu...@slashdotmedia.com>
AuthorDate: Tue Oct 12 14:19:21 2021 -0600

    updated the flash message if the picture upload raises an exception
---
 Allura/allura/controllers/project.py  |  8 ++++++--
 Allura/allura/ext/admin/admin_main.py | 14 +++++++++++---
 Allura/allura/model/project.py        | 25 ++++++++++++++-----------
 3 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 9d01eae..3e8a4b4 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -679,8 +679,12 @@ class NeighborhoodAdminController(object):
             if self.neighborhood.icon:
                 self.neighborhood.icon.delete()
                 M.ProjectFile.query.remove(dict(project_id=c.project._id, category=re.compile(r'^icon')))
-            M.AuditLog.log('update neighborhood icon')
-            c.project.save_icon(icon.filename, icon.file, content_type=icon.type)
+            save_icon = c.project.save_icon(icon.filename, icon.file, content_type=icon.type)
+            if save_icon:
+                M.AuditLog.log('update neighborhood icon')
+            else:
+                M.AuditLog.log('could not update neighborhood icon')
+                flash("There's a problem with the uploaded image", 'error')
         redirect('overview')
 
     @expose('jinja:allura:templates/neighborhood_help.html')
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index 064108e..079f60f 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -328,6 +328,8 @@ class ProjectAdminController(BaseController):
                features=None,
                **kw):
         require_access(c.project, 'update')
+        flash_status = 'success'
+        flash_message = 'Form values saved'
 
         if removal != c.project.removal:
             M.AuditLog.log('change project removal status to %s', removal)
@@ -405,10 +407,16 @@ class ProjectAdminController(BaseController):
         if icon is not None and icon != b'':
             if c.project.icon:
                 M.ProjectFile.query.remove(dict(project_id=c.project._id, category=re.compile(r'^icon')))
-            M.AuditLog.log('update project icon')
-            c.project.save_icon(icon.filename, icon.file, content_type=icon.type)
+            save_icon = c.project.save_icon(icon.filename, icon.file, content_type=icon.type)
+            if not save_icon:
+                M.AuditLog.log('could not update project icon')
+                flash_message = f'{flash_message}, but image upload failed'
+                flash_status = 'warning'
+            else:
+                M.AuditLog.log('update project icon')
+
         g.post_event('project_updated')
-        flash('Saved', 'success')
+        flash(flash_message, flash_status)
         redirect('overview')
 
     def _add_trove(self, type, new_trove):
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 694e0eb..1ef6973 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -392,19 +392,22 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
             original_meta=dict(project_id=self._id, category='icon_original'),
             convert_bmp=True,
         )
-        # store the dimensions so we don't have to read the whole image each time we need to know
-        icon_orig_img = PIL.Image.open(icon_orig.rfile())
+        if icon_orig:
+            # store the dimensions so we don't have to read the whole image each time we need to know
+            icon_orig_img = PIL.Image.open(icon_orig.rfile())
 
-        self.set_tool_data('allura', icon_original_size=icon_orig_img.size)
+            self.set_tool_data('allura', icon_original_size=icon_orig_img.size)
 
-        try:
-            # calc and save icon file hash, for better cache busting purposes
-            file_input.seek(0)
-            file_bytes = file_input.read()
-            file_sha256 = sha256(file_bytes).hexdigest()
-            self.set_tool_data('allura', icon_sha256=file_sha256)
-        except Exception as ex:
-            log.exception('Failed to calculate sha256 for icon file for {}'.format(self.shortname))
+            try:
+                # calc and save icon file hash, for better cache busting purposes
+                file_input.seek(0)
+                file_bytes = file_input.read()
+                file_sha256 = sha256(file_bytes).hexdigest()
+                self.set_tool_data('allura', icon_sha256=file_sha256)
+            except Exception as ex:
+                log.exception('Failed to calculate sha256 for icon file for {}'.format(self.shortname))
+            return True
+        return False
 
     @property
     def icon(self):

[allura] 02/02: Log more details about image failures

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 04f14f15a9a9364e18c61f68acdaa241a470186b
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Fri Oct 15 16:07:02 2021 +0000

    Log more details about image failures
---
 Allura/allura/model/filesystem.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Allura/allura/model/filesystem.py b/Allura/allura/model/filesystem.py
index 32d3296..e7f8d35 100644
--- a/Allura/allura/model/filesystem.py
+++ b/Allura/allura/model/filesystem.py
@@ -218,7 +218,7 @@ class File(MappedClass):
                     image.save(fp_w, format, save_all=save_anim, optimize=True, **save_kwargs)
                 except Exception as e:
                     session(original).expunge(original)
-                    log.error('Error saving image %s %s', filename, e)
+                    log.exception('Error saving image %s %s %s', filename, content_type, format)
                     return None, None
         else:
             original = None