wiki pages: allow members to rename, delete, and undelete wikis.

This commit is contained in:
evazion
2019-12-16 18:44:34 -06:00
parent be9bdc0ab3
commit ddf928515c
4 changed files with 12 additions and 25 deletions

View File

@@ -1,7 +1,6 @@
class WikiPagesController < ApplicationController
respond_to :html, :xml, :json, :js
before_action :member_only, :except => [:index, :search, :show, :show_or_new]
before_action :builder_only, :only => [:destroy]
before_action :normalize_search_params, :only => [:index]
layout "sidebar"
@@ -89,9 +88,8 @@ class WikiPagesController < ApplicationController
end
def wiki_page_params(context)
permitted_params = %i[body other_names other_names_string]
permitted_params += %i[is_locked is_deleted] if CurrentUser.is_builder?
permitted_params += %i[title] if context == :create || CurrentUser.is_builder?
permitted_params = %i[title body other_names other_names_string is_deleted]
permitted_params += %i[is_locked] if CurrentUser.is_builder?
params.fetch(:wiki_page, {}).permit(permitted_params)
end

View File

@@ -2,23 +2,16 @@
<%= error_messages_for("wiki_page") %>
<%= simple_form_for(@wiki_page, url: wiki_page_path(@wiki_page.id)) do |f| %>
<% if CurrentUser.is_builder? %>
<%= f.input :title, error: false, input_html: { data: { autocomplete: "tag" } }, hint: "Change to rename this wiki page. Move the tag and update any wikis linking to this page first." %>
<% else %>
<h1 id="wiki-page-title"><%= @wiki_page.pretty_title %></h1>
<% end %>
<%= f.input :title, error: false, input_html: { data: { autocomplete: "tag" } }, hint: "Change to rename this wiki page. Update any wikis linking to this page first." %>
<%= f.input :other_names_string, as: :text, input_html: { size: "30x1" }, label: "Other names (#{link_to_wiki "help", "help:translated_tags"})".html_safe, hint: "Names used for this tag on other sites such as Pixiv. Separate with spaces." %>
<%= dtext_field "wiki_page", "body" %>
<% if CurrentUser.is_builder? && @wiki_page.is_deleted? %>
<%= f.input :is_deleted, :label => "Deleted", :hint => "Uncheck to restore this wiki page" %>
<% if CurrentUser.is_builder? %>
<%= f.input :is_locked, label: "Locked", hint: "Locked wikis can only be edited by Builders." %>
<% end %>
<% if CurrentUser.is_builder? %>
<%= f.input :is_locked, :label => "Locked" %>
<% end %>
<%= f.input :is_deleted, label: "Deleted", hint: "Check to mark this wiki page as deleted." %>
<%= f.submit "Submit" %>
<%= dtext_preview_button "wiki_page", "body" %>

View File

@@ -15,11 +15,12 @@
<%= subnav_link_to "History", wiki_page_versions_path(:search => {:wiki_page_id => @wiki_page.id}) %>
<% if CurrentUser.is_member? %>
<%= subnav_link_to "Edit", edit_wiki_page_path(@wiki_page.id), "data-shortcut": "e" %>
<% end %>
<% if CurrentUser.is_builder? && @wiki_page.is_deleted? %>
<%= subnav_link_to "Undelete", wiki_page_path(@wiki_page.id), remote: true, method: :put, "data-params": "wiki_page[is_deleted]=false", "data-shortcut": "shift+d" %>
<% elsif CurrentUser.is_builder? && !@wiki_page.is_deleted? %>
<%= subnav_link_to "Delete", wiki_page_path(@wiki_page.id), remote: true, method: :put, "data-params": "wiki_page[is_deleted]=true", "data-shortcut": "shift+d" %>
<% if @wiki_page.is_deleted? %>
<%= subnav_link_to "Undelete", wiki_page_path(@wiki_page.id), remote: true, method: :put, "data-params": "wiki_page[is_deleted]=false", "data-shortcut": "shift+d" %>
<% else %>
<%= subnav_link_to "Delete", wiki_page_path(@wiki_page.id), remote: true, method: :put, "data-params": "wiki_page[is_deleted]=true", "data-shortcut": "shift+d" %>
<% end %>
<% end %>
<% elsif @wiki_page_version %>
<li>|</li>

View File

@@ -168,11 +168,6 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
put_auth wiki_page_path(@wiki_page), @mod, params: { wiki_page: { title: "bar" }}
assert_match(/still has 42 posts/, flash[:notice])
end
should "not allow non-Builders to delete wiki pages" do
put_auth wiki_page_path(@wiki_page), @user, params: {wiki_page: { is_deleted: true }}
assert_equal(false, @wiki_page.reload.is_deleted?)
end
end
context "destroy action" do