forked from e621ng/e621ng
[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 <earlopain+github@protonmail.com> * Update app/views/tickets/show.html.erb Co-authored-by: Earlopain <earlopain+github@protonmail.com> * 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 <earlopain+github@protonmail.com> Co-authored-by: Earlopain <earlopain@protonmail.com>
This commit is contained in:
parent
ee359d290f
commit
b339e84612
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -50,8 +50,8 @@
|
||||
<% end %>
|
||||
|
||||
<td class="<%= ticket.status %>-ticket"><%= pretty_ticket_status(ticket) %></td>
|
||||
<td style="cursor:help;" title="<%= ticket.updated_at.strftime("%b %d, %Y %I:%M %p") %>"><%= time_ago_in_words(ticket.updated_at) %> ago</td>
|
||||
<td style="cursor:help;" title="<%= ticket.created_at.strftime("%b %d, %Y %I:%M %p") %>"><%= time_ago_in_words(ticket.created_at) %> ago</td>
|
||||
<td style="cursor:help;"><%= time_ago_in_words_tagged(ticket.updated_at) %></td>
|
||||
<td style="cursor:help;"><%= time_ago_in_words_tagged(ticket.created_at) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
@ -13,13 +13,24 @@
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if @ticket.accused.present? && CurrentUser.is_moderator? %>
|
||||
<tr>
|
||||
<td><span class="title">Accused</span></td>
|
||||
<td>
|
||||
<%= 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 %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<td><span class="title">Created</span></td>
|
||||
<td style="cursor:help;" title="<%= @ticket.created_at.strftime("%b %d, %Y %I:%M %p") %>"><%= time_ago_in_words(@ticket.created_at) %> ago</td>
|
||||
<td style="cursor:help;"><%= time_ago_in_words_tagged(@ticket.created_at) %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span class="title">Updated</span></td>
|
||||
<td style="cursor:help;" title="<%= @ticket.updated_at.strftime("%b %d, %Y %I:%M %p") %>"><%= time_ago_in_words(@ticket.updated_at) %> ago</td>
|
||||
<td style="cursor:help;"><%= time_ago_in_words_tagged(@ticket.updated_at) %></td>
|
||||
</tr>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<tr>
|
||||
@ -71,10 +82,10 @@
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<% if(!@ticket.response.blank?) %>
|
||||
<% if @ticket.response.present? %>
|
||||
<tr>
|
||||
<td><span class='title'>Handled by</span></td>
|
||||
<% if (!@ticket.handler.nil?)%>
|
||||
<% if @ticket.handler.present? %>
|
||||
<td><%= link_to_user @ticket.handler %></td>
|
||||
<% else %>
|
||||
<td>Unknown</td>
|
||||
|
@ -37,7 +37,7 @@
|
||||
[<%= link_to "sample", posts_path(:tags => "user:#{user.name} order:random limit:300 status:deleted") %>]
|
||||
<% end %>
|
||||
</span>
|
||||
|
||||
|
||||
<span>Replaced</span>
|
||||
<span>
|
||||
<%= presenter.replaced_upload_count(self) %>
|
||||
@ -141,6 +141,17 @@
|
||||
<span><%= presenter.flag_count(self) %></span>
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.user.id == user.id || CurrentUser.is_moderator? %>
|
||||
<span>Tickets</span>
|
||||
<span>
|
||||
<%= 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 %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.id == user.id %>
|
||||
<span>API Key</span>
|
||||
<span>
|
||||
|
7
db/fixes/109_user_status_ticket_count.rb
Executable file
7
db/fixes/109_user_status_ticket_count.rb
Executable file
@ -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
|
@ -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
|
@ -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');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user