From: Jean-Philippe Lang Date: Tue, 21 Apr 2009 12:19:56 +0000 (+0000) Subject: Ask user what to do with child pages when deleting a parent wiki page (#3202). X-Git-Tag: 0.9.0~517 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bb44430b631eba1d33b218c97cb5d506073aeb08;p=redmine.git Ask user what to do with child pages when deleting a parent wiki page (#3202). 3 options are available: * move child pages as root pages * move child pages to another parent page * delete all descendants git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2676 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 1a480e4bd..9c624462a 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -131,9 +131,31 @@ class WikiController < ApplicationController render_404 unless @annotate end - # remove a wiki page and its history + # Removes a wiki page and its history + # Children can be either set as root pages, removed or reassigned to another parent page def destroy return render_403 unless editable? + + @descendants_count = @page.descendants.size + if @descendants_count > 0 + case params[:todo] + when 'nullify' + # Nothing to do + when 'destroy' + # Removes all its descendants + @page.descendants.each(&:destroy) + when 'reassign' + # Reassign children to another parent page + reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i) + return unless reassign_to + @page.children.each do |child| + child.update_attribute(:parent, reassign_to) + end + else + @reassignable_to = @wiki.pages - @page.self_and_descendants + return + end + end @page.destroy redirect_to :action => 'special', :id => @project, :page => 'Page_index' end diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index c692c748b..009d6f8cb 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -17,6 +17,19 @@ module WikiHelper + def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0) + s = '' + pages.select {|p| p.parent == parent}.each do |page| + attrs = "value='#{page.id}'" + attrs << " selected='selected'" if selected == page + indent = (level > 0) ? (' ' * level * 2 + '» ') : nil + + s << "\n" + + wiki_page_options_for_select(pages, selected, page, level + 1) + end + s + end + def html_diff(wdiff) words = wdiff.words.collect{|word| h(word)} words_add = 0 diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index f8bbcdebd..19858dbd4 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -22,7 +22,7 @@ class WikiPage < ActiveRecord::Base belongs_to :wiki has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy acts_as_attachable :delete_permission => :delete_wiki_pages_attachments - acts_as_tree :order => 'title' + acts_as_tree :dependent => :nullify, :order => 'title' acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"}, :description => :text, diff --git a/app/views/wiki/destroy.rhtml b/app/views/wiki/destroy.rhtml new file mode 100644 index 000000000..f552c69a5 --- /dev/null +++ b/app/views/wiki/destroy.rhtml @@ -0,0 +1,19 @@ +

<%=h @page.pretty_title %>

+ +<% form_tag({}) do %> +
+

<%= l(:text_wiki_page_destroy_question, :descendants => @descendants_count) %>

+


+ +<% if @reassignable_to.any? %> +
+: +<%= select_tag 'reassign_to_id', wiki_page_options_for_select(@reassignable_to), + :onclick => "$('todo_reassign').checked = true;" %> +<% end %> +

+
+ +<%= submit_tag l(:button_apply) %> +<%= link_to l(:button_cancel), :controller => 'wiki', :action => 'index', :id => @project, :page => @page.title %> +<% end %> diff --git a/app/views/wiki/edit.rhtml b/app/views/wiki/edit.rhtml index 19f3bd5ae..6a949e2aa 100644 --- a/app/views/wiki/edit.rhtml +++ b/app/views/wiki/edit.rhtml @@ -1,4 +1,4 @@ -

<%= @page.pretty_title %>

+

<%=h @page.pretty_title %>

<% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %> <%= f.hidden_field :version %> diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 5eb724a59..500cc5713 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -784,3 +784,7 @@ bg: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/bs.yml b/config/locales/bs.yml index 9f7de749b..a064372ef 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -817,3 +817,7 @@ bs: label_descending: Opadajuće label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 8ed335f08..8d435241d 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -787,3 +787,7 @@ ca: enumeration_activities: Activitats (seguidor de temps) label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/cs.yml b/config/locales/cs.yml index dd8ed2747..ab8f27fc8 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -790,3 +790,7 @@ cs: label_date_from_to: Od {{start}} do {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/da.yml b/config/locales/da.yml index 7cfa19914..704c5e4e8 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -817,3 +817,7 @@ da: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/de.yml b/config/locales/de.yml index 41e853292..3f9cd17a6 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -816,3 +816,7 @@ de: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/en.yml b/config/locales/en.yml index b60329f30..fd1ed6c51 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -761,6 +761,10 @@ en: text_repository_usernames_mapping: "Select or update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped." text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.' text_custom_field_possible_values_info: 'One line for each value' + text_wiki_page_destroy_question: "This page has {{descendants}} child page(s) and descendant(s). What do you want to do?" + text_wiki_page_nullify_children: "Keep child pages as root pages" + text_wiki_page_destroy_children: "Delete child pages and all their descendants" + text_wiki_page_reassign_children: "Reassign child pages to this parent page" default_role_manager: Manager default_role_developper: Developer diff --git a/config/locales/es.yml b/config/locales/es.yml index f3b9fad7a..c37b96c64 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -837,3 +837,7 @@ es: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/fi.yml b/config/locales/fi.yml index a9801aacf..9c35cb449 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -827,3 +827,7 @@ fi: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/fr.yml b/config/locales/fr.yml index e0b18bf67..ddd349c69 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -791,6 +791,10 @@ fr: text_repository_usernames_mapping: "Vous pouvez sélectionner ou modifier l'utilisateur Redmine associé à chaque nom d'utilisateur figurant dans l'historique du dépôt.\nLes utilisateurs avec le même identifiant ou la même adresse mail seront automatiquement associés." text_diff_truncated: '... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.' text_custom_field_possible_values_info: 'Une ligne par valeur' + text_wiki_page_destroy_question: "Cette page possède {{descendants}} sous-page(s) et descendante(s). Que voulez-vous faire ?" + text_wiki_page_nullify_children: "Conserver les sous-pages en tant que pages racines" + text_wiki_page_destroy_children: "Supprimer les sous-pages et toutes leurs descedantes" + text_wiki_page_reassign_children: "Réaffecter les sous-pages à cette page" default_role_manager: Manager default_role_developper: Développeur diff --git a/config/locales/gl.yml b/config/locales/gl.yml index b908d7d12..9ccd9574e 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -816,3 +816,7 @@ gl: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/he.yml b/config/locales/he.yml index 95c154232..4941240b7 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -799,3 +799,7 @@ he: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 77f52dd2f..a4ac468e7 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -822,3 +822,7 @@ label_date_from_to: "{{start}} -tól {{end}} -ig" label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/it.yml b/config/locales/it.yml index 1cb3195e6..58ee928ab 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -802,3 +802,7 @@ it: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 424775f22..5574aee63 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -815,3 +815,7 @@ ja: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 8019d246b..0b323fe1e 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -846,3 +846,7 @@ ko: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 09b73b73e..dd6b029ca 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -827,3 +827,7 @@ lt: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/nl.yml b/config/locales/nl.yml index ef50eac1c..b5728fbb3 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -772,3 +772,7 @@ nl: label_date_from_to: Van {{start}} tot {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/no.yml b/config/locales/no.yml index 3b4d681de..3eb1dbaba 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -789,3 +789,7 @@ label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/pl.yml b/config/locales/pl.yml index cddcad413..936683e84 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -820,3 +820,7 @@ pl: label_date_from_to: Od {{start}} do {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 8c4f7bd3a..bd065e5d3 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -822,3 +822,7 @@ pt-BR: label_date_from_to: De {{start}} até {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 9d1c765dc..aa8e672d5 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -808,3 +808,7 @@ pt: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/ro.yml b/config/locales/ro.yml index b191bd3c6..fe144c703 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -787,3 +787,7 @@ ro: enumeration_activities: Activitati (timp de lucru) label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/ru.yml b/config/locales/ru.yml index bdb0f6f4d..668a2c7da 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -914,3 +914,7 @@ ru: text_workflow_edit: Выберите роль и трекер для редактирования последовательности состояний warning_attachments_not_saved: "{{count}} файл(ов) невозможно сохранить." + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/sk.yml b/config/locales/sk.yml index e683007e6..6cd573fb1 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -788,3 +788,7 @@ sk: label_date_from_to: Od {{start}} do {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 2d9636643..5ccd5b7fd 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -786,3 +786,7 @@ sl: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/sr.yml b/config/locales/sr.yml index 37cb89fd0..b2b61a1c2 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -810,3 +810,7 @@ label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 700ed78c3..d532d4aa3 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -844,3 +844,7 @@ sv: enumeration_issue_priorities: Ärendeprioriteter enumeration_doc_categories: Dokumentkategorier enumeration_activities: Aktiviteter (tidsuppföljning) + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/th.yml b/config/locales/th.yml index b4ae5a2ae..9de605691 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -787,3 +787,7 @@ th: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/tr.yml b/config/locales/tr.yml index 5a6666373..068c4ec41 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -823,3 +823,7 @@ tr: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/uk.yml b/config/locales/uk.yml index 342825ffa..23edbd172 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -786,3 +786,7 @@ uk: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/vi.yml b/config/locales/vi.yml index 0bda7d995..0a8f82156 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -856,3 +856,7 @@ vi: label_date_from_to: From {{start}} to {{end}} label_greater_or_equal: ">=" label_less_or_equal: <= + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 03d5a4051..7a322c102 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -894,3 +894,7 @@ enumeration_issue_priorities: 項目優先權 enumeration_doc_categories: 文件分類 enumeration_activities: 活動 (時間追蹤) + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 9ad6b8b7c..5ae2411bf 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -819,3 +819,7 @@ zh: enumeration_issue_priorities: 问题优先级 enumeration_doc_categories: 文档类别 enumeration_activities: 活动(时间跟踪) + text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do? + text_wiki_page_reassign_children: Reassign child pages to this parent page + text_wiki_page_nullify_children: Keep child pages as root pages + text_wiki_page_destroy_children: Delete child pages and all their descendants diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 40dc04ae4..22d816e59 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -240,12 +240,50 @@ class WikiControllerTest < Test::Unit::TestCase ) end - def test_destroy + def test_destroy_child @request.session[:user_id] = 2 - post :destroy, :id => 1, :page => 'CookBook_documentation' + post :destroy, :id => 1, :page => 'Child_1' assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' end + def test_destroy_parent + @request.session[:user_id] = 2 + assert_no_difference('WikiPage.count') do + post :destroy, :id => 1, :page => 'Another_page' + end + assert_response :success + assert_template 'destroy' + end + + def test_destroy_parent_with_nullify + @request.session[:user_id] = 2 + assert_difference('WikiPage.count', -1) do + post :destroy, :id => 1, :page => 'Another_page', :todo => 'nullify' + end + assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' + assert_nil WikiPage.find_by_id(2) + end + + def test_destroy_parent_with_cascade + @request.session[:user_id] = 2 + assert_difference('WikiPage.count', -3) do + post :destroy, :id => 1, :page => 'Another_page', :todo => 'destroy' + end + assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' + assert_nil WikiPage.find_by_id(2) + assert_nil WikiPage.find_by_id(5) + end + + def test_destroy_parent_with_reassign + @request.session[:user_id] = 2 + assert_difference('WikiPage.count', -1) do + post :destroy, :id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 + end + assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index' + assert_nil WikiPage.find_by_id(2) + assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent + end + def test_special_routing assert_routing( {:method => :get, :path => '/projects/567/wiki/page_index'}, diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb index f7f62aec4..df41a4a0a 100644 --- a/test/unit/wiki_page_test.rb +++ b/test/unit/wiki_page_test.rb @@ -100,4 +100,18 @@ class WikiPageTest < Test::Unit::TestCase assert WikiContent.find_all_by_page_id(1).empty? assert WikiContent.versioned_class.find_all_by_page_id(1).empty? end + + def test_destroy_should_not_nullify_children + page = WikiPage.find(2) + child_ids = page.child_ids + assert child_ids.any? + page.destroy + assert_nil WikiPage.find_by_id(2) + + children = WikiPage.find_all_by_id(child_ids) + assert_equal child_ids.size, children.size + children.each do |child| + assert_nil child.parent_id + end + end end diff --git a/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb b/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb index 6a6827ee6..54b4373ef 100644 --- a/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb +++ b/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb @@ -40,11 +40,11 @@ module ActiveRecord # * order - makes it possible to sort the children according to this SQL snippet. # * counter_cache - keeps a count in a +children_count+ column if set to +true+ (default: +false+). def acts_as_tree(options = {}) - configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil } + configuration = { :foreign_key => "parent_id", :dependent => :destroy, :order => nil, :counter_cache => nil } configuration.update(options) if options.is_a?(Hash) belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache] - has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => :destroy + has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => configuration[:dependent] class_eval <<-EOV include ActiveRecord::Acts::Tree::InstanceMethods @@ -77,6 +77,13 @@ module ActiveRecord children + children.collect(&:children).flatten end + # Returns list of descendants and a reference to the current node. + # + # root.self_and_descendants # => [root, child1, subchild1, subchild2] + def self_and_descendants + [self] + descendants + end + # Returns the root node of the tree. def root node = self