From b339e8461267fa559d79c42c891c2717ccaa592d Mon Sep 17 00:00:00 2001 From: Donovan Daniels Date: Tue, 16 May 2023 13:48:51 -0500 Subject: [PATCH] [Tickets] Profile Links & Pending Count (#518) * [Tickets] Profile Links & Pending Count * stuff a sock in it, rubocop * Remove counts fixer for ticketss * Update app/views/tickets/show.html.erb Co-authored-by: Earlopain * Update app/views/tickets/show.html.erb Co-authored-by: Earlopain * use standardized timestamps * this got yeeted at some point * Fix search links, only show pending count when >= 2 I'm imagining some confusion if it shows one pending when it is just the one you're looking at right now * Fix fixer? `update_column` throws a readonly error * `for_user` is only used in fixer script * Fix fixer script, for real --------- Co-authored-by: Earlopain Co-authored-by: Earlopain --- app/models/ticket.rb | 9 ++++++ app/models/user.rb | 4 +++ app/presenters/user_presenter.rb | 30 +++++++++++-------- app/views/tickets/index.html.erb | 4 +-- app/views/tickets/show.html.erb | 19 +++++++++--- app/views/users/_statistics.html.erb | 13 +++++++- db/fixes/109_user_status_ticket_count.rb | 7 +++++ ...13074838_add_user_statuses_ticket_count.rb | 5 ++++ db/structure.sql | 6 ++-- 9 files changed, 75 insertions(+), 22 deletions(-) create mode 100755 db/fixes/109_user_status_ticket_count.rb create mode 100644 db/migrate/20230513074838_add_user_statuses_ticket_count.rb diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 0d27eb846..b944f9daf 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1,5 +1,6 @@ class Ticket < ApplicationRecord belongs_to_creator + user_status_counter :ticket_count belongs_to :claimant, class_name: "User", optional: true belongs_to :handler, class_name: "User", optional: true belongs_to :accused, class_name: "User", optional: true @@ -213,6 +214,14 @@ class Ticket < ApplicationRecord end module SearchMethods + def for_accused(user_id) + where(accused_id: user_id) + end + + def active + where(status: %w[pending partial]) + end + def search(params) q = super.includes(:creator).includes(:claimant) diff --git a/app/models/user.rb b/app/models/user.rb index a658e1077..d9c2f3622 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -732,6 +732,10 @@ class User < ApplicationRecord user_status.post_flag_count end + def ticket_count + user_status.ticket_count + end + def positive_feedback_count feedback.positive.count end diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index fb1de2e41..60fb18cde 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -69,11 +69,11 @@ class UserPresenter end def upload_count(template) - template.link_to(user.post_upload_count, template.posts_path(:tags => "user:#{user.name}")) + template.link_to(user.post_upload_count, template.posts_path(tags: "user:#{user.name}")) end def active_upload_count(template) - template.link_to(user.post_upload_count - user.post_deleted_count, template.posts_path(:tags => "user:#{user.name}")) + template.link_to(user.post_upload_count - user.post_deleted_count, template.posts_path(tags: "user:#{user.name}")) end def deleted_upload_count(template) @@ -89,53 +89,57 @@ class UserPresenter end def favorite_count(template) - template.link_to(user.favorite_count, template.favorites_path(:user_id => user.id)) + template.link_to(user.favorite_count, template.favorites_path(user_id: user.id)) end def comment_count(template) - template.link_to(user.comment_count, template.comments_path(:search => {:creator_id => user.id}, :group_by => "comment")) + template.link_to(user.comment_count, template.comments_path(search: { creator_id: user.id }, group_by: "comment")) end def commented_posts_count(template) count = CurrentUser.without_safe_mode { Post.fast_count("commenter:#{user.name}") } - template.link_to(count, template.posts_path(:tags => "commenter:#{user.name} order:comment_bumped")) + template.link_to(count, template.posts_path(tags: "commenter:#{user.name} order:comment_bumped")) end def post_version_count(template) - template.link_to(user.post_update_count, template.post_versions_path(:lr => user.id, :search => {:updater_id => user.id})) + template.link_to(user.post_update_count, template.post_versions_path(lr: user.id, search: { updater_id: user.id })) end def note_version_count(template) - template.link_to(user.note_version_count, template.note_versions_path(:search => {:updater_id => user.id})) + template.link_to(user.note_version_count, template.note_versions_path(search: { updater_id: user.id })) end def noted_posts_count(template) count = CurrentUser.without_safe_mode { Post.fast_count("noteupdater:#{user.name}") } - template.link_to(count, template.posts_path(:tags => "noteupdater:#{user.name} order:note")) + template.link_to(count, template.posts_path(tags: "noteupdater:#{user.name} order:note")) end def wiki_page_version_count(template) - template.link_to(user.wiki_page_version_count, template.wiki_page_versions_path(:search => {:updater_id => user.id})) + template.link_to(user.wiki_page_version_count, template.wiki_page_versions_path(search: { updater_id: user.id })) end def artist_version_count(template) - template.link_to(user.artist_version_count, template.artist_versions_path(:search => {:updater_id => user.id})) + template.link_to(user.artist_version_count, template.artist_versions_path(search: { updater_id: user.id })) end def forum_post_count(template) - template.link_to(user.forum_post_count, template.forum_posts_path(:search => {:creator_id => user.id})) + template.link_to(user.forum_post_count, template.forum_posts_path(search: { creator_id: user.id })) end def pool_version_count(template) - template.link_to(user.pool_version_count, template.pool_versions_path(:search => {:updater_id => user.id})) + template.link_to(user.pool_version_count, template.pool_versions_path(search: { updater_id: user.id })) end def flag_count(template) template.link_to(user.flag_count, template.post_flags_path(search: { creator_id: user.id })) end + def ticket_count(template) + template.link_to(user.ticket_count, template.tickets_path(search: { creator_id: user.id })) + end + def approval_count(template) - template.link_to(Post.where("approver_id = ?", user.id).count, template.posts_path(:tags => "approver:#{user.name}")) + template.link_to(Post.where("approver_id = ?", user.id).count, template.posts_path(tags: "approver:#{user.name}")) end def feedbacks diff --git a/app/views/tickets/index.html.erb b/app/views/tickets/index.html.erb index be94e023c..dfbe66765 100644 --- a/app/views/tickets/index.html.erb +++ b/app/views/tickets/index.html.erb @@ -50,8 +50,8 @@ <% end %> <%= pretty_ticket_status(ticket) %> - "><%= time_ago_in_words(ticket.updated_at) %> ago - "><%= time_ago_in_words(ticket.created_at) %> ago + <%= time_ago_in_words_tagged(ticket.updated_at) %> + <%= time_ago_in_words_tagged(ticket.created_at) %> <% end %> diff --git a/app/views/tickets/show.html.erb b/app/views/tickets/show.html.erb index cb1a14f77..7098263ea 100644 --- a/app/views/tickets/show.html.erb +++ b/app/views/tickets/show.html.erb @@ -13,13 +13,24 @@ <% end %> + <% if @ticket.accused.present? && CurrentUser.is_moderator? %> + + Accused + + <%= link_to_user @ticket.accused %> + <% if (pending_accused_count = Ticket.active.for_accused(@ticket.accused.id).count) >= 2 %> + (<%= link_to "#{pending_accused_count} Pending", tickets_path(search: { accused_id: @ticket.accused.id, status: "pending" }) %>) + <% end %> + + + <% end %> Created - "><%= time_ago_in_words(@ticket.created_at) %> ago + <%= time_ago_in_words_tagged(@ticket.created_at) %> Updated - "><%= time_ago_in_words(@ticket.updated_at) %> ago + <%= time_ago_in_words_tagged(@ticket.updated_at) %> <% if CurrentUser.is_moderator? %> @@ -71,10 +82,10 @@ - <% if(!@ticket.response.blank?) %> + <% if @ticket.response.present? %> Handled by - <% if (!@ticket.handler.nil?)%> + <% if @ticket.handler.present? %> <%= link_to_user @ticket.handler %> <% else %> Unknown diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index 3cee5e1e4..24fef1c93 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -37,7 +37,7 @@ [<%= link_to "sample", posts_path(:tags => "user:#{user.name} order:random limit:300 status:deleted") %>] <% end %> - + Replaced <%= presenter.replaced_upload_count(self) %> @@ -141,6 +141,17 @@ <%= presenter.flag_count(self) %> <% end %> + <% if CurrentUser.user.id == user.id || CurrentUser.is_moderator? %> + Tickets + + <%= presenter.ticket_count(self) %> + <% if CurrentUser.is_moderator? %> + [<%= link_to "pending", tickets_path(search: { creator_id: user.id, status: "pending" }) %>] + [<%= link_to "accused", tickets_path(search: { accused_id: user.id, status: "pending" }) %>] + <% end %> + + <% end %> + <% if CurrentUser.id == user.id %> API Key diff --git a/db/fixes/109_user_status_ticket_count.rb b/db/fixes/109_user_status_ticket_count.rb new file mode 100755 index 000000000..e991f07a9 --- /dev/null +++ b/db/fixes/109_user_status_ticket_count.rb @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "environment")) + +User.find_each do |user| + UserStatus.for_user(user.id).update_all(ticket_count: Ticket.where(creator_id: user.id).count) +end diff --git a/db/migrate/20230513074838_add_user_statuses_ticket_count.rb b/db/migrate/20230513074838_add_user_statuses_ticket_count.rb new file mode 100644 index 000000000..91341dd97 --- /dev/null +++ b/db/migrate/20230513074838_add_user_statuses_ticket_count.rb @@ -0,0 +1,5 @@ +class AddUserStatusesTicketCount < ActiveRecord::Migration[7.0] + def change + add_column :user_statuses, :ticket_count, :integer, default: 0, null: false + end +end diff --git a/db/structure.sql b/db/structure.sql index 76002e7e1..f42f60213 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2214,7 +2214,8 @@ CREATE TABLE public.user_statuses ( artist_edit_count integer DEFAULT 0 NOT NULL, own_post_replaced_count integer DEFAULT 0, own_post_replaced_penalize_count integer DEFAULT 0, - post_replacement_rejected_count integer DEFAULT 0 + post_replacement_rejected_count integer DEFAULT 0, + ticket_count integer DEFAULT 0 NOT NULL ); @@ -4638,6 +4639,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230312103728'), ('20230314170352'), ('20230316084945'), -('20230506161827'); +('20230506161827'), +('20230513074838');