2013-08-12 17:11:41 +08:00
|
|
|
class ProjectInfo < ActiveRecord::Base
|
|
|
|
attr_accessible :project_id, :user_id
|
2013-08-22 20:26:56 +08:00
|
|
|
|
2013-08-12 17:11:41 +08:00
|
|
|
belongs_to :project
|
|
|
|
belongs_to :user
|
|
|
|
validates_presence_of :project_id, :user_id
|
|
|
|
validates_uniqueness_of :project_id, :scope => :user_id
|
2014-06-12 16:35:59 +08:00
|
|
|
after_save :update_user_level
|
2013-08-22 20:26:56 +08:00
|
|
|
def self.manager? (user_id, project)
|
|
|
|
for project_info in project.project_infos
|
|
|
|
if project_info.user_id == user_id
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
2014-06-12 16:35:59 +08:00
|
|
|
|
|
|
|
#更新用户等级
|
|
|
|
def update_user_level
|
|
|
|
self.user.update_user_level
|
|
|
|
end
|
2013-08-12 17:11:41 +08:00
|
|
|
end
|