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!
Class Method Details
.create_if_necessary(user) ⇒ Object
119
120
121
122
|
# File 'app/models/user.rb', line 119
def self.create_if_necessary(user)
user[:uid] ||= user[:email]
where(uid: user[:uid]).first_or_create(user)
end
|
.import_from_json!(json) ⇒ Object
96
97
98
99
|
# File 'app/models/user.rb', line 96
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
105
106
107
|
# File 'app/models/user.rb', line 105
def self.unsubscription_verifier
Rails.application.message_verifier(:unsubscribe)
end
|
Instance Method Details
#accept_invitation!(invitation) ⇒ Object
80
81
82
|
# File 'app/models/user.rb', line 80
def accept_invitation!(invitation)
make_student_of! invitation.course
end
|
#attach!(role, course) ⇒ Object
109
110
111
112
|
# File 'app/models/user.rb', line 109
def attach!(role, course)
add_permission! role, course.slug
save_and_notify!
end
|
#clear_progress! ⇒ Object
73
74
75
76
77
78
|
# File 'app/models/user.rb', line 73
def clear_progress!
transaction do
update! last_submission_date: nil, last_exercise: nil
assignments.destroy_all
end
end
|
#copy_progress_to!(another) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'app/models/user.rb', line 84
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
|
#detach!(role, course) ⇒ Object
114
115
116
117
|
# File 'app/models/user.rb', line 114
def detach!(role, course)
remove_permission! role, course.slug
save_and_notify!
end
|
#interpolations ⇒ Object
124
125
126
127
128
129
130
|
# File 'app/models/user.rb', line 124
def interpolations
{
'user_email' => email,
'user_first_name' => first_name,
'user_last_name' => last_name
}
end
|
#last_lesson ⇒ Object
33
34
35
|
# File 'app/models/user.rb', line 33
def last_lesson
last_guide.try(:lesson)
end
|
#never_submitted? ⇒ Boolean
69
70
71
|
# File 'app/models/user.rb', line 69
def never_submitted?
last_submission_date.nil?
end
|
#passed_assignments ⇒ Object
#passed_submissions_count ⇒ Object
41
42
43
|
# File 'app/models/user.rb', line 41
def passed_submissions_count
passed_assignments.count
end
|
#resubmit!(organization = nil) ⇒ Object
132
133
134
135
136
|
# File 'app/models/user.rb', line 132
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
49
50
51
|
# File 'app/models/user.rb', line 49
def solved_exercises_count
solved_exercises.count
end
|
#submissions_count ⇒ Object
37
38
39
|
# File 'app/models/user.rb', line 37
def submissions_count
assignments.pluck(:submissions_count).sum
end
|
#submitted_exercises_count ⇒ Object
45
46
47
|
# File 'app/models/user.rb', line 45
def submitted_exercises_count
submitted_exercises.count
end
|
#to_s ⇒ Object
65
66
67
|
# File 'app/models/user.rb', line 65
def to_s
"#{id}:#{name}:#{uid}"
end
|
#unread_messages ⇒ Object
57
58
59
|
# File 'app/models/user.rb', line 57
def unread_messages
messages.where read: false
end
|
#unsubscribe_from_reminders! ⇒ Object
101
102
103
|
# File 'app/models/user.rb', line 101
def unsubscribe_from_reminders!
update! accepts_reminders: false
end
|
#visit!(organization) ⇒ Object
61
62
63
|
# File 'app/models/user.rb', line 61
def visit!(organization)
update!(last_organization: organization) if organization != last_organization
end
|