Don't create useless transitions between identical states and clean previous ones with migration
A FIXED -> FIXED transition happens, e.g., here: https://todo.sr.ht/~sircmpwn/meta.sr.ht/46#event-47525 because I fucked up a link and listed this one twice, and Drew opened each link first, then closed them, hence marking the ticket as FIXED twice With this patch, we just do nothing if there's nothing to do
This commit is contained in:
parent
85a7f0f6e1
commit
f368e772f3
|
@ -0,0 +1,31 @@
|
|||
"""Clean no-comment isostatus-change events
|
||||
|
||||
Revision ID: 6742af305c73
|
||||
Revises: c32f13924e46
|
||||
Create Date: 2020-08-25 23:50:49.940532
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '6742af305c73'
|
||||
down_revision = 'c32f13924e46'
|
||||
|
||||
from alembic import op
|
||||
from todosrht.types import Event, EventType
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
Session = sessionmaker()
|
||||
|
||||
|
||||
def upgrade():
|
||||
bind = op.get_bind()
|
||||
session = Session(bind=bind)
|
||||
(session.query(Event)
|
||||
.filter(Event.comment_id == None)
|
||||
.filter(Event.event_type == EventType.status_change)
|
||||
.filter(Event.old_status == Event.new_status)
|
||||
.filter(Event.old_resolution == Event.new_resolution)).delete()
|
||||
|
||||
|
||||
def downgrade():
|
||||
pass
|
|
@ -193,6 +193,8 @@ def ticket_comment_POST(owner, name, ticket_id):
|
|||
participant = get_participant_for_user(current_user)
|
||||
event = add_comment(participant, ticket,
|
||||
text=text, resolve=resolve, resolution=resolution, reopen=reopen)
|
||||
if not event:
|
||||
return redirect(ticket_url(ticket))
|
||||
|
||||
TicketWebhook.deliver(TicketWebhook.Events.event_create,
|
||||
event.to_dict(),
|
||||
|
|
|
@ -197,10 +197,14 @@ def _change_ticket_status(ticket, resolve, resolution, reopen):
|
|||
old_resolution = ticket.resolution
|
||||
|
||||
if resolve:
|
||||
if old_status == TicketStatus.resolved and old_resolution == resolution:
|
||||
return None
|
||||
ticket.status = TicketStatus.resolved
|
||||
ticket.resolution = resolution
|
||||
|
||||
if reopen:
|
||||
if old_status == TicketStatus.reported:
|
||||
return None
|
||||
ticket.status = TicketStatus.reported
|
||||
|
||||
return StatusChange(old_status, ticket.status,
|
||||
|
@ -303,6 +307,8 @@ def add_comment(submitter, ticket,
|
|||
|
||||
comment = _create_comment(ticket, submitter, text) if text else None
|
||||
status_change = _change_ticket_status(ticket, resolve, resolution, reopen)
|
||||
if not comment and not status_change:
|
||||
return None
|
||||
event = _create_comment_event(ticket, submitter, comment, status_change)
|
||||
notified_participants = _send_comment_notifications(
|
||||
submitter, ticket, event, comment, resolution)
|
||||
|
|
Loading…
Reference in New Issue