def destroy
raise Unauthorized unless @issues.all?(&:deletable?)
- @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
+
+ # all issues and their descendants are about to be deleted
+ issues_and_descendants_ids = Issue.self_and_descendants(@issues).pluck(:id)
+ time_entries = TimeEntry.where(:issue_id => issues_and_descendants_ids)
+ @hours = time_entries.sum(:hours).to_f
+
if @hours > 0
case params[:todo]
when 'destroy'
# nothing to do
when 'nullify'
- TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL')
+ time_entries.update_all(:issue_id => nil)
when 'reassign'
- reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
+ reassign_to = @project && @project.issues.find_by_id(params[:reassign_to_id])
if reassign_to.nil?
flash.now[:error] = l(:error_issue_not_found_in_project)
return
+ elsif issues_and_descendants_ids.include?(reassign_to.id)
+ flash.now[:error] = l(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted)
+ return
else
- TimeEntry.where(['issue_id IN (?)', @issues]).
- update_all("issue_id = #{reassign_to.id}")
+ time_entries.update_all(:issue_id => reassign_to.id, :project_id => reassign_to.project_id)
end
else
# display the destroy form if it's a user request
end
end
+ # Returns a scope of the given issues and their descendants
+ def self.self_and_descendants(issues)
+ Issue.joins("JOIN #{Issue.table_name} ancestors" +
+ " ON ancestors.root_id = #{Issue.table_name}.root_id" +
+ " AND ancestors.lft <= #{Issue.table_name}.lft AND ancestors.rgt >= #{Issue.table_name}.rgt"
+ ).
+ where(:ancestors => {:id => issues.map(&:id)})
+ end
+
# Finds an issue relation given its id.
def find_relation(relation_id)
IssueRelation.where("issue_to_id = ? OR issue_from_id = ?", id, id).find(relation_id)
<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 />
+<% if @project %>
<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").attr("checked", true);' %>
+<% end %>
</p>
</div>
<%= submit_tag l(:button_apply) %>
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
text_repository_identifier_info: 'Позволени са малки букви (a-z), цифри, тирета и _.<br />Промяна след създаването му не е възможна.'
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
setting_new_item_menu_tab: Pestanya de nous objectes en el menu de cada projecte
label_new_object_tab_enabled: Mostrar el llistat desplegable "+"
error_no_projects_with_tracker_allowed_for_new_issue: "Cap projecte disposa d'un tipus d'assumpte sobre el qual vostè pugui crear un assumpte"
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Dropdown-Menü "+" anzeigen
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
error_ldap_bind_credentials: "Invalid LDAP Account/Password"
error_no_tracker_allowed_for_new_issue_in_project: "The project doesn't have any trackers for which you can create an issue"
error_no_projects_with_tracker_allowed_for_new_issue: "There are no projects with trackers for which you can create an issue"
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: "Spent time cannot be reassigned to an issue that is about to be deleted"
mail_subject_lost_password: "Your %{value} password"
mail_body_lost_password: 'To change your password, click on the following link:'
setting_new_item_menu_tab: Pestaña de creación de nuevos objetos en el menú de cada proyecto
label_new_object_tab_enabled: Mostrar la lista desplegable "+"
error_no_projects_with_tracker_allowed_for_new_issue: Ningún proyecto dispone de un tipo sobre el cual puedas crear una petición
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
setting_new_item_menu_tab: Pestaña de creación de nuevos objetos en el menú de cada proyecto
label_new_object_tab_enabled: Mostrar la lista desplegable "+"
error_no_projects_with_tracker_allowed_for_new_issue: Ningún proyecto dispone de un tipo sobre el cual puedas crear una petición
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
error_ldap_bind_credentials: "Identifiant ou mot de passe LDAP incorrect"
error_no_tracker_allowed_for_new_issue_in_project: "Le projet ne dispose d'aucun tracker sur lequel vous pouvez créer une demande"
error_no_projects_with_tracker_allowed_for_new_issue: "Aucun projet ne dispose d'un tracker sur lequel vous pouvez créer une demande"
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: "Le temps passé ne peut pas être réaffecté à une demande qui va être supprimée"
mail_subject_lost_password: "Votre mot de passe %{value}"
mail_body_lost_password: 'Pour changer votre mot de passe, cliquez sur le lien suivant :'
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: '"+" ドロップダウンを表示'
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: 메뉴에 "+" 탭 표시
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Exibir o "+" suspenso
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Отображать выпадающий список "+"
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: Display the "+" drop-down
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
description_date_from: 輸入起始日期
description_date_to: 輸入結束日期
text_repository_identifier_info: '僅允許使用小寫英文字母 (a-z), 阿拉伯數字, 虛線與底線。<br />一旦儲存之後, 代碼便無法再次被更改。'
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
label_new_object_tab_enabled: 显示 "+" 为下拉列表
error_no_projects_with_tracker_allowed_for_new_issue: There are no projects with trackers
for which you can create an issue
+ error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: Spent time cannot
+ be reassigned to an issue that is about to be deleted
assert_response :success
end
- def test_destroy_issue_with_no_time_entries
+ def test_destroy_issue_with_no_time_entries_should_delete_the_issues
assert_nil TimeEntry.find_by_issue_id(2)
@request.session[:user_id] = 2
assert_nil Issue.find_by_id(2)
end
- def test_destroy_issues_with_time_entries
+ def test_destroy_issues_with_time_entries_should_show_the_reassign_form
@request.session[:user_id] = 2
assert_no_difference 'Issue.count' do
end
end
+ def test_destroy_issues_with_time_entries_should_show_hours_on_issues_and_descendants
+ parent = Issue.generate_with_child!
+ TimeEntry.generate!(:issue => parent)
+ TimeEntry.generate!(:issue => parent.children.first)
+ leaf = Issue.generate!
+ TimeEntry.generate!(:issue => leaf)
+ @request.session[:user_id] = 2
+
+ delete :destroy, :ids => [parent.id, leaf.id]
+ assert_response :success
+
+ assert_select 'p', :text => /3\.00 hours were reported/
+ end
+
def test_destroy_issues_and_destroy_time_entries
@request.session[:user_id] = 2
assert_equal 2, TimeEntry.find(2).issue_id
end
+ def test_destroy_issues_with_time_entries_should_reassign_time_entries_of_issues_and_descendants
+ parent = Issue.generate_with_child!
+ TimeEntry.generate!(:issue => parent)
+ TimeEntry.generate!(:issue => parent.children.first)
+ leaf = Issue.generate!
+ TimeEntry.generate!(:issue => leaf)
+ target = Issue.generate!
+ @request.session[:user_id] = 2
+
+ assert_difference 'Issue.count', -3 do
+ assert_no_difference 'TimeEntry.count' do
+ delete :destroy, :ids => [parent.id, leaf.id], :todo => 'reassign', :reassign_to_id => target.id
+ assert_response 302
+ end
+ end
+ assert_equal 3, target.time_entries.count
+ end
+
def test_destroy_issues_and_reassign_time_entries_to_an_invalid_issue_should_fail
@request.session[:user_id] = 2
assert_template 'destroy'
end
+ def test_destroy_issues_and_reassign_time_entries_to_an_issue_to_delete_should_fail
+ @request.session[:user_id] = 2
+
+ assert_no_difference 'Issue.count' do
+ assert_no_difference 'TimeEntry.count' do
+ delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 3
+ end
+ end
+ assert_response :success
+ assert_select '#flash_error', :text => I18n.t(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted)
+ end
+
def test_destroy_issues_from_different_projects
@request.session[:user_id] = 2