Skip to content

Commit

Permalink
Allow admins to add/remove/see tags on tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
crismali committed Dec 18, 2024
1 parent 2c9734b commit c16b6e1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/items/tickets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/items/tickets/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/admin/items/tickets/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<tr>
<th>Title</th>
<th>Status</th>
<th>Tags</th>
<th>Last Updated</th>
</tr>
</thead>
Expand All @@ -13,6 +14,11 @@
<tr>
<td><%= link_to ticket.title, admin_item_ticket_path(@item, ticket) %></td>
<td><span class="chip bg-primary"><%= ticket_status_name ticket.status %></span></td>
<td>
<% ticket.tag_list.each do |tag| %>
<span class="chip"><%= tag %></span>
<% end %>
</td>
<td><%= display_date ticket.updated_at, :short_date %></td>
</tr>
<% end %>
Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/items/tickets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
</h2>
<p class="mb-3">
<span class="chip bg-primary"><%= ticket_status_name @ticket.status %></span>
<% @ticket.tag_list.each do |tag| %>
<span class="chip"><%= tag %></span>
<% end %>
<br>
Created by <%= link_to_member(@ticket.creator.member) %> on <%= display_date @ticket.created_at, :short_date %>
</p>

Expand Down
10 changes: 7 additions & 3 deletions test/controllers/admin/items/tickets_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c16b6e1

Please sign in to comment.