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
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"
<% 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>
--- /dev/null
+<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 %>
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:'
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:'
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:'
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:'
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
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:'
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:'
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:'
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)."
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
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:'
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:'
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:'
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:'
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:'
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:'
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:'
label_last_month: last month\r
label_add_another_file: Add another file\r
label_optional_description: Optional description\r
+text_destroy_time_entries_question: %.02f hours were reported on the issues you are about to delete. What do you want to do ?\r
+error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'\r
+text_assign_time_entries_to_project: Assign reported hours to the project\r
+text_destroy_time_entries: Delete reported hours\r
+text_reassign_time_entries: 'Reassign reported hours to this issue:'\r
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:'
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:'
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:'
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:'
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:'
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:'
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:'
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:'
:workflows,
:custom_fields,
:custom_values,
- :custom_fields_trackers
+ :custom_fields_trackers,
+ :time_entries
def setup
@controller = IssuesController.new
: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
# 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