mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-14 13:51:26 +00:00
34 lines
669 B
Ruby
34 lines
669 B
Ruby
|
class Grouper < ActiveRecord::Base
|
||
|
attr_protected :id, :created_at, :updated_at
|
||
|
attr_accessor :username
|
||
|
|
||
|
belongs_to :group
|
||
|
belongs_to :user
|
||
|
|
||
|
validates_associated :group, :user
|
||
|
validates :group, :user, :presence => true
|
||
|
validates :task, :length => {:maximum => 25}
|
||
|
|
||
|
before_validation :fetch_user, :if => Proc.new {|grouper| grouper.username and !grouper.username.empty?}
|
||
|
|
||
|
def to_s
|
||
|
user.to_s
|
||
|
end
|
||
|
|
||
|
def fetch_user
|
||
|
self.user = User.find_by_username(username)
|
||
|
end
|
||
|
|
||
|
def can_create? cuser
|
||
|
cuser and cuser.admin?
|
||
|
end
|
||
|
|
||
|
def can_update? cuser
|
||
|
cuser and cuser.admin?
|
||
|
end
|
||
|
|
||
|
def can_destroy? cuser
|
||
|
cuser and cuser.admin?
|
||
|
end
|
||
|
end
|