forked from e621ng/e621ng
[Posts] Log destroyed post information
This commit is contained in:
parent
c132d6a375
commit
01abcf5762
3
app/models/destroyed_post.rb
Normal file
3
app/models/destroyed_post.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class DestroyedPost < ApplicationRecord
|
||||
|
||||
end
|
@ -1472,12 +1472,43 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
module DeletionMethods
|
||||
def backup_post_data_destroy
|
||||
post_data = {
|
||||
id: id,
|
||||
description: description,
|
||||
md5: md5,
|
||||
tags: tag_string,
|
||||
height: image_height,
|
||||
width: image_width,
|
||||
file_size: file_size,
|
||||
sources: source,
|
||||
approver_id: approver_id,
|
||||
locked_tags: locked_tags,
|
||||
rating: rating,
|
||||
parent_id: parent_id,
|
||||
change_seq: change_seq,
|
||||
is_deleted: is_deleted,
|
||||
is_pending: is_pending,
|
||||
duration: duration,
|
||||
fav_count: fav_count,
|
||||
comment_count: comment_count
|
||||
}
|
||||
DestroyedPost.create!(post_id: id, post_data: post_data, md5: md5,
|
||||
uploader_ip_addr: uploader_ip_addr, uploader_id: uploader_id,
|
||||
destroyer_id: CurrentUser.id, destroyer_ip_addr: CurrentUser.ip_addr,
|
||||
upload_date: created_at)
|
||||
end
|
||||
|
||||
def expunge!
|
||||
if is_status_locked?
|
||||
self.errors.add(:is_status_locked, "; cannot delete post")
|
||||
return false
|
||||
end
|
||||
|
||||
transaction do
|
||||
backup_post_data_destroy
|
||||
end
|
||||
|
||||
transaction do
|
||||
Post.without_timeout do
|
||||
ModAction.log(:post_destroy, {post_id: id, md5: md5})
|
||||
|
15
db/migrate/20201113073842_create_destroyed_posts.rb
Normal file
15
db/migrate/20201113073842_create_destroyed_posts.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class CreateDestroyedPosts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :destroyed_posts do |t|
|
||||
t.integer :post_id, null: false
|
||||
t.string :md5, null: false
|
||||
t.integer :destroyer_id, null: false
|
||||
t.inet :destroyer_ip_addr, null: false
|
||||
t.integer :uploader_id
|
||||
t.inet :uploader_ip_addr
|
||||
t.timestamp :upload_date
|
||||
t.json :post_data, null: false
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -550,6 +550,44 @@ CREATE SEQUENCE public.comments_id_seq
|
||||
ALTER SEQUENCE public.comments_id_seq OWNED BY public.comments.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: destroyed_posts; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.destroyed_posts (
|
||||
id bigint NOT NULL,
|
||||
post_id integer NOT NULL,
|
||||
md5 character varying NOT NULL,
|
||||
destroyer_id integer NOT NULL,
|
||||
destroyer_ip_addr inet NOT NULL,
|
||||
uploader_id integer,
|
||||
uploader_ip_addr inet,
|
||||
upload_date timestamp without time zone,
|
||||
post_data json NOT NULL,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: destroyed_posts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.destroyed_posts_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: destroyed_posts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.destroyed_posts_id_seq OWNED BY public.destroyed_posts.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: dmail_filters; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
@ -2714,6 +2752,13 @@ ALTER TABLE ONLY public.comment_votes ALTER COLUMN id SET DEFAULT nextval('publi
|
||||
ALTER TABLE ONLY public.comments ALTER COLUMN id SET DEFAULT nextval('public.comments_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: destroyed_posts id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.destroyed_posts ALTER COLUMN id SET DEFAULT nextval('public.destroyed_posts_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: dmail_filters id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@ -3181,6 +3226,14 @@ ALTER TABLE ONLY public.comments
|
||||
ADD CONSTRAINT comments_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: destroyed_posts destroyed_posts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.destroyed_posts
|
||||
ADD CONSTRAINT destroyed_posts_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: dmail_filters dmail_filters_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@ -5082,6 +5135,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20200420032714'),
|
||||
('20200713053034'),
|
||||
('20200806101238'),
|
||||
('20200910015420');
|
||||
('20200910015420'),
|
||||
('20201113073842');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user