[Replacements] Record original uploader

Add a link to users profile to search for their replaced posts and give
janitors the option to penalize the user when appropriate
This commit is contained in:
Earlopain 2021-06-26 13:01:26 +02:00
parent 851c0b281c
commit da96e16fd6
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
10 changed files with 74 additions and 12 deletions

View File

@ -25,7 +25,7 @@ class PostReplacementsController < ApplicationController
def approve
@post_replacement = PostReplacement.find(params[:id])
@post_replacement.approve!
@post_replacement.approve!(penalize_current_uploader: params[:penalize_current_uploader])
respond_with(@post_replacement, location: post_path(@post_replacement.post))
end

View File

@ -35,7 +35,7 @@ class UploadService
raise ProcessingError, "Could not create post file backup?" if !repl.valid?
end
def process!
def process!(penalize_current_uploader:)
# Prevent trying to replace deleted posts
raise ProcessingError, "Cannot replace post: post is deleted." if post.is_deleted?
@ -91,7 +91,17 @@ class UploadService
rescale_notes(post)
update_ugoira_frame_data(post, upload)
replacement.update({status: 'approved', approver_id: CurrentUser.id})
replacement.update({
status: 'approved',
approver_id: CurrentUser.id,
uploader_id_on_approve: post.uploader_id_before_last_save,
penalize_uploader_on_approve: penalize_current_uploader
})
UserStatus.for_user(post.uploader_id_before_last_save).update_all("own_post_replaced_count = own_post_replaced_count + 1")
if penalize_current_uploader
UserStatus.for_user(post.uploader_id_before_last_save).update_all("own_post_replaced_penalize_count = own_post_replaced_penalize_count + 1")
end
if post.is_video?
post.generate_video_samples(later: true)

View File

@ -173,11 +173,11 @@ class PostReplacement < ApplicationRecord
end
module ProcessingMethods
def approve!
def approve!(penalize_current_uploader:)
transaction do
ModAction.log(:post_replacement_accept, {post_id: post.id, replacement_id: self.id, old_md5: post.md5, new_md5: self.md5})
processor = UploadService::Replacer.new(post: post, replacement: self)
processor.process!
processor.process!(penalize_current_uploader: penalize_current_uploader)
end
post.update_index
end
@ -195,6 +195,7 @@ class PostReplacement < ApplicationRecord
def reject!
ModAction.log(:post_replacement_reject, {post_id: post.id, replacement_id: self.id})
update_attribute(:status, 'rejected')
UserStatus.for_user(creator_id).update_all("post_replacement_rejected_count = post_replacement_rejected_count + 1")
post.update_index
end
end
@ -233,6 +234,14 @@ class PostReplacement < ApplicationRecord
q = q.where(creator_id: User.name_to_id(params[:creator_name]))
end
if params[:uploader_id_on_approve].present?
q = q.where(uploader_id_on_approve: params[:uploader_id_on_approve].split(",").map(&:to_i))
end
if params[:uploader_name_on_approve].present?
q = q.where(uploader_id_on_approve: User.name_to_id(params[:uploader_name_on_approve]))
end
if params[:post_id].present?
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
end

View File

@ -579,7 +579,8 @@ class User < ApplicationRecord
def upload_limit_pieces
deleted_count = Post.deleted.for_user(id).count
rejected_replacement_count = PostReplacement.rejected.for_user(id).count
rejected_replacement_count = post_replacement_rejected_count
replaced_penalize_count = own_post_replaced_penalize_count
unapproved_count = Post.pending_or_flagged.for_user(id).count
unapproved_replacements_count = PostReplacement.pending.for_user(id).count
approved_count = Post.for_user(id).where('is_flagged = false AND is_deleted = false AND is_pending = false').count
@ -753,6 +754,18 @@ class User < ApplicationRecord
feedback.negative.count
end
def post_replacement_rejected_count
user_status.post_replacement_rejected_count
end
def own_post_replaced_count
user_status.own_post_replaced_count
end
def own_post_replaced_penalize_count
user_status.own_post_replaced_penalize_count
end
def refresh_counts!
self.class.without_timeout do
UserStatus.where(user_id: id).update_all(

View File

@ -78,6 +78,10 @@ class UserPresenter
template.link_to(user.post_deleted_count, template.deleted_posts_path(user_id: user.id))
end
def replaced_upload_count(template)
template.link_to(user.own_post_replaced_count, template.post_replacements_path(search: {uploader_name_on_approve: user.name}))
end
def favorite_count(template)
template.link_to(user.favorite_count, template.favorites_path(:user_id => user.id))
end

View File

@ -2,6 +2,7 @@
<%= f.input :md5, label: "MD5", input_html: { value: params.dig(:search, :md5) } %>
<%= f.input :creator_name, label: "Creator", input_html: { value: params.dig(:search, :creator_name) } %>
<%= f.input :post_id, label: "Post ID", input_html: { value: params.dig(:search, :post_id) } %>
<%= f.input :uploader_name_on_approve, label: "Uploader on Approve", input_html: { value: params.dig(:search, :uploader_name_on_approve) } %>
<%= f.input :status, label: "status", collection: ["pending", "rejected", "approved", "promoted"], include_blank: true, selected: params.dig(:search, :status) %>
<%= f.submit "Search" %>
<% end %>

View File

@ -84,7 +84,8 @@
<td>
<% if CurrentUser.is_janitor? %>
<%= link_to "Approve", approve_post_replacement_path(post_replacement), method: :PUT %><br>
<%= link_to "Approve and penalize uploader", approve_post_replacement_path(post_replacement, penalize_current_uploader: true), method: :PUT %><br>
<%= link_to "Approve", approve_post_replacement_path(post_replacement, penalize_current_uploader: false), method: :PUT %><br>
<%= link_to "Reject", reject_post_replacement_path(post_replacement), method: :PUT %><br>
<%= link_to "As New Post", promote_post_replacement_path(post_replacement), method: :PUT %><br>
<% end %>

View File

@ -51,12 +51,13 @@
</tr>
<tr>
<th>Deleted Posts</th>
<th>Deleted/Replaced Posts</th>
<td>
<%= presenter.deleted_upload_count(self) %>
<% if CurrentUser.is_moderator? %>
[<%= link_to "sample", posts_path(:tags => "user:#{user.name} order:random limit:300 status:deleted") %>]
<% end %>
/ <%= presenter.replaced_upload_count(self) %>
</td>
<th>Post Changes</th>
<td>

View File

@ -0,0 +1,18 @@
class AddReplacementAuditStats < ActiveRecord::Migration[6.1]
def up
add_column :post_replacements2, :uploader_id_on_approve, :int
add_column :post_replacements2, :penalize_uploader_on_approve, :boolean
add_column :user_statuses, :own_post_replaced_count, :int, nil: false, default: 0
add_column :user_statuses, :own_post_replaced_penalize_count, :int, nil: false, default: 0
add_column :user_statuses, :post_replacement_rejected_count, :int, nil: false, default: 0
end
def down
drop_column :post_replacements2, :uploader_id_on_approve
drop_column :post_replacements2, :penalize_uploader_on_approve
drop_column :user_statuses, :own_post_replaced_count
drop_column :user_statuses, :own_post_replaced_penalize_count
drop_column :user_statuses, :post_replacement_rejected_count
end
end

View File

@ -1638,7 +1638,9 @@ CREATE TABLE public.post_replacements2 (
storage_id character varying NOT NULL,
status character varying DEFAULT 'pending'::character varying NOT NULL,
reason character varying NOT NULL,
protected boolean DEFAULT false NOT NULL
protected boolean DEFAULT false NOT NULL,
uploader_id_on_approve integer,
penalize_uploader_on_approve boolean
);
@ -2588,7 +2590,10 @@ CREATE TABLE public.user_statuses (
pool_edit_count integer DEFAULT 0 NOT NULL,
blip_count integer DEFAULT 0 NOT NULL,
set_count integer DEFAULT 0 NOT NULL,
artist_edit_count integer DEFAULT 0 NOT NULL
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
);
@ -5263,6 +5268,6 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210426025625'),
('20210430201028'),
('20210506235640'),
('20210718172512');
('20210718172512'),
('20210625155528');