Adds status transition validation

pull/782/head
Hagen Schink 11 years ago
parent f968ce4b84
commit 9f40a7184b
  1. 12
      app/models/type.rb
  2. 20
      app/models/work_package/validations.rb
  3. 2
      config/locales/de.yml
  4. 2
      config/locales/en.yml

@ -102,8 +102,20 @@ class Type < ActiveRecord::Base
PlanningElementTypeColor.all
end
def is_valid_transition?(status_id_a, status_id_b, roles)
transition_exists?(status_id_a, status_id_b, roles.collect(&:id))
end
private
def check_integrity
raise "Can't delete type" if WorkPackage.find(:first, :conditions => ["type_id=?", self.id])
end
def transition_exists?(status_id_a, status_id_b, role_ids)
!workflows.where(old_status_id: status_id_a,
new_status_id: status_id_b,
role_id: role_ids)
.empty?
end
end

@ -46,6 +46,8 @@ module WorkPackage::Validations
validate :validate_milestone_constraint
validate :validate_parent_constraint
validate :validate_status_transition
end
def validate_start_date_before_soonest_start_date
@ -84,4 +86,22 @@ module WorkPackage::Validations
errors.add :parent_id, :cannot_be_milestone if parent.is_milestone?
end
end
def validate_status_transition
if status_changed? && !status_transition_exists?
errors.add :status_id, :status_transition_invalid
end
end
private
def status_changed?
self.status_id_was != 0 && self.status_id_changed?
end
def status_transition_exists?
roles = User.current.roles_for_project(self.project)
self.type.is_valid_transition?(self.status_id_was, self.status_id, roles)
end
end

@ -219,6 +219,8 @@ de:
cannot_be_in_another_project: "darf nicht in einem anderen Projekt sein"
not_a_valid_parent: "ist ungültig"
does_not_exist: "existiert nicht"
status_id:
status_transition_invalid: "es existiert kein valider Übergang vom alten zum neuen Status"
project_association:
identical_projects: "kann nicht von einem Projekt auf sich selbst erstellt werden"
project_association_not_allowed: "erlaubt keine Projekt-Abhängigkeiten"

@ -220,6 +220,8 @@ en:
cannot_be_in_another_project: "cannot be in another project"
not_a_valid_parent: "is invaild"
does_not_exist: "does not exist"
status_id:
status_transition_invalid: "no valid transition exists from old to new status"
user:
attributes:
password:

Loading…
Cancel
Save