Class: User
Instance Method Summary
collapse
#navigable_name, #navigation_end?
#build_reminder, #remind!, #should_remind?, #try_remind_with_lock!
Methods included from Syncable
#platform_class_name, #sync_key
aggregate_of, all_except, defaults, numbered, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, #update_and_notify!, update_or_create!, whitelist_attributes
Instance Method Details
#accept_invitation!(invitation) ⇒ Object
83
84
85
|
# File 'app/models/user.rb', line 83
def accept_invitation!(invitation)
make_student_of! invitation.course_slug
end
|
#attach!(role, course) ⇒ Object
108
109
110
111
|
# File 'app/models/user.rb', line 108
def attach!(role, course)
add_permission! role, course.slug
save_and_notify!
end
|
#clear_progress! ⇒ Object
76
77
78
79
80
81
|
# File 'app/models/user.rb', line 76
def clear_progress!
transaction do
update! last_submission_date: nil, last_exercise: nil
assignments.destroy_all
end
end
|
#copy_progress_to!(another) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/models/user.rb', line 87
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
132
133
134
|
# File 'app/models/user.rb', line 132
def currently_in_exam?
exams.any? { |e| e.in_progress_for? self }
end
|
#detach!(role, course) ⇒ Object
113
114
115
116
|
# File 'app/models/user.rb', line 113
def detach!(role, course)
remove_permission! role, course.slug
save_and_notify!
end
|
#import_from_resource_h!(json) ⇒ Object
99
100
101
|
# File 'app/models/user.rb', line 99
def import_from_resource_h!(json)
update! Mumukit::Platform::User::Helpers.slice_platform_json json
end
|
#interpolations ⇒ Object
118
119
120
121
122
123
124
|
# File 'app/models/user.rb', line 118
def interpolations
{
'user_email' => email,
'user_first_name' => first_name,
'user_last_name' => last_name
}
end
|
#last_lesson ⇒ Object
36
37
38
|
# File 'app/models/user.rb', line 36
def last_lesson
last_guide.try(:lesson)
end
|
#never_submitted? ⇒ Boolean
72
73
74
|
# File 'app/models/user.rb', line 72
def never_submitted?
last_submission_date.nil?
end
|
#passed_assignments ⇒ Object
#passed_submissions_count ⇒ Object
44
45
46
|
# File 'app/models/user.rb', line 44
def passed_submissions_count
passed_assignments.count
end
|
#resubmit!(organization = nil) ⇒ Object
126
127
128
129
130
|
# File 'app/models/user.rb', line 126
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
52
53
54
|
# File 'app/models/user.rb', line 52
def solved_exercises_count
solved_exercises.count
end
|
#submissions_count ⇒ Object
40
41
42
|
# File 'app/models/user.rb', line 40
def submissions_count
assignments.pluck(:submissions_count).sum
end
|
#submitted_exercises_count ⇒ Object
48
49
50
|
# File 'app/models/user.rb', line 48
def submitted_exercises_count
submitted_exercises.count
end
|
#to_s ⇒ Object
68
69
70
|
# File 'app/models/user.rb', line 68
def to_s
"#{id}:#{name}:#{uid}"
end
|
#unread_messages ⇒ Object
60
61
62
|
# File 'app/models/user.rb', line 60
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
64
65
66
|
# File 'app/models/user.rb', line 64
def visit!(organization)
update!(last_organization: organization) if organization != last_organization
end
|