Return-Path: X-Original-To: apmail-allura-commits-archive@www.apache.org Delivered-To: apmail-allura-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EB31417F30 for ; Thu, 16 Apr 2015 16:28:46 +0000 (UTC) Received: (qmail 45628 invoked by uid 500); 16 Apr 2015 16:28:46 -0000 Delivered-To: apmail-allura-commits-archive@allura.apache.org Received: (qmail 45575 invoked by uid 500); 16 Apr 2015 16:28:46 -0000 Mailing-List: contact commits-help@allura.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@allura.apache.org Delivered-To: mailing list commits@allura.apache.org Received: (qmail 45490 invoked by uid 99); 16 Apr 2015 16:28:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Apr 2015 16:28:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 82535E10B1; Thu, 16 Apr 2015 16:28:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: heiths@apache.org To: commits@allura.apache.org Date: Thu, 16 Apr 2015 16:28:50 -0000 Message-Id: In-Reply-To: <973df9d266bc466a85cb114c6685d1a7@git.apache.org> References: <973df9d266bc466a85cb114c6685d1a7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/6] 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/master Commit: b5a084fd7832afe989e5722340c44477f088285a Parents: 9546f5a Author: Igor Bondarenko Authored: Thu Apr 16 14:51:43 2015 +0000 Committer: Igor Bondarenko 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