From 6446c312beab7e23162827a79bd9ab6f9e4d7958 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 25 May 2007 16:44:50 +0000 Subject: [PATCH] Added the ability to destroy wiki pages (content and its history are deleted from the database). This permission has to be explicitly given (Roles & Permissions -> Wiki pages/Delete). git-svn-id: http://redmine.rubyforge.org/svn/trunk@540 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/wiki_controller.rb | 12 +++++++++++- app/models/permission.rb | 1 + app/views/wiki/show.rhtml | 1 + db/migrate/049_add_wiki_destroy_page_permission.rb | 9 +++++++++ lang/bg.yml | 1 + lang/de.yml | 1 + lang/en.yml | 1 + lang/es.yml | 1 + lang/fr.yml | 1 + lang/it.yml | 1 + lang/ja.yml | 1 + lang/nl.yml | 1 + lang/pt-br.yml | 1 + lang/pt.yml | 1 + lang/zh.yml | 1 + test/unit/wiki_page_test.rb | 11 ++++++++++- 16 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 db/migrate/049_add_wiki_destroy_page_permission.rb diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 9e750b3a6..f68b71ecc 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -18,7 +18,10 @@ class WikiController < ApplicationController layout 'base' before_filter :find_wiki, :check_project_privacy, :except => [:preview] - + before_filter :authorize, :only => :destroy + + verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index } + # display a page (in editing mode if it doesn't exist) def index page_title = params[:page] @@ -72,6 +75,13 @@ class WikiController < ApplicationController :select => "id, author_id, comments, updated_on, version", :order => 'version DESC' end + + # remove a wiki page and its history + def destroy + @page = @wiki.find_page(params[:page]) + @page.destroy if @page + redirect_to :action => 'special', :id => @project, :page => 'Page_index' + end # display special pages def special diff --git a/app/models/permission.rb b/app/models/permission.rb index f78118d86..bea670c4c 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -32,6 +32,7 @@ class Permission < ActiveRecord::Base 1300 => :label_attachment_plural, 1400 => :label_repository, 1500 => :label_time_tracking, + 1700 => :label_wiki_page_plural, 2000 => :label_board_plural }.freeze diff --git a/app/views/wiki/show.rhtml b/app/views/wiki/show.rhtml index a65b1a61e..c2deba02b 100644 --- a/app/views/wiki/show.rhtml +++ b/app/views/wiki/show.rhtml @@ -1,5 +1,6 @@
<%= link_to(l(:button_edit), {:action => 'edit', :page => @page.title}, :class => 'icon icon-edit') if @content.version == @page.content.version %> +<%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :page => @page.title}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> <%= link_to(l(:button_rollback), {:action => 'edit', :page => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %> <%= link_to(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %> <%= link_to(l(:label_page_index), {:action => 'special', :page => 'Page_index'}, :class => 'icon icon-index') %> diff --git a/db/migrate/049_add_wiki_destroy_page_permission.rb b/db/migrate/049_add_wiki_destroy_page_permission.rb new file mode 100644 index 000000000..c68370f22 --- /dev/null +++ b/db/migrate/049_add_wiki_destroy_page_permission.rb @@ -0,0 +1,9 @@ +class AddWikiDestroyPagePermission < ActiveRecord::Migration + def self.up + Permission.create :controller => 'wiki', :action => 'destroy', :description => 'button_delete', :sort => 1740, :is_public => false, :mail_option => 0, :mail_enabled => 0 + end + + def self.down + Permission.find_by_controller_and_action('wiki', 'destroy').destroy + end +end diff --git a/lang/bg.yml b/lang/bg.yml index 912074400..47ade6312 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -346,6 +346,7 @@ label_all_words: Всички думи label_wiki: Wiki label_wiki_edit: Wiki редакция label_wiki_edit_plural: Wiki редакции +label_wiki_page_plural: Wiki pages label_page_index: Индекс label_current_version: Текуща версия label_preview: Преглед diff --git a/lang/de.yml b/lang/de.yml index b74aa5c69..3fc39dad5 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -346,6 +346,7 @@ label_all_words: Alle Wörter label_wiki: Wiki label_wiki_edit: Wiki Bearbeitung label_wiki_edit_plural: Wiki Bearbeitungen +label_wiki_page_plural: Wiki pages label_page_index: Index label_current_version: Gegenwärtige Version label_preview: Vorschau diff --git a/lang/en.yml b/lang/en.yml index 586fc8b09..9cc452d8f 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -346,6 +346,7 @@ label_all_words: All words label_wiki: Wiki label_wiki_edit: Wiki edit label_wiki_edit_plural: Wiki edits +label_wiki_page_plural: Wiki pages label_page_index: Index label_current_version: Current version label_preview: Preview diff --git a/lang/es.yml b/lang/es.yml index 2a0b3599c..523754c3d 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -346,6 +346,7 @@ label_all_words: Todas las palabras label_wiki: Wiki label_wiki_edit: Wiki edit label_wiki_edit_plural: Wiki edits +label_wiki_page_plural: Wiki pages label_page_index: Índice label_current_version: Versión actual label_preview: Previo diff --git a/lang/fr.yml b/lang/fr.yml index 35ec97b36..35812bc7f 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -346,6 +346,7 @@ label_all_words: Tous les mots label_wiki: Wiki label_wiki_edit: Révision wiki label_wiki_edit_plural: Révisions wiki +label_wiki_page_plural: Pages wiki label_page_index: Index label_current_version: Version actuelle label_preview: Prévisualisation diff --git a/lang/it.yml b/lang/it.yml index 91eaae6e3..77a12162a 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -346,6 +346,7 @@ label_all_words: Tutte le parole label_wiki: Wiki label_wiki_edit: Modifica Wiki label_wiki_edit_plural: Modfiche wiki +label_wiki_page_plural: Wiki pages label_page_index: Indice label_current_version: Versione corrente label_preview: Anteprima diff --git a/lang/ja.yml b/lang/ja.yml index 2c205bee8..357777d3b 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -347,6 +347,7 @@ label_all_words: すべての単語 label_wiki: Wiki label_wiki_edit: Wiki編集 label_wiki_edit_plural: Wiki編集 +label_wiki_page_plural: Wiki pages label_page_index: 索引 label_current_version: 最新版 label_preview: プレビュー diff --git a/lang/nl.yml b/lang/nl.yml index c6e92df4d..8b706f013 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -346,6 +346,7 @@ label_all_words: Alle woorden label_wiki: Wiki label_wiki_edit: Wiki edit label_wiki_edit_plural: Wiki edits +label_wiki_page_plural: Wiki pages label_page_index: Index label_current_version: Huidige versie label_preview: Testweergave diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 0b648af0e..f3a6caf74 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -346,6 +346,7 @@ label_all_words: Todas as palavras label_wiki: Wiki label_wiki_edit: Wiki edit label_wiki_edit_plural: Wiki edits +label_wiki_page_plural: Wiki pages label_page_index: Index label_current_version: Versao atual label_preview: Previa diff --git a/lang/pt.yml b/lang/pt.yml index 4aa5eb6a0..231b96992 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -346,6 +346,7 @@ label_all_words: Todas as palavras label_wiki: Wiki label_wiki_edit: Wiki edit label_wiki_edit_plural: Wiki edits +label_wiki_page_plural: Wiki pages label_page_index: Index label_current_version: Versão atual label_preview: Prévia diff --git a/lang/zh.yml b/lang/zh.yml index f71a05e0c..8f05ec9e2 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -349,6 +349,7 @@ label_all_words: 所有单词 label_wiki: Wiki label_wiki_edit: Wiki edit label_wiki_edit_plural: Wiki edits +label_wiki_page_plural: Wiki pages label_page_index: 索引 label_current_version: 当前版本 label_preview: 预览 diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb index bfe8aa06f..bb8111176 100644 --- a/test/unit/wiki_page_test.rb +++ b/test/unit/wiki_page_test.rb @@ -18,7 +18,7 @@ require File.dirname(__FILE__) + '/../test_helper' class WikiPageTest < Test::Unit::TestCase - fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions + fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions def setup @wiki = Wiki.find(1) @@ -47,4 +47,13 @@ class WikiPageTest < Test::Unit::TestCase assert_kind_of WikiPage, page assert page.new_record? end + + def test_destroy + page = WikiPage.find(1) + page.destroy + assert_nil WikiPage.find_by_id(1) + # make sure that page content and its history are deleted + assert WikiContent.find_all_by_page_id(1).empty? + assert WikiContent.versioned_class.find_all_by_page_id(1).empty? + end end -- 2.39.5