blob: 968b9964a41321347565e8eb90fa1909f3b2604d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
require 'permissions/set.rb'
class UserCategory < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
timestamps
end
belongs_to :user, :null => false
belongs_to :question_category, :null => false
validates_uniqueness_of :user_id, :scope => :question_category_id
multi_permission :create, :update, :destroy do
return true if acting_user.role.is_recruiter?
return true if user_is?(acting_user)
false
end
def view_permitted?(field)
return true if acting_user.role.is_recruiter?
return true if user_is?(acting_user)
return true if user.mentor_is?(acting_user)
false
end
def before_create
for group in QuestionGroup.unassociated_in_category(user, question_category).all
chosen_question = rand(group.questions.count)
UserQuestionGroup.create! :user => user, :question =>
(Question.all :limit => 1, :offset => chosen_question, :conditions => {:question_group_id => group.id})[0]
end
end
end
|