mirror of
https://github.com/wahyd4/ocelots.git
synced 2026-08-09 04:56:21 +10:00
36 lines
924 B
Ruby
36 lines
924 B
Ruby
class Team < ActiveRecord::Base
|
|
attr_accessible :description, :name, :slug, :creator
|
|
|
|
validates_presence_of :name
|
|
validates_presence_of :slug
|
|
validates_uniqueness_of :slug
|
|
validate :format_slug ,:on => :create
|
|
|
|
has_many :memberships
|
|
has_many :people, through: :memberships
|
|
has_many :messages
|
|
has_many :engagements
|
|
has_many :organisations, through: :engagements
|
|
belongs_to :creator, class_name: 'Person'
|
|
|
|
|
|
def api_attributes params={}
|
|
att = attributes.except *%w{id creator_id}
|
|
att[:members] = memberships.includes(:person).approved.map(&:person).map(&:api_attributes) if params[:include] and params[:include].include? :members
|
|
att
|
|
end
|
|
|
|
def blessed?(domain)
|
|
organisations.map{|org| org.domains.split(',')}.flatten.include?(domain)
|
|
end
|
|
|
|
def add_to (organisation)
|
|
organisations << organisation if organisation
|
|
end
|
|
|
|
def format_slug
|
|
|
|
slug.gsub!(/ /, "_") if slug
|
|
end
|
|
|
|
end |