Class: User
Class Method Summary
collapse
Instance Method Summary
collapse
#navigable_name, #navigation_end?
#build_reminder, #remind!, #should_remind?, #try_remind_with_lock!
aggregate_of, all_except, defaults, name_model_as, numbered, #save, #save_and_notify!, #save_and_notify_changes!, #update_and_notify!, update_or_create!, whitelist_attributes
Class Method Details
.create_if_necessary(user) ⇒ Object
121
122
123
124
|
# File 'app/models/user.rb', line 121
def self.create_if_necessary(user)
user[:uid] ||= user[:email]
where(uid: user[:uid]).first_or_create(user)
end
|
.import_from_json!(json) ⇒ Object
98
99
100
101
|
# File 'app/models/user.rb', line 98
def self.import_from_json!(json)
json = Mumukit::Platform::User::Helpers.slice_platform_json json
User.where(uid: json[:uid]).update_or_create!(json)
end
|
.unsubscription_verifier ⇒ Object
107
108
109
|
# File 'app/models/user.rb', line 107
def self.unsubscription_verifier
Rails.application.message_verifier(:unsubscribe)
end
|
Instance Method Details
#accept_invitation!(invitation) ⇒ Object
82
83
84
|
# File 'app/models/user.rb', line 82
def accept_invitation!(invitation)
make_student_of! invitation.course
end
|
#attach!(role, course) ⇒ Object
111
112
113
114
|
# File 'app/models/user.rb', line 111
def attach!(role, course)
add_permission! role, course.slug
save_and_notify!
end
|
#clear_progress! ⇒ Object
75
76
77
78
79
80
|
# File 'app/models/user.rb', line 75
def clear_progress!
transaction do
update! last_submission_date: nil, last_exercise: nil
assignments.destroy_all
end
end
|
#copy_progress_to!(another) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
|
# File 'app/models/user.rb', line 86
def copy_progress_to!(another)
transaction do
assignments.update_all(submitter_id: another.id)
if another.never_submitted? || last_submission_date.try { |it| it > another.last_submission_date }
another.update! last_submission_date: last_submission_date,
last_exercise: last_exercise,
last_organization: last_organization
end
end
reload
end
|
#currently_in_exam? ⇒ Boolean
140
141
142
|
# File 'app/models/user.rb', line 140
def currently_in_exam?
exams.any? { |e| e.in_progress_for? self }
end
|
#detach!(role, course) ⇒ Object
116
117
118
119
|
# File 'app/models/user.rb', line 116
def detach!(role, course)
remove_permission! role, course.slug
save_and_notify!
end
|
#interpolations ⇒ Object
126
127
128
129
130
131
132
|
# File 'app/models/user.rb', line 126
def interpolations
{
'user_email' => email,
'user_first_name' => first_name,
'user_last_name' => last_name
}
end
|
#last_lesson ⇒ Object
35
36
37
|
# File 'app/models/user.rb', line 35
def last_lesson
last_guide.try(:lesson)
end
|
#never_submitted? ⇒ Boolean
71
72
73
|
# File 'app/models/user.rb', line 71
def never_submitted?
last_submission_date.nil?
end
|
#passed_assignments ⇒ Object
#passed_submissions_count ⇒ Object
43
44
45
|
# File 'app/models/user.rb', line 43
def passed_submissions_count
passed_assignments.count
end
|
#resubmit!(organization = nil) ⇒ Object
134
135
136
137
138
|
# File 'app/models/user.rb', line 134
def resubmit!(organization = nil)
organization = Organization.find_by_name(organization) || main_organization
organization.switch!
assignments.each { |it| it.notify! rescue nil }
end
|
#solved_exercises_count ⇒ Object
51
52
53
|
# File 'app/models/user.rb', line 51
def solved_exercises_count
solved_exercises.count
end
|
#submissions_count ⇒ Object
39
40
41
|
# File 'app/models/user.rb', line 39
def submissions_count
assignments.pluck(:submissions_count).sum
end
|
#submitted_exercises_count ⇒ Object
47
48
49
|
# File 'app/models/user.rb', line 47
def submitted_exercises_count
submitted_exercises.count
end
|
#to_s ⇒ Object
67
68
69
|
# File 'app/models/user.rb', line 67
def to_s
"#{id}:#{name}:#{uid}"
end
|
#unread_messages ⇒ Object
59
60
61
|
# File 'app/models/user.rb', line 59
def unread_messages
messages.where read: false
end
|
#unsubscribe_from_reminders! ⇒ Object
103
104
105
|
# File 'app/models/user.rb', line 103
def unsubscribe_from_reminders!
update! accepts_reminders: false
end
|
#visit!(organization) ⇒ Object
63
64
65
|
# File 'app/models/user.rb', line 63
def visit!(organization)
update!(last_organization: organization) if organization != last_organization
end
|