From 32f026648173c7ac9d9ecb061e10083d0614918f Mon Sep 17 00:00:00 2001 From: Kira Date: Fri, 15 Nov 2019 20:00:54 -0800 Subject: [PATCH] Add wiki edit reason --- app/controllers/wiki_pages_controller.rb | 2 +- app/models/wiki_page.rb | 27 +++---------------- .../wiki_page_versions/_page_listing.html.erb | 8 +++--- app/views/wiki_pages/_form.html.erb | 2 ++ .../20191116032230_add_wiki_edit_reason.rb | 5 ++++ db/structure.sql | 6 +++-- 6 files changed, 21 insertions(+), 29 deletions(-) create mode 100644 db/migrate/20191116032230_add_wiki_edit_reason.rb diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index 4419407bf..7b0169c13 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -108,7 +108,7 @@ class WikiPagesController < ApplicationController end def wiki_page_params(context) - permitted_params = %i[body other_names other_names_string skip_secondary_validations] + permitted_params = %i[body other_names other_names_string skip_secondary_validations edit_reason] permitted_params += %i[is_locked is_deleted] if CurrentUser.is_janitor? permitted_params += %i[title] if context == :create || CurrentUser.is_janitor? diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 5dd4c4345..23842f25e 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -15,7 +15,7 @@ class WikiPage < ApplicationRecord before_save :log_changes - attr_accessor :skip_secondary_validations + attr_accessor :skip_secondary_validations, :edit_reason array_attribute :other_names belongs_to_creator belongs_to_updater @@ -202,22 +202,6 @@ class WikiPage < ApplicationRecord saved_change_to_title? || saved_change_to_body? || saved_change_to_is_locked? || saved_change_to_is_deleted? || saved_change_to_other_names? end - def merge_version - prev = versions.last - prev.update( - :title => title, - :body => body, - :is_locked => is_locked, - :is_deleted => is_deleted, - :other_names => other_names - ) - end - - def merge_version? - prev = versions.last - prev && prev.updater_id == CurrentUser.user.id && prev.updated_at > 1.hour.ago - end - def create_new_version versions.create( :updater_id => CurrentUser.user.id, @@ -226,17 +210,14 @@ class WikiPage < ApplicationRecord :body => body, :is_locked => is_locked, :is_deleted => is_deleted, - :other_names => other_names + :other_names => other_names, + reason: edit_reason ) end def create_version if wiki_page_changed? - if merge_version? - merge_version - else - create_new_version - end + create_new_version end end diff --git a/app/views/wiki_page_versions/_page_listing.html.erb b/app/views/wiki_page_versions/_page_listing.html.erb index 332286a81..12792bd19 100644 --- a/app/views/wiki_page_versions/_page_listing.html.erb +++ b/app/views/wiki_page_versions/_page_listing.html.erb @@ -8,12 +8,13 @@ Title - Del - + Deleted + View <% if CurrentUser.is_moderator? %> IP Address <% end %> Last edited + Reason @@ -33,7 +34,7 @@ <%= link_to wiki_page_version.title, wiki_page_version_path(wiki_page_version) %> <%= wiki_page_version.is_deleted? ? "Y" : "" %> - <%= link_to "wiki", wiki_page_path(wiki_page_version.wiki_page_id) %> + <%= link_to "view version", wiki_page_path(wiki_page_version.wiki_page_id) %> <% if CurrentUser.is_moderator? %> <%= link_to_ip wiki_page_version.updater_ip_addr %> @@ -46,6 +47,7 @@ <%= link_to_user wiki_page_version.updater %> <% end %> + <%= wiki_page_version.reason %> <% end %> diff --git a/app/views/wiki_pages/_form.html.erb b/app/views/wiki_pages/_form.html.erb index 424ab7d5b..6dac74ef3 100644 --- a/app/views/wiki_pages/_form.html.erb +++ b/app/views/wiki_pages/_form.html.erb @@ -22,6 +22,8 @@ <%= f.input :is_locked, :label => "Locked" %> <% end %> + <%= f.input :edit_reason, label: "Edit Reason" %> + <% if @wiki_page.errors[:title].present? %> <%= f.input :skip_secondary_validations, as: :boolean, label: "Force rename", hint: "Ignore the renaming requirements" %> <% end %> diff --git a/db/migrate/20191116032230_add_wiki_edit_reason.rb b/db/migrate/20191116032230_add_wiki_edit_reason.rb new file mode 100644 index 000000000..12a623bad --- /dev/null +++ b/db/migrate/20191116032230_add_wiki_edit_reason.rb @@ -0,0 +1,5 @@ +class AddWikiEditReason < ActiveRecord::Migration[6.0] + def change + add_column :wiki_page_versions, :reason, :string, null: true + end +end diff --git a/db/structure.sql b/db/structure.sql index 5de87987d..aa17d5ff8 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2752,7 +2752,8 @@ CREATE TABLE public.wiki_page_versions ( created_at timestamp without time zone, updated_at timestamp without time zone, other_names text[] DEFAULT '{}'::text[] NOT NULL, - is_deleted boolean DEFAULT false NOT NULL + is_deleted boolean DEFAULT false NOT NULL, + reason character varying ); @@ -5334,6 +5335,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191003070653'), ('20191006073950'), ('20191006143246'), -('20191013233447'); +('20191013233447'), +('20191116032230');