forked from e621ng/e621ng
Add wiki edit reason
This commit is contained in:
parent
598e862e6d
commit
32f0266481
@ -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?
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -8,12 +8,13 @@
|
||||
<th width="2%"></th>
|
||||
|
||||
<th>Title</th>
|
||||
<th width="3%">Del</th>
|
||||
<th width="5%"></th>
|
||||
<th width="3%">Deleted</th>
|
||||
<th width="5%">View</th>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<th width="10%">IP Address</th>
|
||||
<% end %>
|
||||
<th width="26%">Last edited</th>
|
||||
<th>Reason</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -33,7 +34,7 @@
|
||||
<%= link_to wiki_page_version.title, wiki_page_version_path(wiki_page_version) %>
|
||||
</td>
|
||||
<td><%= wiki_page_version.is_deleted? ? "Y" : "" %></td>
|
||||
<td><%= link_to "wiki", wiki_page_path(wiki_page_version.wiki_page_id) %></td>
|
||||
<td><%= link_to "view version", wiki_page_path(wiki_page_version.wiki_page_id) %></td>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<td>
|
||||
<%= link_to_ip wiki_page_version.updater_ip_addr %>
|
||||
@ -46,6 +47,7 @@
|
||||
<%= link_to_user wiki_page_version.updater %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= wiki_page_version.reason %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
@ -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 %>
|
||||
|
5
db/migrate/20191116032230_add_wiki_edit_reason.rb
Normal file
5
db/migrate/20191116032230_add_wiki_edit_reason.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddWikiEditReason < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :wiki_page_versions, :reason, :string, null: true
|
||||
end
|
||||
end
|
@ -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');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user