forked from e621ng/e621ng
fixes #2716: Wiki pages should be undeletable
This commit is contained in:
parent
2a5343b8cf
commit
e78b7d2a8c
@ -336,9 +336,9 @@ GEM
|
||||
faraday (~> 0.9)
|
||||
jwt (~> 1.5)
|
||||
multi_json (~> 1.10)
|
||||
simple_form (3.1.0)
|
||||
actionpack (~> 4.0)
|
||||
activemodel (~> 4.0)
|
||||
simple_form (3.3.1)
|
||||
actionpack (> 4, < 5.1)
|
||||
activemodel (> 4, < 5.1)
|
||||
simple_oauth (0.3.1)
|
||||
simplecov (0.10.0)
|
||||
docile (~> 1.1.0)
|
||||
|
@ -5,6 +5,7 @@ form.simple_form {
|
||||
label {
|
||||
display: inline;
|
||||
vertical-align: middle;
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
class WikiPagesController < ApplicationController
|
||||
respond_to :html, :xml, :json, :js
|
||||
before_filter :member_only, :except => [:index, :show, :show_or_new]
|
||||
before_filter :moderator_only, :only => [:destroy]
|
||||
before_filter :builder_only, :only => [:destroy]
|
||||
before_filter :normalize_search_params, :only => [:index]
|
||||
rescue_from ActiveRecord::StatementInvalid, :with => :rescue_exception
|
||||
rescue_from ActiveRecord::RecordNotFound, :with => :rescue_exception
|
||||
@ -61,7 +61,7 @@ class WikiPagesController < ApplicationController
|
||||
|
||||
def destroy
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
@wiki_page.destroy
|
||||
@wiki_page.update_attribute(:is_deleted, true)
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
|
@ -6,14 +6,13 @@ class WikiPage < ActiveRecord::Base
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
after_save :create_version
|
||||
before_destroy :create_mod_action_for_destroy
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
validates_uniqueness_of :title, :case_sensitive => false
|
||||
validates_presence_of :title
|
||||
validate :validate_locker_is_moderator
|
||||
validate :validate_locker_is_builder
|
||||
validate :validate_not_locked
|
||||
attr_accessible :title, :body, :is_locked, :other_names
|
||||
attr_accessible :title, :body, :is_locked, :is_deleted, :other_names
|
||||
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
||||
has_one :artist, lambda {where(:is_active => true)}, :foreign_key => "name", :primary_key => "title"
|
||||
has_many :versions, lambda {order("wiki_page_versions.id ASC")}, :class_name => "WikiPageVersion", :dependent => :destroy
|
||||
@ -23,6 +22,10 @@ class WikiPage < ActiveRecord::Base
|
||||
where("title = ?", title.mb_chars.downcase.tr(" ", "_"))
|
||||
end
|
||||
|
||||
def active
|
||||
where("is_deleted = false")
|
||||
end
|
||||
|
||||
def recent
|
||||
order("updated_at DESC").limit(25)
|
||||
end
|
||||
@ -65,6 +68,10 @@ class WikiPage < ActiveRecord::Base
|
||||
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].tr(" ", "_").mb_chars.downcase)
|
||||
end
|
||||
|
||||
if params[:hide_deleted] =~ /y/i
|
||||
q = q.where("is_deleted = false")
|
||||
end
|
||||
|
||||
if params[:other_names_present] == "yes"
|
||||
q = q.where("other_names is not null and other_names != ''")
|
||||
elsif params[:other_names_present] == "no"
|
||||
@ -114,15 +121,15 @@ class WikiPage < ActiveRecord::Base
|
||||
titled(title).select("title, id").first
|
||||
end
|
||||
|
||||
def validate_locker_is_moderator
|
||||
if is_locked_changed? && !CurrentUser.is_moderator?
|
||||
errors.add(:is_locked, "can be modified by moderators only")
|
||||
def validate_locker_is_builder
|
||||
if is_locked_changed? && !CurrentUser.is_builder?
|
||||
errors.add(:is_locked, "can be modified by builders only")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def validate_not_locked
|
||||
if is_locked? && !CurrentUser.is_moderator?
|
||||
if is_locked? && !CurrentUser.is_builder?
|
||||
errors.add(:is_locked, "and cannot be updated")
|
||||
return false
|
||||
end
|
||||
@ -187,12 +194,13 @@ class WikiPage < ActiveRecord::Base
|
||||
:title => title,
|
||||
:body => body,
|
||||
:is_locked => is_locked,
|
||||
:is_deleted => is_deleted,
|
||||
:other_names => other_names
|
||||
)
|
||||
end
|
||||
|
||||
def create_version
|
||||
if title_changed? || body_changed? || is_locked_changed? || other_names_changed?
|
||||
if title_changed? || body_changed? || is_locked_changed? || is_deleted_changed? || other_names_changed?
|
||||
if merge_version?
|
||||
merge_version
|
||||
else
|
||||
@ -231,12 +239,8 @@ class WikiPage < ActiveRecord::Base
|
||||
end.map {|x| x.mb_chars.downcase.tr(" ", "_").to_s}
|
||||
end
|
||||
|
||||
def create_mod_action_for_destroy
|
||||
ModAction.create(:description => "permanently deleted wiki page [[#{title}]]")
|
||||
end
|
||||
|
||||
def visible?
|
||||
artist.blank? || !artist.is_banned? || CurrentUser.is_moderator?
|
||||
artist.blank? || !artist.is_banned? || CurrentUser.is_builder?
|
||||
end
|
||||
|
||||
def other_names_array
|
||||
|
@ -41,7 +41,7 @@ class WikiPageVersion < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def visible?
|
||||
artist.blank? || !artist.is_banned? || CurrentUser.is_moderator?
|
||||
artist.blank? || !artist.is_banned? || CurrentUser.is_builder?
|
||||
end
|
||||
|
||||
def other_names_array
|
||||
|
@ -15,6 +15,7 @@
|
||||
<th width="2%"></th>
|
||||
<% end %>
|
||||
<th>Title</th>
|
||||
<th width="3%">Del</th>
|
||||
<th width="5%"></th>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<th width="10%">IP Address</th>
|
||||
@ -49,6 +50,7 @@
|
||||
</td>
|
||||
<% end %>
|
||||
<td class="category-<%= wiki_page_version.category_name %>"><%= 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>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<td>
|
||||
|
@ -18,8 +18,12 @@
|
||||
|
||||
<%= dtext_field "wiki_page", "body" %>
|
||||
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<%= f.input :is_locked %>
|
||||
<% if CurrentUser.is_builder? && @wiki_page.is_deleted? %>
|
||||
<%= f.input :is_deleted, :label => "Deleted", :hint => "Uncheck to restore this wiki page" %>
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.is_builder? %>
|
||||
<%= f.input :is_locked, :label => "Locked" %>
|
||||
<% end %>
|
||||
|
||||
<%= f.button :submit, "Submit", :data => { :disable_with => "Submitting..." } %>
|
||||
|
@ -18,7 +18,7 @@
|
||||
<% if CurrentUser.is_member? %>
|
||||
<li><%= link_to "Edit", edit_wiki_page_path(@wiki_page), :id => "wiki-page-edit-link" %></li>
|
||||
<% end %>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<% if CurrentUser.is_builder? && !@wiki_page.is_deleted? %>
|
||||
<li><%= link_to "Delete", wiki_page_path(@wiki_page), :remote => true, :method => :delete, :data => {:confirm => "Are you sure you want to delete this wiki page?"} %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
@ -16,6 +16,11 @@
|
||||
<%= select "search", "order", ["Name", "Date"] %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<label for="search_hide_deleted">Hide Deleted</label>
|
||||
<%= select "search", "hide_deleted", ["Yes", "No"] %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
@ -10,6 +10,10 @@
|
||||
<% if @wiki_page.is_locked? %>
|
||||
(locked)
|
||||
<% end %>
|
||||
|
||||
<% if @wiki_page.is_deleted? %>
|
||||
(deleted)
|
||||
<% end %>
|
||||
</h1>
|
||||
|
||||
<div id="wiki-page-body" class="prose">
|
||||
|
@ -0,0 +1,7 @@
|
||||
class AddIsDeletedToWikiPages < ActiveRecord::Migration
|
||||
def change
|
||||
execute "set statement_timeout = 0"
|
||||
add_column :wiki_pages, :is_deleted, :boolean, :null => false, :default => false
|
||||
add_column :wiki_page_versions, :is_deleted, :boolean, :null => false, :default => false
|
||||
end
|
||||
end
|
@ -3305,7 +3305,8 @@ CREATE TABLE wiki_page_versions (
|
||||
is_locked boolean NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
other_names text
|
||||
other_names text,
|
||||
is_deleted boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@ -3343,7 +3344,8 @@ CREATE TABLE wiki_pages (
|
||||
updated_at timestamp without time zone,
|
||||
updater_id integer,
|
||||
other_names text,
|
||||
other_names_index tsvector
|
||||
other_names_index tsvector,
|
||||
is_deleted boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@ -7452,3 +7454,5 @@ INSERT INTO schema_migrations (version) VALUES ('20160822230752');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20160919234407');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20161018221128');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user