OSDN Git Service

Add check to ensure that a team member has atleast one Access Role selected
authorgitlabhq <m@gitlabhq.com>
Thu, 20 Oct 2011 13:48:09 +0000 (09:48 -0400)
committergitlabhq <m@gitlabhq.com>
Sat, 22 Oct 2011 11:08:02 +0000 (14:08 +0300)
app/models/users_project.rb

index bdc1063..96e2d16 100644 (file)
@@ -9,7 +9,8 @@ class UsersProject < ActiveRecord::Base
   validates_uniqueness_of :user_id, :scope => [:project_id]
   validates_presence_of :user_id
   validates_presence_of :project_id
+  validate :user_has_a_role_selected
+
   delegate :name, :email, :to => :user, :prefix => true
 
   def update_gitosis_project
@@ -18,6 +19,10 @@ class UsersProject < ActiveRecord::Base
     end
   end
 
+  def user_has_a_role_selected
+    errors.add(:base, "Please choose at least one Role in the Access list") unless read || write || admin
+  end
+
 end
 # == Schema Information
 #