summaryrefslogtreecommitdiffstats
path: root/app/models/principal.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-04-11 17:51:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-04-11 17:51:16 +0000
commit97a647c1e5d43106d97d3b07febfd659eb5681c1 (patch)
treefe5d3519bf622c06210093db3bb126a57fb2684d /app/models/principal.rb
parent1da39caad3d2bded1da854f44b99d902beca2494 (diff)
downloadredmine-97a647c1e5d43106d97d3b07febfd659eb5681c1.tar.gz
redmine-97a647c1e5d43106d97d3b07febfd659eb5681c1.zip
Validate status of users and groups.
git-svn-id: http://svn.redmine.org/redmine/trunk@15320 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/principal.rb')
-rw-r--r--app/models/principal.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/principal.rb b/app/models/principal.rb
index 3aca26466..f3e0a3d4d 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -24,6 +24,8 @@ class Principal < ActiveRecord::Base
STATUS_REGISTERED = 2
STATUS_LOCKED = 3
+ class_attribute :valid_statuses
+
has_many :members, :foreign_key => 'user_id', :dependent => :destroy
has_many :memberships,
lambda {preload(:project, :roles).
@@ -34,6 +36,8 @@ class Principal < ActiveRecord::Base
has_many :projects, :through => :memberships
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
+ validate :validate_status
+
# Groups and active users
scope :active, lambda { where(:status => STATUS_ACTIVE) }
@@ -178,6 +182,14 @@ class Principal < ActiveRecord::Base
self.lastname ||= ''
true
end
+
+ def validate_status
+ if status_changed? && self.class.valid_statuses.present?
+ unless self.class.valid_statuses.include?(status)
+ errors.add :status, :invalid
+ end
+ end
+ end
end
require_dependency "user"