From b223a87868fa9a35745eb02f797fec94bb492a2d Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 6 Jan 2021 15:53:08 -0600 Subject: [PATCH] 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. --- app/models/tag_relationship.rb | 2 +- app/views/tag_aliases/_listing.html.erb | 19 ++++++++++++------- app/views/tag_aliases/show.html.erb | 2 +- app/views/tag_implications/_listing.html.erb | 19 ++++++++++++------- app/views/tag_implications/show.html.erb | 2 +- app/views/tag_relationships/_search.html.erb | 1 + ..._reason_to_tag_aliases_and_implications.rb | 6 ++++++ db/structure.sql | 9 ++++++--- 8 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 db/migrate/20210106212805_add_reason_to_tag_aliases_and_implications.rb diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index 28e6bacb1..dd6878ebc 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -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]) diff --git a/app/views/tag_aliases/_listing.html.erb b/app/views/tag_aliases/_listing.html.erb index 277f1fbad..84c67e31e 100644 --- a/app/views/tag_aliases/_listing.html.erb +++ b/app/views/tag_aliases/_listing.html.erb @@ -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 }) %> <%= tag_alias.antecedent_tag&.post_count.to_i %> <% 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 }) %> <%= tag_alias.consequent_tag&.post_count.to_i %> <% end %> - <% t.column "Topic", width: "10%" do |tag_alias| %> + <% t.column "Reason" do |tag_alias| %> + + <%= format_text(tag_alias.reason, inline: true) %> + + <% 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| %> <%= tag_alias.status %> <% 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? %> diff --git a/app/views/tag_aliases/show.html.erb b/app/views/tag_aliases/show.html.erb index 2c4f194d3..25e6f4e0f 100644 --- a/app/views/tag_aliases/show.html.erb +++ b/app/views/tag_aliases/show.html.erb @@ -10,7 +10,7 @@ <% end %>
  • Creator <%= link_to_user @tag_alias.creator %>
  • Date <%= @tag_alias.created_at %>
  • - <% if @tag_alias.respond_to?(:reason) && @tag_alias.reason.present? %> + <% if @tag_alias.reason.present? %>
  • Reason
    diff --git a/app/views/tag_implications/_listing.html.erb b/app/views/tag_implications/_listing.html.erb index 48952f928..e4aef9f01 100644 --- a/app/views/tag_implications/_listing.html.erb +++ b/app/views/tag_implications/_listing.html.erb @@ -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 }) %> <%= tag_implication.antecedent_tag&.post_count.to_i %> <% 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 }) %> <%= tag_implication.consequent_tag&.post_count.to_i %> <% end %> - <% t.column "Topic", width: "10%" do |tag_implication| %> + <% t.column "Reason" do |tag_implication| %> + + <%= format_text(tag_implication.reason, inline: true) %> + + <% 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| %> <%= tag_implication.status %> <% 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? %> diff --git a/app/views/tag_implications/show.html.erb b/app/views/tag_implications/show.html.erb index bcd28565f..1f4bdffbc 100644 --- a/app/views/tag_implications/show.html.erb +++ b/app/views/tag_implications/show.html.erb @@ -10,7 +10,7 @@ <% end %>
  • Creator <%= link_to_user @tag_implication.creator %>
  • Date <%= @tag_implication.created_at %>
  • - <% if @tag_implication.respond_to?(:reason) && @tag_implication.reason.present? %> + <% if @tag_implication.reason.present? %>
  • Reason
    diff --git a/app/views/tag_relationships/_search.html.erb b/app/views/tag_relationships/_search.html.erb index 21f2bb4cc..7568fc065 100644 --- a/app/views/tag_relationships/_search.html.erb +++ b/app/views/tag_relationships/_search.html.erb @@ -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 %> diff --git a/db/migrate/20210106212805_add_reason_to_tag_aliases_and_implications.rb b/db/migrate/20210106212805_add_reason_to_tag_aliases_and_implications.rb new file mode 100644 index 000000000..f316f6cc3 --- /dev/null +++ b/db/migrate/20210106212805_add_reason_to_tag_aliases_and_implications.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index f57281afa..2d978ad70 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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');