diff --git a/app/controllers/admin/items/tickets_controller.rb b/app/controllers/admin/items/tickets_controller.rb index 2a51254df..274026761 100644 --- a/app/controllers/admin/items/tickets_controller.rb +++ b/app/controllers/admin/items/tickets_controller.rb @@ -57,7 +57,7 @@ def set_ticket end def ticket_params - params.require(:ticket).permit(:title, :body, :status).merge(creator_id: current_user.id) + params.require(:ticket).permit(:title, :body, :status, :tag_list).merge(creator_id: current_user.id) end end end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 939ad40e1..15da967c9 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -35,7 +35,7 @@ class Ticket < ApplicationRecord validates :title, presence: true validates :status, inclusion: {in: Ticket.statuses.keys} - audited + audited except: :tag_list acts_as_tenant :library scope :active, -> { where(status: Ticket.statuses.values_at(:assess, :parts, :repairing)) } diff --git a/app/views/admin/items/tickets/_form.html.erb b/app/views/admin/items/tickets/_form.html.erb index a726dc6b8..bf3194fdc 100644 --- a/app/views/admin/items/tickets/_form.html.erb +++ b/app/views/admin/items/tickets/_form.html.erb @@ -4,6 +4,7 @@ <%= form.text_field :title %> <%= form.rich_text_area :body %> <%= form.select :status, options_for_select(ticket_status_options, ticket.status), label: "Ticket Status" %> + <%= form.text_field :tag_list, label: "Tags", value: ticket.tag_list.join(", "), hint: "Comma separated e.g. 'Urgent, Quick Fix, etc'" %> <%= form.actions do %> <%= form.submit %> diff --git a/app/views/admin/items/tickets/index.html.erb b/app/views/admin/items/tickets/index.html.erb index 39b295870..e18c03854 100644 --- a/app/views/admin/items/tickets/index.html.erb +++ b/app/views/admin/items/tickets/index.html.erb @@ -4,6 +4,7 @@ Title Status + Tags Last Updated @@ -13,6 +14,11 @@ <%= link_to ticket.title, admin_item_ticket_path(@item, ticket) %> <%= ticket_status_name ticket.status %> + + <% ticket.tag_list.each do |tag| %> + <%= tag %> + <% end %> + <%= display_date ticket.updated_at, :short_date %> <% end %> diff --git a/app/views/admin/items/tickets/show.html.erb b/app/views/admin/items/tickets/show.html.erb index d8643e688..043426f0f 100644 --- a/app/views/admin/items/tickets/show.html.erb +++ b/app/views/admin/items/tickets/show.html.erb @@ -7,6 +7,10 @@

<%= ticket_status_name @ticket.status %> + <% @ticket.tag_list.each do |tag| %> + <%= tag %> + <% end %> +
Created by <%= link_to_member(@ticket.creator.member) %> on <%= display_date @ticket.created_at, :short_date %>

diff --git a/test/controllers/admin/items/tickets_controller_test.rb b/test/controllers/admin/items/tickets_controller_test.rb index 55b00981d..933c79e3c 100644 --- a/test/controllers/admin/items/tickets_controller_test.rb +++ b/test/controllers/admin/items/tickets_controller_test.rb @@ -31,9 +31,10 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest status = "assess" title = "A ticket title" body = "A ticket body" + tags = ["a", "b", "c"] assert_difference("Ticket.count") do - post admin_item_tickets_url(@item), params: {ticket: {status:, title:, body:}} + post admin_item_tickets_url(@item), params: {ticket: {status:, title:, body:, tag_list: tags.join(", ")}} end assert_redirected_to admin_item_ticket_url(@item, Ticket.last) @@ -43,6 +44,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest assert_equal status, ticket.status assert_equal title, ticket.title assert_equal body, ticket.body.to_plain_text + assert_equal tags, ticket.tag_list end test "creating a ticket with any status besides 'retired' updates the ticket's status to 'maintenance'" do @@ -91,17 +93,19 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest end test "should update ticket" do - @ticket = create(:ticket, item: @item) + @ticket = create(:ticket, item: @item, tag_list: %w[foo bar]) status = "parts" body = "Waiting on parts" + tags = ["a", "b", "c"] - patch admin_item_ticket_url(@item, @ticket), params: {ticket: {status:, body:}} + patch admin_item_ticket_url(@item, @ticket), params: {ticket: {status:, body:, tag_list: tags.join(", ")}} assert_redirected_to admin_item_ticket_url(@item, @ticket) @ticket.reload assert_equal status, @ticket.status assert_equal body, @ticket.body.to_plain_text + assert_equal tags, @ticket.tag_list end test "updating a ticket to retired makes the item retired" do