Skip to content

Commit

Permalink
Fixed issue status validation (#8938)
Browse files Browse the repository at this point in the history
  • Loading branch information
anteo committed Oct 5, 2012
1 parent d9a6f1f commit d7f3817
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/redmine_custom_workflows/issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def self.included(base)

module InstanceMethods
def validate_status
return true unless @extra_validation
if status_id_was != status_id && !new_statuses_allowed_to(User.current, new_record?).collect(&:id).include?(status_id)
status_was = IssueStatus.find_by_id(status_id_was)
status_new = IssueStatus.find_by_id(status_id)
return true unless @saved_attributes && @saved_attributes['status_id'] != status_id &&
!new_statuses_allowed_to(User.current, new_record?).collect(&:id).include?(status_id)

errors.add :status, :new_status_invalid,
:old_status => status_was && status_was.name,
:new_status => status_new && status_new.name
end
status_was = IssueStatus.find_by_id(status_id_was)
status_new = IssueStatus.find_by_id(status_id)

errors.add :status, :new_status_invalid,
:old_status => status_was && status_was.name,
:new_status => status_new && status_new.name
end

def run_custom_workflows(on)
Expand All @@ -47,10 +47,9 @@ def run_custom_workflows(on)
end

def before_save_custom_workflows
saved_attributes = attributes.dup
@extra_validation = true
result = run_custom_workflows(:before_save) && (saved_attributes == attributes || valid?)
@extra_validation = false
@saved_attributes = attributes.dup
result = run_custom_workflows(:before_save) && (@saved_attributes == attributes || valid?)
@saved_attributes = nil
result
end

Expand Down

0 comments on commit d7f3817

Please sign in to comment.