rosa-build/app/models/group.rb

34 lines
1.4 KiB
Ruby
Raw Normal View History

class Group < ActiveRecord::Base
belongs_to :owner, :class_name => 'User'
2011-10-18 16:00:06 +01:00
has_many :own_projects, :as => :owner, :class_name => 'Project'
has_many :relations, :as => :object, :dependent => :destroy
has_many :objects, :as => :target, :class_name => 'Relation'
has_many :targets, :as => :object, :class_name => 'Relation'
2011-10-16 21:39:45 +01:00
has_many :members, :through => :objects, :source => :object, :source_type => 'User', :autosave => true
has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true
2011-10-16 21:39:45 +01:00
validates :name, :owner, :presence => true
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ }
validate { errors.add(:uname, :taken) if User.where('uname LIKE ?', uname).present? }
attr_readonly :uname
delegate :ssh_key, :to => :owner
2011-10-18 16:00:06 +01:00
2011-11-30 15:27:19 +00:00
after_create :add_owner_to_members
include Modules::Models::PersonalRepository
# include Modules::Models::Owner
2011-11-30 15:27:19 +00:00
protected
def add_owner_to_members
Relation.create_with_role(self.owner, self, 'admin')
# members << self.owner if !members.exists?(:id => self.owner.id)
end
end