parsemail.py: Improve status-change-through-email
PATCH 1/1 parsemail.py: Improve status-change-through-email
Patch status can be edited through email by project maintainers only without any feedback if this is attempted by any other user, providing a poor user experience.
This change extends the patch-status-through-email functionality to be performed by the series submitter also, and provides a system-generated message if an attempt was made through a message using an email address not recognized neither as project maintainer or series submitter in patchwork.
[YOCTO #11027]
Signed-off-by Jose Lamego <[email protected]>
--- patchwork/bin/parsemail.py | 73 +++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 24 deletions(-)
patchwork/bin/parsemail.py +49 -24
@@ -838,31 +838,56 @@ def parse_mail(mail): comment.msgid = msgid comment.save() LOGGER.debug('Comment saved') - - # if comment's author has project-maintainer permissions, - # parse comment content and process the status-change command - # if it is found - if author.user and project in \ - (author.user).profile.maintainer_projects.all(): - cmd = None - comment_re = re.compile('^\[Patchwork-Status:\s*(Under Review|\ -Rejected|RFC|Not Applicable|Changes Requested|Awaiting Upstream|Superseded|\ -Deferred)\]$', re.M | re.I) - # if multiple valid status-change commands are found, use last one - for match in comment_re.finditer(comment.content): - cmd = re.sub(r'(\[Patchwork-Status:\s*)(.*)(\])', r'\2', - "{}".format(match.group(0))) - if cmd is not None: - new_state = State.objects.get(name=cmd.title()) - mod_patch = Patch.objects.get(pk=comment.patch.pk) - if new_state and mod_patch.state != new_state: - mod_patch.state = new_state - mod_patch.save() - cmd_message = 'This is a system generated Comment: Patch \ -%s status was updated to "%s" due to request in comment.' % ( - comment.patch.pk, cmd) + # look for a status-change command string in the comment + cmd = None + comment_re = re.compile('^(?:\n|\r\n?)\[Patchwork-Status:\s*\ +(Under Review|Rejected|RFC|Not Applicable|Changes Requested|Awaiting \ +Upstream|Superseded|Deferred)\](?:\n|\r\n?)$', re.M | re.I) + # if multiple valid status-change commands are found, use last one + for match in comment_re.finditer(comment.content): + cmd = re.sub( + r'((?:\n|\r\n?)\[Patchwork-Status:\s*)(.*)(\](?:\n|\r\n?))', + r'\2', "{}".format(match.group(0))) + # if a status-change command string is found, see if comment's author + # has either project-maintainer permissions or is the series submitter + # and process the command if true. + if cmd is not None: + refs = build_references_list(mail) + if not refs == []: + if not series: + series = SeriesRevision.objects.filter( + series__project=project, + root_msgid=refs[-1]).reverse()[0].series + if (author.user and project in + (author.user).profile.maintainer_projects.all()) or ( + author and author == series.submitter): + new_state = State.objects.get(name=cmd.title()) + mod_patch = Patch.objects.get(pk=comment.patch.pk) + if new_state and mod_patch.state != new_state: + mod_patch.state = new_state + mod_patch.save() + cmd_message = 'This is a system generated Comment: \ +Patch %s status was updated to "%s"\ndue to request in comment body.' % ( + comment.patch.pk, cmd) + cmd_msgid = "%s: System generated by comment %s" % ( + datetime.datetime.now().strftime("\ +%d%b%Y.%H:%M:%S.%f"), comment.pk) + new_comment = Comment(pk=None, patch=comment.patch, + content=cmd_message, + date=datetime.datetime.now(), + submitter=comment.submitter, + msgid=cmd_msgid) + new_comment.save() + else: + # notify that a patch-status change was attempted without + # apropriate submitter/maintainer permissions + cmd_message = 'This is a system generated Comment: \ +A command to change a patch-status through\nemail was detected in comment, \ +but the sender email does not belong either to\na project maintainer or to \ +the series submitter, the only approved users for\nthis function. \ +Ensure you are using an approved email address when submitting.' cmd_msgid = "%s: System generated by comment %s" % ( - datetime.datetime.now().strftime("\ + datetime.datetime.now().strftime("\ %d%b%Y.%H:%M:%S.%f"), comment.pk) new_comment = Comment(pk=None, patch=comment.patch, content=cmd_message,
Signature · 1 line
2.7.4