Commit c01c64e9 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Let the user choose when deleting issues with reported hours (closes #734, #71):

* to delete the hours
* to assign the hours to the project
* to reassign the hours to another issue


git-svn-id: http://redmine.rubyforge.org/svn/trunk@1182 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 87742f23
......@@ -263,6 +263,26 @@ class IssuesController < ApplicationController
end
def destroy
@hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
if @hours > 0
case params[:todo]
when 'destroy'
# nothing to do
when 'nullify'
TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
when 'reassign'
reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
if reassign_to.nil?
flash.now[:error] = l(:error_issue_not_found_in_project)
return
else
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
end
else
# display the destroy form
return
end
end
@issues.each(&:destroy)
redirect_to :action => 'index', :project_id => @project
end
......
......@@ -27,7 +27,7 @@ class Issue < ActiveRecord::Base
has_many :journals, :as => :journalized, :dependent => :destroy
has_many :attachments, :as => :container, :dependent => :destroy
has_many :time_entries, :dependent => :nullify
has_many :time_entries, :dependent => :delete_all
has_many :custom_values, :dependent => :delete_all, :as => :customized
has_many :custom_fields, :through => :custom_values
has_and_belongs_to_many :changesets, :order => "revision ASC"
......
......@@ -3,9 +3,9 @@
<% form_tag({}) do %>
<div class="box">
<p><strong><%= l(:text_issue_category_destroy_question, @issue_count) %></strong></p>
<p><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_issue_category_destroy_assignments) %><br />
<p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_issue_category_destroy_assignments) %></label><br />
<% if @categories.size > 0 %>
<%= radio_button_tag 'todo', 'reassign', false %> <%= l(:text_issue_category_reassign_to) %>:
<label><%= radio_button_tag 'todo', 'reassign', false %> <%= l(:text_issue_category_reassign_to) %></label>:
<%= select_tag 'reassign_to_id', options_from_collection_for_select(@categories, 'id', 'name') %></p>
<% end %>
</div>
......
<h2><%= l(:confirmation) %></h2>
<% form_tag do %>
<%= @issues.collect {|i| hidden_field_tag 'ids[]', i.id } %>
<div class="box">
<p><strong><%= l(:text_destroy_time_entries_question, @hours) %></strong></p>
<p>
<label><%= radio_button_tag 'todo', 'destroy', true %> <%= l(:text_destroy_time_entries) %></label><br />
<label><%= radio_button_tag 'todo', 'nullify', false %> <%= l(:text_assign_time_entries_to_project) %></label><br />
<label><%= radio_button_tag 'todo', 'reassign', false, :onchange => 'if (this.checked) { $("reassign_to_id").focus(); }' %> <%= l(:text_reassign_time_entries) %></label>
<%= text_field_tag 'reassign_to_id', params[:reassign_to_id], :size => 6, :onfocus => '$("todo_reassign").checked=true;' %>
</p>
</div>
<%= submit_tag l(:button_apply) %>
<% end %>
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -80,6 +80,7 @@ notice_default_data_loaded: Default configuration successfully loaded.
error_can_t_load_default_data: "Default configuration could not be loaded: %s"
error_scm_not_found: "Entry and/or revision doesn't exist in the repository."
error_scm_command_failed: "An error occurred when trying to access the repository: %s"
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
mail_subject_lost_password: Your Redmine password
mail_body_lost_password: 'To change your Redmine password, click on the following link:'
......@@ -577,6 +578,10 @@ text_select_project_modules: 'Select modules to enable for this project:'
text_default_administrator_account_changed: Default administrator account changed
text_file_repository_writable: File repository writable
text_rmagick_available: RMagick available (optional)
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
text_destroy_time_entries: Delete reported hours
text_assign_time_entries_to_project: Assign reported hours to the project
text_reassign_time_entries: 'Reassign reported hours to this issue:'
default_role_manager: Manager
default_role_developper: Developer
......
......@@ -605,3 +605,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -606,3 +606,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -80,6 +80,7 @@ notice_default_data_loaded: Paramétrage par défaut chargé avec succès.
error_can_t_load_default_data: "Une erreur s'est produite lors du chargement du paramétrage: %s"
error_scm_not_found: "L'entrée et/ou la révision demandée n'existe pas dans le dépôt."
error_scm_command_failed: "Une erreur s'est produite lors de l'accès au dépôt: %s"
error_issue_not_found_in_project: "La demande n'existe pas ou n'appartient pas à ce projet"
mail_subject_lost_password: Votre mot de passe redMine
mail_body_lost_password: 'Pour changer votre mot de passe Redmine, cliquez sur le lien suivant:'
......@@ -565,7 +566,7 @@ text_issues_ref_in_commit_messages: Référencement et résolution des demandes
text_issue_added: La demande %s a été soumise par %s.
text_issue_updated: La demande %s a été mise à jour par %s.
text_wiki_destroy_confirmation: Etes-vous sûr de vouloir supprimer ce wiki et tout son contenu ?
text_issue_category_destroy_question: Des demandes (%d) sont affectées à cette catégories. Que voulez-vous faire ?
text_issue_category_destroy_question: %d demandes sont affectées à cette catégories. Que voulez-vous faire ?
text_issue_category_destroy_assignments: N'affecter les demandes à aucune autre catégorie
text_issue_category_reassign_to: Réaffecter les demandes à cette catégorie
text_user_mail_option: "Pour les projets non sélectionnés, vous recevrez seulement des notifications pour ce que vous surveillez ou à quoi vous participez (exemple: demandes dont vous êtes l'auteur ou la personne assignée)."
......@@ -577,6 +578,10 @@ text_select_project_modules: 'Selectionner les modules à activer pour ce projec
text_default_administrator_account_changed: Compte administrateur par défaut changé
text_file_repository_writable: Répertoire de stockage des fichiers accessible en écriture
text_rmagick_available: Bibliothèque RMagick présente (optionnelle)
text_destroy_time_entries_question: %.02f heures ont été enregistrées sur les demandes à supprimer. Que voulez-vous faire ?
text_destroy_time_entries: Supprimer les heures
text_assign_time_entries_to_project: Reporter les heures sur le projet
text_reassign_time_entries: 'Reporter les heures sur cette demande:'
default_role_manager: Manager
default_role_developper: Développeur
......
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -603,3 +603,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -603,3 +603,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -603,3 +603,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -606,3 +606,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -603,3 +603,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -603,3 +603,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -604,3 +604,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -602,3 +602,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -605,3 +605,8 @@ label_yesterday: yesterday
label_last_month: last month
label_add_another_file: Add another file
label_optional_description: Optional description
text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
text_assign_time_entries_to_project: Assign reported hours to the project
text_destroy_time_entries: Delete reported hours
text_reassign_time_entries: 'Reassign reported hours to this issue:'
......@@ -37,7 +37,8 @@ class IssuesControllerTest < Test::Unit::TestCase
:workflows,
:custom_fields,
:custom_values,
:custom_fields_trackers
:custom_fields_trackers,
:time_entries
def setup
@controller = IssuesController.new
......@@ -428,13 +429,48 @@ class IssuesControllerTest < Test::Unit::TestCase
:class => 'icon-del disabled' }
end
def test_destroy
def test_destroy_issue_with_no_time_entries
@request.session[:user_id] = 2
post :destroy, :id => 1
post :destroy, :id => 3
assert_redirected_to 'projects/ecookbook/issues'
assert_nil Issue.find_by_id(1)
assert_nil Issue.find_by_id(3)
end
def test_destroy_issues_with_time_entries
@request.session[:user_id] = 2
post :destroy, :ids => [1, 3]
assert_response :success
assert_template 'destroy'
assert_not_nil assigns(:hours)
assert Issue.find_by_id(1) && Issue.find_by_id(3)
end
def test_destroy_issues_and_destroy_time_entries
@request.session[:user_id] = 2
post :destroy, :ids => [1, 3], :todo => 'destroy'
assert_redirected_to 'projects/ecookbook/issues'
assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
assert_nil TimeEntry.find_by_id([1, 2])
end
def test_destroy_issues_and_assign_time_entries_to_project
@request.session[:user_id] = 2
post :destroy, :ids => [1, 3], :todo => 'nullify'
assert_redirected_to 'projects/ecookbook/issues'
assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
assert_nil TimeEntry.find(1).issue_id
assert_nil TimeEntry.find(2).issue_id
end
def test_destroy_issues_and_reassign_time_entries_to_another_issue
@request.session[:user_id] = 2
post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
assert_redirected_to 'projects/ecookbook/issues'
assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
assert_equal 2, TimeEntry.find(1).issue_id
assert_equal 2, TimeEntry.find(2).issue_id
end
def test_destroy_attachment
issue = Issue.find(3)
a = issue.attachments.size
......
......@@ -70,4 +70,10 @@ class IssueTest < Test::Unit::TestCase
# Make sure time entries were move to the target project
assert_equal 2, issue.time_entries.first.project_id
end
def test_issue_destroy
Issue.find(1).destroy
assert_nil Issue.find_by_id(1)
assert_nil TimeEntry.find_by_issue_id(1)
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment