anteo / redmine_custom_workflows

Allows to create custom workflows for Redmine
http://www.redmine.org/plugins/custom-workflows
GNU General Public License v2.0
182 stars 72 forks source link

When using Before Destruction on issues, no error gets displayed #275

Closed Seahawk240 closed 2 years ago

Seahawk240 commented 2 years ago

Hello,

I prevent the deletion of issues once someone worked on them. This way one can delete a new ticket, in the case they made a mistake or something.

My code is as follows:

if self.status_id != 8     
  errors.add(:base,"Nur neue Tickets können gelöscht werden.")
  throw(:abort)
end

if self.children?
  errors.add(:base, "Dieses Ticket kann nicht gelöscht werden, da untergeordnete Tickets existieren.")
  throw(:abort)
end 

if self.spent_hours > 0
  errors.add(:base, "Dieses Ticket kann nicht gelöscht werden, da schon Zeiten gebucht wurden.")
  throw(:abort)
end

The deletion of the issue gets prevented but when i click on delete, redmine still tells me deletion worked as intended and raises no errors.

Thank you for this amazing plugin and thanks to anyone willing to help me :)

Greetings Matthias

AirTibu commented 2 years ago

Hi,

Change this code:

throw(:abort)

To this:

return true

This will interupt the running.

Seahawk240 commented 2 years ago

Hi,

thanks for your reply. I finally came around trying this. Sadly it didn't work any ideas why?

Greetings Matthias

Edit_1: For Clarification what does not work. When i do what you suggest, then the process doesn't get halted, the Issue gets deleted and that's it. When using throw(:abort) then it will. Combining them does not bring any improvements.

picman commented 2 years ago

This is not possible in the present code. throw :abort interrupts the plugin's destroy method, but the parent issue's destroy method will continue. return true is simply ignored.

picman commented 2 years ago

This code will work in v2.0.6

before destroy

# Suppress the original message "Issue deleted"
self.custom_workflow_messages[:notice] = ''
# Add your own error message
self.custom_workflow_messages[:error] = 'Issue cannot be deleted'
# Return false to stop processing of delete event
return false
Seahawk240 commented 1 year ago

This code will work in v2.0.6

It does! Just updated to v2.0.8 Thanks Man! Thanks for your amazing work on this project, really appreciate it!