aliases/implications: add back legacy reason field.

In Danbooru 1, aliases (and implications) had a `reason` field where
either the admin or the alias requester gave a reason for the alias.
This field was removed from the code and the database schema, but it
still existed in the production database. This adds the field back, so
that the dev schema is consistent with the production schema, and so
that legacy reasons can be viewed on site again.

* Add back legacy tag_aliases.reason and tag_implications.reason field.
* Make /tag_aliases and /tag_implications show legacy reasons.
* Add the reason field to the search form.
This commit is contained in:
evazion
2021-01-06 15:53:08 -06:00
parent c5d109dd87
commit b223a87868
8 changed files with 40 additions and 20 deletions

View File

@@ -66,7 +66,7 @@ class TagRelationship < ApplicationRecord
end
def search(params)
q = search_attributes(params, :id, :created_at, :updated_at, :antecedent_name, :consequent_name, :creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki)
q = search_attributes(params, :id, :created_at, :updated_at, :antecedent_name, :consequent_name, :reason, :creator, :approver, :forum_post, :forum_topic, :antecedent_tag, :consequent_tag, :antecedent_wiki, :consequent_wiki)
if params[:name_matches].present?
q = q.name_matches(params[:name_matches])

View File

@@ -1,26 +1,31 @@
<%= table_for tag_aliases, width: "100%" do |t| %>
<% t.column "From", width: "25%" do |tag_alias| %>
<%= table_for tag_aliases, class: "striped autofit" do |t| %>
<% t.column "From", width: "30%" do |tag_alias| %>
<%= link_to tag_alias.antecedent_name, posts_path(tags: tag_alias.antecedent_name), class: tag_class(tag_alias.antecedent_tag) %>
<%= link_to "»", tag_aliases_path(search: { antecedent_name_ilike: tag_alias.antecedent_name }) %>
<span class="count"><%= tag_alias.antecedent_tag&.post_count.to_i %></span>
<% end %>
<% t.column "To", width: "25%" do |tag_alias| %>
<% t.column "To", td: { class: "col-expand" } do |tag_alias| %>
<%= link_to tag_alias.consequent_name, posts_path(tags: tag_alias.consequent_name), class: tag_class(tag_alias.consequent_tag) %>
<%= link_to "»", tag_aliases_path(search: { consequent_name_ilike: tag_alias.consequent_name }) %>
<span class="count"><%= tag_alias.consequent_tag&.post_count.to_i %></span>
<% end %>
<% t.column "Topic", width: "10%" do |tag_alias| %>
<% t.column "Reason" do |tag_alias| %>
<span class="prose">
<%= format_text(tag_alias.reason, inline: true) %>
</span>
<% end %>
<% t.column "Topic" do |tag_alias| %>
<% if tag_alias.forum_topic_id %>
<%= link_to "topic ##{tag_alias.forum_topic_id}", forum_topic_path(tag_alias.forum_topic_id) %>
<% end %>
<% end %>
<% t.column "Approver", width: "15%" do |tag_alias| %>
<% t.column "Approver" do |tag_alias| %>
<%= link_to_user(tag_alias.approver) if tag_alias.approver %>
<% end %>
<% t.column "Status", width: "5%" do |tag_alias| %>
<% t.column "Status" do |tag_alias| %>
<span id="tag-alias-status-for-<%= tag_alias.id %>"><%= tag_alias.status %></span>
<% end %>
<% t.column column: "control", width: "15%" do |tag_alias| %>
<% t.column column: "control" do |tag_alias| %>
<%= link_to "Show", tag_alias_path(tag_alias) %>
<% if policy(tag_alias).destroy? %>

View File

@@ -10,7 +10,7 @@
<% end %>
<li><strong>Creator</strong> <%= link_to_user @tag_alias.creator %></li>
<li><strong>Date</strong> <%= @tag_alias.created_at %></li>
<% if @tag_alias.respond_to?(:reason) && @tag_alias.reason.present? %>
<% if @tag_alias.reason.present? %>
<li>
<strong>Reason</strong>
<div class="prose">

View File

@@ -1,26 +1,31 @@
<%= table_for tag_implications, width: "100%" do |t| %>
<% t.column "From", width: "25%" do |tag_implication| %>
<%= table_for tag_implications, class: "striped autofit" do |t| %>
<% t.column "From", width: "30%" do |tag_implication| %>
<%= link_to tag_implication.antecedent_name, posts_path(tags: tag_implication.antecedent_name), class: tag_class(tag_implication.antecedent_tag) %>
<%= link_to "»", tag_implications_path(search: { implied_from: tag_implication.antecedent_name }) %>
<span class="count"><%= tag_implication.antecedent_tag&.post_count.to_i %></span>
<% end %>
<% t.column "To", width: "25%" do |tag_implication| %>
<% t.column "To", td: { class: "col-expand" } do |tag_implication| %>
<%= link_to tag_implication.consequent_name, posts_path(tags: tag_implication.consequent_name), class: tag_class(tag_implication.consequent_tag) %>
<%= link_to "»", tag_implications_path(search: { implied_to: tag_implication.consequent_name }) %>
<span class="count"><%= tag_implication.consequent_tag&.post_count.to_i %></span>
<% end %>
<% t.column "Topic", width: "10%" do |tag_implication| %>
<% t.column "Reason" do |tag_implication| %>
<span class="prose">
<%= format_text(tag_implication.reason, inline: true) %>
</span>
<% end %>
<% t.column "Topic" do |tag_implication| %>
<% if tag_implication.forum_topic_id %>
<%= link_to "topic ##{tag_implication.forum_topic_id}", forum_topic_path(tag_implication.forum_topic_id) %>
<% end %>
<% end %>
<% t.column "Approver", width: "15%" do |tag_implication| %>
<% t.column "Approver" do |tag_implication| %>
<%= link_to_user(tag_implication.approver) if tag_implication.approver %>
<% end %>
<% t.column "Status", width: "5%" do |tag_implication| %>
<% t.column "Status" do |tag_implication| %>
<span id="tag-implication-status-for-<%= tag_implication.id %>"><%= tag_implication.status %></span>
<% end %>
<% t.column column: "control", width: "15%" do |tag_implication| %>
<% t.column column: "control" do |tag_implication| %>
<%= link_to "Show", tag_implication_path(tag_implication) %>
<% if policy(tag_implication).destroy? %>

View File

@@ -10,7 +10,7 @@
<% end %>
<li><strong>Creator</strong> <%= link_to_user @tag_implication.creator %></li>
<li><strong>Date</strong> <%= @tag_implication.created_at %></li>
<% if @tag_implication.respond_to?(:reason) && @tag_implication.reason.present? %>
<% if @tag_implication.reason.present? %>
<li>
<strong>Reason</strong>
<div class="prose">

View File

@@ -3,6 +3,7 @@
<%= search_form_for(url) do |f| %>
<%= f.input :antecedent_name_ilike, label: "From", input_html: { value: params[:search][:antecedent_name_ilike], data: { autocomplete: "tag" } } %>
<%= f.input :consequent_name_ilike, label: "To", input_html: { value: params[:search][:consequent_name_ilike], data: { autocomplete: "tag" } } %>
<%= f.input :reason_ilike, label: "Reason", input_html: { value: params[:search][:reason_ilike] } %>
<%= f.simple_fields_for :antecedent_tag do |fa| %>
<%= fa.input :category, label: "From Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true, selected: params.dig(:search, :antecedent_tag, :category) %>
<% end %>

View File

@@ -0,0 +1,6 @@
class AddReasonToTagAliasesAndImplications < ActiveRecord::Migration[6.1]
def change
add_column :tag_aliases, :reason, :text, null: false, default: "", if_not_exists: true
add_column :tag_implications, :reason, :text, null: false, default: "", if_not_exists: true
end
end

View File

@@ -2876,7 +2876,8 @@ CREATE TABLE public.tag_aliases (
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
approver_id integer,
forum_post_id integer
forum_post_id integer,
reason text DEFAULT ''::text NOT NULL
);
@@ -2913,7 +2914,8 @@ CREATE TABLE public.tag_implications (
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
approver_id integer,
forum_post_id integer
forum_post_id integer,
reason text DEFAULT ''::text NOT NULL
);
@@ -7523,6 +7525,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20201201211748'),
('20201213052805'),
('20201219201007'),
('20201224101208');
('20201224101208'),
('20210106212805');