[Tickets] Make response mandatory

This commit is contained in:
Earlopain 2024-01-14 12:36:37 +01:00
parent bca7d2cdd0
commit 1fed677a45
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
4 changed files with 20 additions and 8 deletions

View File

@ -34,13 +34,14 @@ class TicketsController < ApplicationController
def update
@ticket = Ticket.find(params[:id])
if @ticket.claimant_id.present? && @ticket.claimant_id != CurrentUser.id && !params[:force_claim].to_s.truthy?
flash[:notice] = "Ticket has already been claimed by somebody else, submit again to force"
redirect_to ticket_path(@ticket, force_claim: "true")
return
end
ticket_params = update_ticket_params
@ticket.transaction do
if @ticket.claimant_id.present? && @ticket.claimant_id != CurrentUser.id && !params[:force_claim].to_s.truthy?
flash[:notice] = "Ticket has already been claimed by somebody else, submit again to force"
redirect_to ticket_path(@ticket, force_claim: 'true')
return
end
ticket_params = update_ticket_params
if @ticket.warnable? && ticket_params[:record_type].present?
@ticket.content.user_warned!(ticket_params[:record_type].to_i, CurrentUser.user)
end
@ -48,9 +49,12 @@ class TicketsController < ApplicationController
@ticket.handler_id = CurrentUser.id
@ticket.claimant_id = CurrentUser.id
@ticket.update(ticket_params)
@ticket.push_pubsub("update")
end
if @ticket.valid?
not_changed = ticket_params[:send_update_dmail].to_s.truthy? && (!@ticket.saved_change_to_response? && !@ticket.saved_change_to_status?)
flash[:notice] = "Not sending update, no changes" if not_changed
@ticket.push_pubsub("update")
end
respond_with(@ticket)

View File

@ -11,6 +11,7 @@ class Ticket < ApplicationRecord
validates :qtype, presence: true
validates :reason, presence: true
validates :reason, length: { minimum: 2, maximum: Danbooru.config.ticket_max_size }
validates :response, length: { minimum: 2 }, on: :update
enum status: %i[pending partial approved].index_with(&:to_s)
after_update :log_update
after_update :create_dmail

View File

@ -0,0 +1 @@
<%= render template: "tickets/show" %>

View File

@ -34,7 +34,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
should "send a new dmail if the status is changed" do
assert_difference(-> { Dmail.count }, 2) do
put_auth ticket_path(@ticket), @admin, params: { ticket: { status: "approved" } }
put_auth ticket_path(@ticket), @admin, params: { ticket: { status: "approved", response: "abc" } }
end
end
@ -47,6 +47,12 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
put_auth ticket_path(@ticket), @admin, params: { ticket: { response: "def", send_update_dmail: true } }
end
end
should "reject empty responses" do
assert_no_changes(-> { @ticket.reload.status }) do
put_auth ticket_path(@ticket), @admin, params: { ticket: { status: "approved", response: "" } }
end
end
end
context "for a forum ticket" do