You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/04/21 16:25:42 UTC
[12/25] allura git commit: [#6017] ticket:756 Send notification when
attachment is deleted
[#6017] ticket:756 Send notification when attachment is deleted
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/b5a084fd
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/b5a084fd
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/b5a084fd
Branch: refs/heads/ib/7856
Commit: b5a084fd7832afe989e5722340c44477f088285a
Parents: 9546f5a
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Apr 16 14:51:43 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Apr 16 14:51:43 2015 +0000
----------------------------------------------------------------------
Allura/allura/controllers/attachments.py | 19 ++++----
ForgeTracker/forgetracker/tracker_main.py | 60 ++++++++++++++++++++------
2 files changed, 57 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/b5a084fd/Allura/allura/controllers/attachments.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/attachments.py b/Allura/allura/controllers/attachments.py
index 4ab3b92..a648873 100644
--- a/Allura/allura/controllers/attachments.py
+++ b/Allura/allura/controllers/attachments.py
@@ -73,17 +73,20 @@ class AttachmentController(BaseController):
raise exc.HTTPNotFound
return attachment
+ def handle_post(self, delete, **kw):
+ require_access(self.artifact, self.edit_perm)
+ if delete:
+ self.attachment.delete()
+ try:
+ if self.thumbnail:
+ self.thumbnail.delete()
+ except exc.HTTPNotFound:
+ pass
+
@expose()
def index(self, delete=False, **kw):
if request.method == 'POST':
- require_access(self.artifact, self.edit_perm)
- if delete:
- self.attachment.delete()
- try:
- if self.thumbnail:
- self.thumbnail.delete()
- except exc.HTTPNotFound:
- pass
+ self.handle_post(delete, **kw)
redirect(request.referer)
embed = False
if self.attachment.content_type and self.attachment.content_type.startswith('image/'):
http://git-wip-us.apache.org/repos/asf/allura/blob/b5a084fd/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index f8a5680..9fc39d8 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -148,6 +148,33 @@ def get_change_text(name, new_value, old_value):
comment=None)
+def attachments_info(attachments):
+ text = []
+ for attach in attachments:
+ text.append("{} ({}; {})".format(
+ attach.filename,
+ h.do_filesizeformat(attach.length),
+ attach.content_type))
+ return "\n".join(text)
+
+
+def render_changes(changes, comment=None):
+ """
+ Render ticket changes given instanse of :class changelog:
+
+ Returns tuple (post_text, notification_text)
+ """
+ template = pkg_resources.resource_filename(
+ 'forgetracker', 'data/ticket_changed_tmpl')
+ render = partial(
+ h.render_genshi_plaintext,
+ template,
+ changelist=changes.get_changed())
+ post_text = render(comment=None)
+ notification_text = render(comment=comment) if comment else None
+ return post_text, notification_text
+
+
def _my_trackers(user, current_tracker_app_config):
'''Collect all 'Tickets' instances in all user's projects
for which user has admin permissions.
@@ -1390,15 +1417,6 @@ class TicketController(BaseController, FeedController):
@require_post()
def _update_ticket(self, post_data):
- def attachments_info(attachments):
- text = []
- for attach in attachments:
- text.append("{} ({}; {})".format(
- attach.filename,
- h.do_filesizeformat(attach.length),
- attach.content_type))
- return "\n".join(text)
-
require_access(self.ticket, 'update')
changes = changelog()
comment = post_data.pop('comment', None)
@@ -1469,11 +1487,7 @@ class TicketController(BaseController, FeedController):
self.ticket.custom_fields[cf.name] = value
changes[cf.label] = cf_val(cf)
- tpl = pkg_resources.resource_filename(
- 'forgetracker', 'data/ticket_changed_tmpl')
- render = partial(h.render_genshi_plaintext, tpl, changelist=changes.get_changed())
- post_text = render(comment=None)
- notification_text = render(comment=comment) if comment else None
+ post_text, notification_text = render_changes(changes, comment)
thread = self.ticket.discussion_thread
thread.add_post(text=post_text, is_meta=True,
notification_text=notification_text)
@@ -1552,6 +1566,24 @@ class AttachmentController(att.AttachmentController):
AttachmentClass = TM.TicketAttachment
edit_perm = 'update'
+ def handle_post(self, delete, **kw):
+ old_attachments = attachments_info(self.artifact.attachments)
+ super(AttachmentController, self).handle_post(delete, **kw)
+ if delete:
+ session(self.artifact.attachment_class()).flush()
+ # self.artifact.attachments is ming's LazyProperty, we need to reset
+ # it's cache to fetch updated attachments here:
+ self.artifact.__dict__.pop('attachments')
+ new_attachments = attachments_info(self.artifact.attachments)
+ changes = changelog()
+ changes['attachments'] = old_attachments
+ changes['attachments'] = new_attachments
+ post_text, notification = render_changes(changes)
+ self.artifact.discussion_thread.add_post(
+ text=post_text,
+ is_meta=True,
+ notification_text=notification)
+
class AttachmentsController(att.AttachmentsController):
AttachmentControllerClass = AttachmentController