2009-01-08 16:33:27 +01:00
|
|
|
# Groups organize the User.
|
2009-01-06 11:49:19 +01:00
|
|
|
# A Member gets the roles from the Group
|
|
|
|
class Group < ActiveRecord::Base
|
|
|
|
has_many :memberships, :dependent => :destroy
|
|
|
|
has_many :users, :through => :memberships
|
2011-06-10 01:36:04 +02:00
|
|
|
|
|
|
|
validates :name, :presence => true, :length => {:in => 1..25}, :uniqueness => true
|
2011-06-10 13:22:15 +02:00
|
|
|
|
2011-05-16 00:34:43 +02:00
|
|
|
attr_reader :user_tokens
|
2009-01-06 11:49:19 +01:00
|
|
|
|
|
|
|
# Returns true if the given user if is an member of this group.
|
|
|
|
def member?(user)
|
|
|
|
memberships.find_by_user_id(user.id)
|
|
|
|
end
|
|
|
|
|
2009-01-14 12:46:01 +01:00
|
|
|
# Returns all NONmembers and a checks for possible multiple Ordergroup-Memberships
|
2009-01-06 11:49:19 +01:00
|
|
|
def non_members
|
2009-02-01 20:56:23 +01:00
|
|
|
User.all(:order => 'nick').reject { |u| users.include?(u) }
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2011-05-15 23:43:23 +02:00
|
|
|
|
2011-05-16 00:34:43 +02:00
|
|
|
def user_tokens=(ids)
|
|
|
|
self.user_ids = ids.split(",")
|
|
|
|
end
|
2009-01-06 11:49:19 +01:00
|
|
|
|
|
|
|
end
|
2011-05-07 20:50:39 +02:00
|
|
|
|
2011-05-07 21:55:24 +02:00
|
|
|
|