mumuki-classroom 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +661 -0
- data/README.md +371 -0
- data/Rakefile +29 -0
- data/lib/mumuki/classroom.rb +56 -0
- data/lib/mumuki/classroom/collection.rb +10 -0
- data/lib/mumuki/classroom/engine.rb +8 -0
- data/lib/mumuki/classroom/event.rb +4 -0
- data/lib/mumuki/classroom/event/user_changed.rb +54 -0
- data/lib/mumuki/classroom/locales/en.yml +3 -0
- data/lib/mumuki/classroom/locales/es-CL.yml +3 -0
- data/lib/mumuki/classroom/locales/es.yml +3 -0
- data/lib/mumuki/classroom/locales/pt.yml +3 -0
- data/lib/mumuki/classroom/models.rb +22 -0
- data/lib/mumuki/classroom/models/assignment.rb +148 -0
- data/lib/mumuki/classroom/models/concerns/course_member.rb +53 -0
- data/lib/mumuki/classroom/models/concerns/extensions.rb +90 -0
- data/lib/mumuki/classroom/models/concerns/with_failed_submission_reprocess.rb +74 -0
- data/lib/mumuki/classroom/models/concerns/with_submission_process.rb +148 -0
- data/lib/mumuki/classroom/models/document.rb +12 -0
- data/lib/mumuki/classroom/models/exercise.rb +7 -0
- data/lib/mumuki/classroom/models/failed_submission.rb +16 -0
- data/lib/mumuki/classroom/models/follower.rb +19 -0
- data/lib/mumuki/classroom/models/guide_progress.rb +57 -0
- data/lib/mumuki/classroom/models/last_assignment.rb +7 -0
- data/lib/mumuki/classroom/models/message.rb +32 -0
- data/lib/mumuki/classroom/models/notification.rb +52 -0
- data/lib/mumuki/classroom/models/reporting.rb +24 -0
- data/lib/mumuki/classroom/models/searching.rb +60 -0
- data/lib/mumuki/classroom/models/searching/guide_progress.rb +90 -0
- data/lib/mumuki/classroom/models/sorting.rb +92 -0
- data/lib/mumuki/classroom/models/sorting/guide_progress.rb +147 -0
- data/lib/mumuki/classroom/models/sorting/student.rb +45 -0
- data/lib/mumuki/classroom/models/sorting/total_stats_sort_by.rb +5 -0
- data/lib/mumuki/classroom/models/student.rb +88 -0
- data/lib/mumuki/classroom/models/submission.rb +62 -0
- data/lib/mumuki/classroom/models/suggestion.rb +35 -0
- data/lib/mumuki/classroom/models/teacher.rb +3 -0
- data/lib/mumuki/classroom/permissions_diff.rb +83 -0
- data/lib/mumuki/classroom/reports.rb +4 -0
- data/lib/mumuki/classroom/reports/formats.rb +35 -0
- data/lib/mumuki/classroom/sinatra.rb +301 -0
- data/lib/mumuki/classroom/sinatra/courses.rb +157 -0
- data/lib/mumuki/classroom/sinatra/errors.rb +13 -0
- data/lib/mumuki/classroom/sinatra/exams.rb +71 -0
- data/lib/mumuki/classroom/sinatra/followers.rb +29 -0
- data/lib/mumuki/classroom/sinatra/guides.rb +79 -0
- data/lib/mumuki/classroom/sinatra/manual_evaluation.rb +16 -0
- data/lib/mumuki/classroom/sinatra/massive.rb +206 -0
- data/lib/mumuki/classroom/sinatra/messages.rb +52 -0
- data/lib/mumuki/classroom/sinatra/notifications.rb +29 -0
- data/lib/mumuki/classroom/sinatra/organization.rb +7 -0
- data/lib/mumuki/classroom/sinatra/pagination.rb +13 -0
- data/lib/mumuki/classroom/sinatra/permissions.rb +9 -0
- data/lib/mumuki/classroom/sinatra/ping.rb +7 -0
- data/lib/mumuki/classroom/sinatra/searching.rb +27 -0
- data/lib/mumuki/classroom/sinatra/students.rb +111 -0
- data/lib/mumuki/classroom/sinatra/suggestions.rb +17 -0
- data/lib/mumuki/classroom/sinatra/teachers.rb +14 -0
- data/lib/mumuki/classroom/version.rb +5 -0
- data/lib/mumuki/profile.rb +17 -0
- data/lib/mumuki/views/threads.html.erb +43 -0
- data/lib/tasks/mumuki/messages.rake +20 -0
- data/lib/tasks/mumuki/resubmissions.rake +15 -0
- data/lib/tasks/mumuki/students.rake +31 -0
- data/lib/tasks/mumuki/submissions.rake +17 -0
- data/lib/tasks/mumuki/user_permissions.rake +17 -0
- metadata +291 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
class Mumuki::Classroom::Event::UserChanged
|
2
|
+
class << self
|
3
|
+
|
4
|
+
attr_accessor :changes
|
5
|
+
|
6
|
+
def execute!(user_h)
|
7
|
+
set_diff_permissions user_h
|
8
|
+
update_user_model user_h
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def update_user_model(user)
|
14
|
+
Organization.pluck(:name).each do |organization|
|
15
|
+
changes[organization]&.each do |change|
|
16
|
+
message = change.description
|
17
|
+
self.send message, organization, user, change.granted_slug if self.respond_to? message, true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_diff_permissions(user)
|
23
|
+
self.changes = Mumukit::Auth::Permissions::Diff.diff(user[:old_permissions], user[:new_permissions]).changes_by_organization
|
24
|
+
end
|
25
|
+
|
26
|
+
def student_added(organization, user, granted_slug)
|
27
|
+
uid = user[:uid]
|
28
|
+
students = Mumuki::Classroom::Student.where(organization: organization, course: granted_slug.to_s, uid: uid)
|
29
|
+
if students.exists?
|
30
|
+
students.first.attach!
|
31
|
+
else
|
32
|
+
student = Mumuki::Classroom::Student.attributes_from_uid uid
|
33
|
+
Mumuki::Classroom::Student.create! student.merge(organization: organization, course: granted_slug.to_s)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def student_removed(organization, user, granted_slug)
|
38
|
+
student = Mumuki::Classroom::Student.find_by!(organization: organization, course: granted_slug.to_s, uid: user[:uid])
|
39
|
+
student.detach!
|
40
|
+
end
|
41
|
+
|
42
|
+
def teacher_added(organization, user, granted_slug)
|
43
|
+
uid = user[:uid]
|
44
|
+
teacher = Mumuki::Classroom::Teacher.find_or_create_by!(organization: organization, course: granted_slug.to_s, uid: uid)
|
45
|
+
teacher.update_attributes!(Mumuki::Classroom::Teacher.attributes_from_uid(uid))
|
46
|
+
end
|
47
|
+
|
48
|
+
def teacher_removed(organization, user, granted_slug)
|
49
|
+
teacher = Mumuki::Classroom::Teacher.find_by!(organization: organization, course: granted_slug.to_s, uid: user[:uid])
|
50
|
+
teacher.destroy!
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative './models/concerns/extensions'
|
2
|
+
require_relative './models/concerns/with_submission_process'
|
3
|
+
require_relative './models/concerns/with_failed_submission_reprocess'
|
4
|
+
require_relative './models/concerns/course_member'
|
5
|
+
|
6
|
+
require_relative './models/document'
|
7
|
+
require_relative './models/message'
|
8
|
+
require_relative './models/submission'
|
9
|
+
require_relative './models/exercise'
|
10
|
+
require_relative './models/last_assignment'
|
11
|
+
require_relative './models/failed_submission'
|
12
|
+
require_relative './models/guide_progress'
|
13
|
+
require_relative './models/assignment'
|
14
|
+
require_relative './models/follower'
|
15
|
+
require_relative './models/student'
|
16
|
+
require_relative './models/teacher'
|
17
|
+
require_relative './models/notification'
|
18
|
+
require_relative './models/suggestion'
|
19
|
+
|
20
|
+
require_relative './models/sorting'
|
21
|
+
require_relative './models/searching'
|
22
|
+
require_relative './models/reporting'
|
@@ -0,0 +1,148 @@
|
|
1
|
+
class Mumuki::Classroom::Assignment < Mumuki::Classroom::Document
|
2
|
+
include Mongoid::Timestamps
|
3
|
+
|
4
|
+
field :guide, type: Hash
|
5
|
+
field :student, type: Hash
|
6
|
+
field :organization, type: String
|
7
|
+
field :course, type: Mumukit::Auth::Slug
|
8
|
+
embeds_one :exercise, class_name: 'Mumuki::Classroom::Exercise'
|
9
|
+
embeds_many :submissions, class_name: 'Mumuki::Classroom::Submission'
|
10
|
+
|
11
|
+
create_index({'organization': 1, 'course': 1, 'student.uid': 1})
|
12
|
+
create_index({'organization': 1, 'exercise.eid': 1, 'student.uid': 1})
|
13
|
+
create_index({'organization': 1, 'course': 1, 'guide.slug': 1, 'exercise.eid': 1, 'student.uid': 1})
|
14
|
+
create_index({'organization': 1, 'course': 1, 'guide.slug': 1, 'student.uid': 1, 'exercise.eid': 1})
|
15
|
+
create_index({'guide.slug': 1, 'exercise.eid': 1}, {name: 'ExBibIdIndex'})
|
16
|
+
|
17
|
+
def evaluate_manually!(sid, comment, status)
|
18
|
+
submission = submission(sid)
|
19
|
+
submission.evaluate_manually! comment, status
|
20
|
+
update_submissions!
|
21
|
+
end
|
22
|
+
|
23
|
+
def submission(sid)
|
24
|
+
submissions.find_by!(sid: sid)
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_message!(message, sid)
|
28
|
+
submission(sid).tap do |it|
|
29
|
+
it.add_message! message
|
30
|
+
update_submissions!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_submission!(submission)
|
35
|
+
self.submissions << Mumuki::Classroom::Submission.new(submission.as_json)
|
36
|
+
update_submissions!
|
37
|
+
end
|
38
|
+
|
39
|
+
def notify_message!(message, sid)
|
40
|
+
Mumukit::Nuntius.notify! 'teacher-messages', json_to_notify(message, sid)
|
41
|
+
end
|
42
|
+
|
43
|
+
def notify_manual_evaluation!(sid)
|
44
|
+
assignment = {submission_id: sid}.merge(submission(sid).as_json only: [:status, :manual_evaluation])
|
45
|
+
Mumukit::Nuntius.notify_event!('AssignmentManuallyEvaluated', {assignment: assignment}, {sender: :classroom})
|
46
|
+
end
|
47
|
+
|
48
|
+
def json_to_notify(message, sid)
|
49
|
+
{
|
50
|
+
message: message,
|
51
|
+
submission_id: sid,
|
52
|
+
exercise_id: exercise.eid,
|
53
|
+
organization: organization
|
54
|
+
}.as_json
|
55
|
+
end
|
56
|
+
|
57
|
+
def threads(language)
|
58
|
+
language = guide[:language][:name] if language.blank?
|
59
|
+
submissions.map { |it| it.thread(language) }.compact
|
60
|
+
end
|
61
|
+
|
62
|
+
def with_full_messages(user)
|
63
|
+
self[:submissions] = submissions.map { |it| it.with_full_messages user }
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_message_to_submission!(message, sid)
|
68
|
+
submission = add_message! message, sid
|
69
|
+
notify_message! message, sid
|
70
|
+
submission
|
71
|
+
end
|
72
|
+
|
73
|
+
def notification_preview
|
74
|
+
as_json(
|
75
|
+
only: %i(course exercise guide student),
|
76
|
+
include: {
|
77
|
+
exercise: {
|
78
|
+
only: %i(eid name)
|
79
|
+
},
|
80
|
+
guide: {
|
81
|
+
only: %i(slug)
|
82
|
+
},
|
83
|
+
student: {
|
84
|
+
only: %i(first_name last_name image_url uid)
|
85
|
+
}
|
86
|
+
}
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def update_submissions!
|
93
|
+
update_attributes! submissions: submissions
|
94
|
+
end
|
95
|
+
|
96
|
+
class << self
|
97
|
+
def detach_all_by!(query)
|
98
|
+
where(query).set(detached: true)
|
99
|
+
end
|
100
|
+
|
101
|
+
def attach_all_by!(query)
|
102
|
+
where(query).unset(:detached)
|
103
|
+
end
|
104
|
+
|
105
|
+
def destroy_all_by!(query)
|
106
|
+
where(query).destroy
|
107
|
+
end
|
108
|
+
|
109
|
+
def transfer_all_by!(query, new_organization, new_course)
|
110
|
+
where(query).set(organization: new_organization, course: new_course)
|
111
|
+
end
|
112
|
+
|
113
|
+
def empty_stats
|
114
|
+
{passed: 0, failed: 0, passed_with_warnings: 0}
|
115
|
+
end
|
116
|
+
|
117
|
+
def with_full_messages(query, user)
|
118
|
+
where(query)
|
119
|
+
.map { |assignment| assignment.with_full_messages(user) }
|
120
|
+
end
|
121
|
+
|
122
|
+
def items_to_review(query, exercises)
|
123
|
+
passed_exercises_ids = where(query)
|
124
|
+
.map { |assignment| [assignment.exercise.eid, assignment.submissions.max_by(&:created_at)] }
|
125
|
+
.map { |eid, submission| eid if solved?(submission.status) }
|
126
|
+
exercises.reject { |exercise| passed_exercises_ids.include? exercise[:id] }
|
127
|
+
.pluck(:tag_list, :language)
|
128
|
+
.flatten
|
129
|
+
.uniq
|
130
|
+
end
|
131
|
+
|
132
|
+
def solved?(status)
|
133
|
+
status.passed? || status.skipped?
|
134
|
+
end
|
135
|
+
|
136
|
+
def stats_by(query)
|
137
|
+
stats = where(query)
|
138
|
+
.map { |assignment| assignment.submissions.max_by(&:created_at) }
|
139
|
+
.group_by { |submission| submission.status }
|
140
|
+
.map { |status, submissions| [status.to_sym, submissions.size] }
|
141
|
+
.to_h.compact
|
142
|
+
stats = empty_stats.merge(stats)
|
143
|
+
stats[:failed] += stats.delete(:errored) || 0
|
144
|
+
stats.slice(*empty_stats.keys)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module CourseMember
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
include Mongoid::Timestamps
|
6
|
+
|
7
|
+
field :uid, type: String
|
8
|
+
field :first_name, type: String
|
9
|
+
field :last_name, type: String
|
10
|
+
field :image_url, type: String
|
11
|
+
field :name, type: String
|
12
|
+
field :email, type: String
|
13
|
+
field :social_id, type: String
|
14
|
+
field :organization, type: String
|
15
|
+
field :course, type: Mumukit::Auth::Slug
|
16
|
+
|
17
|
+
create_index({organization: 1, course: 1, uid: 1}, {unique: true})
|
18
|
+
end
|
19
|
+
|
20
|
+
def as_user(verified: true)
|
21
|
+
member_json = as_json.merge_if(verified, validated_first_name: first_name, validated_last_name: last_name)
|
22
|
+
User.whitelist_attributes member_json
|
23
|
+
end
|
24
|
+
|
25
|
+
class_methods do
|
26
|
+
def ensure_not_exists!(query)
|
27
|
+
existing_members = where(query)
|
28
|
+
raise Mumuki::Classroom::CourseMemberExistsError, {existing_members: existing_members.map(&:uid)}.to_json if existing_members.exists?
|
29
|
+
end
|
30
|
+
|
31
|
+
def attributes_from_uid(uid)
|
32
|
+
whitelist_attributes User.locate!(uid).to_resource_h
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_from_json!(member_json)
|
36
|
+
create! normalized_attributes_from_json(member_json)
|
37
|
+
end
|
38
|
+
|
39
|
+
def normalized_attributes_from_json(member_json)
|
40
|
+
whitelist_attributes as_normalized_json(member_json)
|
41
|
+
end
|
42
|
+
|
43
|
+
def as_normalized_json(member = {})
|
44
|
+
member.as_json.merge uid: (member[:uid] || member[:email])&.downcase,
|
45
|
+
email: member[:email]&.downcase,
|
46
|
+
last_name: member[:last_name]&.downcase&.titleize,
|
47
|
+
first_name: member[:first_name]&.downcase&.titleize
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Mumuki::Classroom::CourseMemberExistsError < Exception
|
53
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Document
|
3
|
+
|
4
|
+
def as_json(options = {})
|
5
|
+
super(options).as_json(except: ['_id', :_id]).deep_compact.with_indifferent_access
|
6
|
+
end
|
7
|
+
|
8
|
+
def upsert_attributes(attrs)
|
9
|
+
assign_attributes(attrs)
|
10
|
+
upsert
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def create_index(*args)
|
15
|
+
index *args
|
16
|
+
Mumuki::Classroom.register_index! self
|
17
|
+
end
|
18
|
+
|
19
|
+
def drop_index(index_name)
|
20
|
+
collection.indexes.drop_one(index_name) if has_index_named?(index_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_index_named?(index_name)
|
24
|
+
collection.indexes.any? { |spec| spec['name'] == index_name }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
class Hash
|
33
|
+
def deep_compact
|
34
|
+
compact
|
35
|
+
each_pair do |k, v|
|
36
|
+
if self[k].respond_to? :deep_compact
|
37
|
+
self[k].deep_compact
|
38
|
+
end
|
39
|
+
self.delete(k) if self[k].nil?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def merge_unless(criterion, hash)
|
44
|
+
return merge hash unless criterion
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def merge_if(criterion, hash)
|
49
|
+
return merge hash if criterion
|
50
|
+
self
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
class Array
|
56
|
+
def deep_compact
|
57
|
+
compact
|
58
|
+
each do |e|
|
59
|
+
if e.respond_to? :deep_compact
|
60
|
+
e.deep_compact
|
61
|
+
end
|
62
|
+
self.delete(e) if e.nil?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
class String
|
69
|
+
def boolean_value
|
70
|
+
downcase.strip == 'true'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class TrueClass
|
75
|
+
def boolean_value
|
76
|
+
self
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class FalseClass
|
81
|
+
def boolean_value
|
82
|
+
self
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class NilClass
|
87
|
+
def boolean_value
|
88
|
+
false
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module WithFailedSubmissionReprocess
|
2
|
+
|
3
|
+
def reprocess!(uid, destination)
|
4
|
+
reprocess_from_organization uid, destination, destination
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def reprocess_from_organization(uid, source, destination)
|
10
|
+
Mumuki::Classroom::FailedSubmission.for(source).find_by_uid(uid).each do |failed_submission|
|
11
|
+
delete_failed_submission failed_submission, source
|
12
|
+
try_reprocess failed_submission, source, destination
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def try_reprocess(failed_submission, source, destination)
|
17
|
+
begin
|
18
|
+
reprocess_failed_submission destination, failed_submission
|
19
|
+
rescue => e
|
20
|
+
Mumukit::Nuntius::Logger.warn "Resubmission failed #{e}. it was: #{failed_submission.as_json}"
|
21
|
+
insert_failed_submission failed_submission, source
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def insert_failed_submission(failed_submission, source)
|
26
|
+
Mumuki::Classroom::FailedSubmission.create! failed_submission.as_json.merge(organization: source)
|
27
|
+
end
|
28
|
+
|
29
|
+
def reprocess_failed_submission(destination, it)
|
30
|
+
json = it.as_json
|
31
|
+
json['organization'] = destination
|
32
|
+
Mumuki::Classroom::Submission.process! json
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_failed_submission(it, source)
|
36
|
+
Mumuki::Classroom::FailedSubmission.for(source).where(_id: it._id).destroy_all
|
37
|
+
end
|
38
|
+
|
39
|
+
def new_failed_submission(progress, submission)
|
40
|
+
submission.merge({
|
41
|
+
exercise: exercise_from(progress[:exercise]),
|
42
|
+
guide: guide_from(progress[:guide]),
|
43
|
+
submitter: submitter_from(progress[:student])
|
44
|
+
})
|
45
|
+
end
|
46
|
+
|
47
|
+
def submitter_from(student)
|
48
|
+
{
|
49
|
+
uid: student[:uid],
|
50
|
+
name: student[:name],
|
51
|
+
email: student[:email],
|
52
|
+
social_id: student[:social_id],
|
53
|
+
image_url: student[:image_url]
|
54
|
+
}.compact
|
55
|
+
end
|
56
|
+
|
57
|
+
def guide_from(guide)
|
58
|
+
{
|
59
|
+
name: guide[:name],
|
60
|
+
slug: guide[:slug],
|
61
|
+
parent: guide[:parent],
|
62
|
+
lesson: guide[:lesson],
|
63
|
+
language: guide[:language]
|
64
|
+
}.compact
|
65
|
+
end
|
66
|
+
|
67
|
+
def exercise_from(exercise)
|
68
|
+
{
|
69
|
+
eid: exercise[:eid],
|
70
|
+
name: exercise[:name],
|
71
|
+
number: exercise[:number]
|
72
|
+
}.compact
|
73
|
+
end
|
74
|
+
end
|