[#6441] Block editing Locked or Closed Deliverables.

This commit is contained in:
Eric Davis
2011-08-08 15:52:13 -07:00
parent 51f62ca5a3
commit ac24ae08e6
4 changed files with 202 additions and 2 deletions
+27
View File
@@ -20,6 +20,7 @@ class Deliverable < ActiveRecord::Base
validates_presence_of :type
validates_presence_of :manager
validates_inclusion_of :status, :in => ["open","locked","closed"], :allow_blank => true, :allow_nil => true
validate :validate_update_allowed
# Accessors
include DollarizedAttribute
@@ -63,6 +64,10 @@ class Deliverable < ActiveRecord::Base
update_attribute(:status, "closed")
end
def open?
self.status == "open"
end
def locked?
self.status == "locked"
end
@@ -71,6 +76,28 @@ class Deliverable < ActiveRecord::Base
self.status == "closed"
end
def editable?
(new_record? || open?)
end
def validate_update_allowed
unless new_record?
if changes.keys == ["status"]
noop("Allow changes to the status only")
elsif changes["status"].present? && changes["status"].second == "open"
noop("Allow any changes when going to 'open'")
elsif changes["status"].present?
errors.add_to_base(:cant_update_locked_deliverable) if locked?
errors.add_to_base(:cant_update_closed_deliverable) if closed?
end
end
end
# No operation method, useful to clean up logic with an optional message
# for documentation
def noop(message="")
end
def to_s
title
end