mumuki-domain 8.5.0 → 9.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/application_record.rb +6 -0
- data/app/models/assignment.rb +2 -2
- data/app/models/book.rb +1 -1
- data/app/models/certificate.rb +29 -0
- data/app/models/certificate_program.rb +42 -0
- data/app/models/concerns/with_assignments.rb +2 -3
- data/app/models/concerns/with_assignments_batch.rb +2 -2
- data/app/models/concerns/with_generated_code.rb +19 -0
- data/app/models/concerns/with_notifications.rb +17 -0
- data/app/models/course.rb +26 -2
- data/app/models/discussion.rb +5 -1
- data/app/models/exam_authorization_request.rb +7 -0
- data/app/models/exam_registration.rb +9 -1
- data/app/models/exercise.rb +13 -0
- data/app/models/guide.rb +1 -10
- data/app/models/invitation.rb +7 -11
- data/app/models/message.rb +4 -0
- data/app/models/notification.rb +4 -0
- data/app/models/organization.rb +5 -1
- data/app/models/topic.rb +7 -12
- data/app/models/user.rb +28 -5
- data/app/models/user_stats.rb +32 -0
- data/db/migrate/20210119174504_create_certificate_programs.rb +13 -0
- data/db/migrate/20210119174835_create_certificates.rb +13 -0
- data/db/migrate/20210301210530_add_period_start_and_end_to_course.rb +7 -0
- data/db/migrate/20210302181654_add_faqs_to_organizations.rb +5 -0
- data/lib/mumuki/domain/factories.rb +3 -0
- data/lib/mumuki/domain/factories/book_factory.rb +13 -0
- data/lib/mumuki/domain/factories/certificate_factory.rb +8 -0
- data/lib/mumuki/domain/factories/certificate_program_factory.rb +7 -0
- data/lib/mumuki/domain/factories/notification_factory.rb +5 -0
- data/lib/mumuki/domain/factories/organization_factory.rb +2 -1
- data/lib/mumuki/domain/helpers/course.rb +1 -1
- data/lib/mumuki/domain/incognito.rb +3 -0
- data/lib/mumuki/domain/organization/settings.rb +2 -2
- data/lib/mumuki/domain/version.rb +1 -1
- metadata +15 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07771f9e0e712988ad05c336cabef30fea9af24bbfd6da99dc48d7ab19aee1ba
|
4
|
+
data.tar.gz: 52c848e349daf6f371daf73d5ef675c06af6da0eee19ce25f6329db5ff5a9383
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 556d16f80533171f7e67f9652f84c955a5d9f8d7efdd981ec7b141afb845f4bb880c391486c2a5f2adad434410c0a789a1552b0dd1019d22b24ee149d335c1e7
|
7
|
+
data.tar.gz: 00cbc6852719e47a496f2bb2569cd98db9499df559bc9958ca6e482b3ece6c03498540b65cb38c8e0bee813c70e10eeca7ed2c87fc70c80d1a59bc9b407efee0
|
@@ -129,6 +129,12 @@ class ApplicationRecord < ActiveRecord::Base
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
+
def self.enum_prefixed_translations_for(selector)
|
133
|
+
send(selector.to_s.pluralize).map do |key, _|
|
134
|
+
[I18n.t("#{selector}_#{key}", default: key.to_sym), key]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
132
138
|
private
|
133
139
|
|
134
140
|
def raise_foreign_key_error!
|
data/app/models/assignment.rb
CHANGED
@@ -275,11 +275,11 @@ class Assignment < Progress
|
|
275
275
|
|
276
276
|
def update_submissions_count!
|
277
277
|
self.class.connection.execute(
|
278
|
-
"update
|
278
|
+
"update exercises
|
279
279
|
set submissions_count = submissions_count + 1
|
280
280
|
where id = #{exercise.id}")
|
281
281
|
self.class.connection.execute(
|
282
|
-
"update
|
282
|
+
"update assignments
|
283
283
|
set submissions_count = submissions_count + 1
|
284
284
|
where id = #{id}")
|
285
285
|
exercise.reload
|
data/app/models/book.rb
CHANGED
@@ -18,7 +18,7 @@ class Book < Content
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def discussions_in_organization(organization = Organization.current)
|
21
|
-
Discussion.where(organization: organization).includes(exercise: [:language, :guide])
|
21
|
+
Discussion.where(organization: organization, item: organization.exercises).includes(exercise: [:language, :guide])
|
22
22
|
end
|
23
23
|
|
24
24
|
def first_chapter
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Certificate < ApplicationRecord
|
2
|
+
include WithGeneratedCode
|
3
|
+
|
4
|
+
belongs_to :user
|
5
|
+
belongs_to :certificate_program
|
6
|
+
|
7
|
+
has_one :organization, through: :certificate_program
|
8
|
+
|
9
|
+
delegate :title, :description, :template_html_erb, :background_image_url, to: :certificate_program
|
10
|
+
|
11
|
+
def self.code_size
|
12
|
+
12
|
13
|
+
end
|
14
|
+
|
15
|
+
def filename
|
16
|
+
"#{title.parameterize.underscore}.pdf"
|
17
|
+
end
|
18
|
+
|
19
|
+
def template_locals
|
20
|
+
{ user: user,
|
21
|
+
certificate_program: certificate_program,
|
22
|
+
organization: organization,
|
23
|
+
certificate: self }
|
24
|
+
end
|
25
|
+
|
26
|
+
def for_user?(user)
|
27
|
+
self.user == user
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class CertificateProgram < ApplicationRecord
|
2
|
+
belongs_to :organization
|
3
|
+
has_many :certificates
|
4
|
+
|
5
|
+
def friendly
|
6
|
+
title
|
7
|
+
end
|
8
|
+
|
9
|
+
def template_html_erb
|
10
|
+
self[:template_html_erb] ||= <<HTML
|
11
|
+
<style>
|
12
|
+
.qr-code {
|
13
|
+
bottom: 5px;
|
14
|
+
right: 5px;
|
15
|
+
height: 15mm;
|
16
|
+
width: 15mm;
|
17
|
+
}
|
18
|
+
.name {
|
19
|
+
position: absolute;
|
20
|
+
width: 100%;
|
21
|
+
top: 380px;
|
22
|
+
text-align: center;
|
23
|
+
}
|
24
|
+
</style>
|
25
|
+
<!-- You can use interpolations like --
|
26
|
+
<%#= certificate.start_date %>
|
27
|
+
<%#= certificate.end_date %>
|
28
|
+
<%#= user.formal_first_name %>
|
29
|
+
<%#= user.formal_last_name %>
|
30
|
+
<%#= user.formal_full_name %>
|
31
|
+
<%#= certificate_program.title %>
|
32
|
+
<%#= certificate_program.description %>
|
33
|
+
<%#= organization.name %>
|
34
|
+
<%#= organization.display_name %>
|
35
|
+
-- -->
|
36
|
+
<section class="name">
|
37
|
+
<h1><%= user.formal_full_name %></h1>
|
38
|
+
</section>
|
39
|
+
HTML
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -19,9 +19,8 @@ module WithAssignments
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# TODO: When the organization is used in this one, please change guide.pending_exercises
|
22
|
-
|
23
|
-
|
24
|
-
assignments.find_by(submitter: user)
|
22
|
+
def find_assignment_for(user, organization)
|
23
|
+
assignments.find_by(submitter: user, organization: organization)
|
25
24
|
end
|
26
25
|
|
27
26
|
def status_for(user)
|
@@ -4,13 +4,13 @@
|
|
4
4
|
module WithAssignmentsBatch
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
def find_assignments_for(user,
|
7
|
+
def find_assignments_for(user, organization = Organization.current, &block)
|
8
8
|
block = block_given? ? block : lambda { |it, _e| it }
|
9
9
|
|
10
10
|
return exercises.map { |it| block.call nil, it } unless user
|
11
11
|
|
12
12
|
pairs = exercises.map { |it| [it.id, [nil, it]] }.to_h
|
13
|
-
Assignment.where(submitter: user, exercise: exercises).each do |it|
|
13
|
+
Assignment.where(submitter: user, organization: organization, exercise: exercises).each do |it|
|
14
14
|
pairs[it.exercise_id][0] = it
|
15
15
|
end
|
16
16
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WithGeneratedCode
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
validates_uniqueness_of :code
|
6
|
+
|
7
|
+
defaults do
|
8
|
+
self.code ||= self.class.generate_code
|
9
|
+
end
|
10
|
+
|
11
|
+
required :code_size
|
12
|
+
end
|
13
|
+
|
14
|
+
class_methods do
|
15
|
+
def generate_code
|
16
|
+
SecureRandom.urlsafe_base64 code_size
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module WithNotifications
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
def unread_messages
|
5
|
+
messages_in_organization.where read: false
|
6
|
+
end
|
7
|
+
|
8
|
+
def unread_notifications
|
9
|
+
# TODO: message and discussion should trigger a notification instead of being one
|
10
|
+
all = notifications.where(read: false) + unread_messages + unread_discussions
|
11
|
+
all.sort_by(&:created_at).reverse
|
12
|
+
end
|
13
|
+
|
14
|
+
def read_notification!(target)
|
15
|
+
notifications.find_by(target: target)&.mark_as_read!
|
16
|
+
end
|
17
|
+
end
|
data/app/models/course.rb
CHANGED
@@ -3,7 +3,7 @@ class Course < ApplicationRecord
|
|
3
3
|
include Mumuki::Domain::Helpers::Course
|
4
4
|
include Mumuki::Domain::Area
|
5
5
|
|
6
|
-
validates_presence_of :slug, :
|
6
|
+
validates_presence_of :slug, :period, :code, :description, :organization_id
|
7
7
|
validates_uniqueness_of :slug
|
8
8
|
belongs_to :organization
|
9
9
|
|
@@ -11,7 +11,7 @@ class Course < ApplicationRecord
|
|
11
11
|
|
12
12
|
alias_attribute :name, :code
|
13
13
|
|
14
|
-
resource_fields :slug, :shifts, :code, :days, :period, :description
|
14
|
+
resource_fields :slug, :shifts, :code, :days, :period, :description, :period_start, :period_end
|
15
15
|
|
16
16
|
def current_invitation
|
17
17
|
invitations.where('expiration_date > ?', Time.now).first
|
@@ -35,6 +35,30 @@ class Course < ApplicationRecord
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def ended?
|
39
|
+
period_end.present? && period_end.past?
|
40
|
+
end
|
41
|
+
|
42
|
+
def started?
|
43
|
+
period_start.present? && period_start.past?
|
44
|
+
end
|
45
|
+
|
46
|
+
def infer_period_range!
|
47
|
+
return if period_start || period_end
|
48
|
+
|
49
|
+
period =~ /^(\d{4})?/
|
50
|
+
year = $1.to_i
|
51
|
+
|
52
|
+
return nil unless year.between? 2014, (DateTime.now.year + 1)
|
53
|
+
|
54
|
+
self.period_start = DateTime.new(year).beginning_of_year
|
55
|
+
self.period_end = DateTime.new(year).end_of_year
|
56
|
+
end
|
57
|
+
|
58
|
+
def canonical_code
|
59
|
+
"#{period}-#{code}".downcase
|
60
|
+
end
|
61
|
+
|
38
62
|
def closed?
|
39
63
|
current_invitation.blank? || current_invitation.expired?
|
40
64
|
end
|
data/app/models/discussion.rb
CHANGED
@@ -48,6 +48,10 @@ class Discussion < ApplicationRecord
|
|
48
48
|
nil
|
49
49
|
end
|
50
50
|
|
51
|
+
def target
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
51
55
|
def used_in?(organization)
|
52
56
|
organization == self.organization
|
53
57
|
end
|
@@ -163,7 +167,7 @@ class Discussion < ApplicationRecord
|
|
163
167
|
end
|
164
168
|
|
165
169
|
def being_accessed_by_moderator?
|
166
|
-
last_moderator_access_at.present? && last_moderator_access_at
|
170
|
+
last_moderator_access_at.present? && last_moderator_access_at.future? - MODERATOR_REVIEW_AVERAGE_TIME
|
167
171
|
end
|
168
172
|
|
169
173
|
def last_moderator_access_visible_for?(user)
|
@@ -1,7 +1,10 @@
|
|
1
1
|
class ExamAuthorizationRequest < ApplicationRecord
|
2
|
+
include TerminalNavigation
|
3
|
+
|
2
4
|
belongs_to :exam
|
3
5
|
belongs_to :user
|
4
6
|
belongs_to :organization
|
7
|
+
belongs_to :exam_registration
|
5
8
|
|
6
9
|
enum status: %i(pending approved rejected)
|
7
10
|
|
@@ -11,6 +14,10 @@ class ExamAuthorizationRequest < ApplicationRecord
|
|
11
14
|
exam.authorize! user if approved?
|
12
15
|
end
|
13
16
|
|
17
|
+
def name
|
18
|
+
exam_registration.description
|
19
|
+
end
|
20
|
+
|
14
21
|
private
|
15
22
|
|
16
23
|
def notify_user!
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class ExamRegistration < ApplicationRecord
|
2
2
|
include WithTimedEnablement
|
3
|
+
include TerminalNavigation
|
3
4
|
|
4
5
|
belongs_to :organization
|
5
6
|
has_and_belongs_to_many :exams
|
6
|
-
has_many :authorization_requests, class_name: 'ExamAuthorizationRequest'
|
7
|
+
has_many :authorization_requests, class_name: 'ExamAuthorizationRequest'
|
7
8
|
|
8
9
|
enum authorization_criterion_type: %i(none passed_exercises), _prefix: :authorization_criterion
|
9
10
|
|
@@ -11,6 +12,8 @@ class ExamRegistration < ApplicationRecord
|
|
11
12
|
|
12
13
|
delegate :meets_authorization_criteria?, :process_request!, to: :authorization_criterion
|
13
14
|
|
15
|
+
alias_attribute :name, :description
|
16
|
+
|
14
17
|
def authorization_criterion
|
15
18
|
@authorization_criterion ||= ExamRegistration::AuthorizationCriterion.parse(authorization_criterion_type, authorization_criterion_value)
|
16
19
|
end
|
@@ -30,6 +33,11 @@ class ExamRegistration < ApplicationRecord
|
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
36
|
+
def authorization_request_for(user)
|
37
|
+
authorization_requests.find_by(user: user) ||
|
38
|
+
ExamAuthorizationRequest.new(exam_registration: self, organization: organization)
|
39
|
+
end
|
40
|
+
|
33
41
|
private
|
34
42
|
|
35
43
|
def notify_user!(user)
|
data/app/models/exercise.rb
CHANGED
@@ -267,4 +267,17 @@ class Exercise < ApplicationRecord
|
|
267
267
|
def self.default_layout
|
268
268
|
layouts.keys[0]
|
269
269
|
end
|
270
|
+
|
271
|
+
def self.with_pending_assignments_for(user, relation)
|
272
|
+
relation.
|
273
|
+
joins("left join assignments assignments
|
274
|
+
on assignments.exercise_id = exercises.id
|
275
|
+
and assignments.submitter_id = #{user.id}
|
276
|
+
and assignments.organization_id = #{Organization.current.id}
|
277
|
+
and assignments.submission_status in (
|
278
|
+
#{Mumuki::Domain::Status::Submission::Passed.to_i},
|
279
|
+
#{Mumuki::Domain::Status::Submission::ManualEvaluationPending.to_i}
|
280
|
+
)").
|
281
|
+
where('assignments.id is null')
|
282
|
+
end
|
270
283
|
end
|
data/app/models/guide.rb
CHANGED
@@ -50,17 +50,8 @@ class Guide < Content
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
# TODO: Make use of pending_siblings logic
|
54
53
|
def pending_exercises(user)
|
55
|
-
exercises
|
56
|
-
joins("left join public.assignments assignments
|
57
|
-
on assignments.exercise_id = exercises.id
|
58
|
-
and assignments.submitter_id = #{user.id}
|
59
|
-
and assignments.submission_status in (
|
60
|
-
#{Mumuki::Domain::Status::Submission::Passed.to_i},
|
61
|
-
#{Mumuki::Domain::Status::Submission::ManualEvaluationPending.to_i}
|
62
|
-
)").
|
63
|
-
where('assignments.id is null')
|
54
|
+
Exercise.with_pending_assignments_for(user, exercises)
|
64
55
|
end
|
65
56
|
|
66
57
|
def first_exercise
|
data/app/models/invitation.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
class Invitation < ApplicationRecord
|
2
|
-
include Mumuki::Domain::Syncable
|
2
|
+
include Mumuki::Domain::Syncable,
|
3
|
+
WithGeneratedCode
|
3
4
|
|
4
5
|
belongs_to :course
|
5
6
|
|
6
7
|
validate :ensure_not_expired, on: :create
|
7
|
-
validates_uniqueness_of :code
|
8
|
-
|
9
|
-
defaults do
|
10
|
-
self.code ||= self.class.generate_code
|
11
|
-
end
|
12
8
|
|
13
9
|
def ensure_not_expired
|
14
10
|
errors.add(:base, :invitation_expired) if expired?
|
@@ -43,7 +39,7 @@ class Invitation < ApplicationRecord
|
|
43
39
|
end
|
44
40
|
|
45
41
|
def expired?
|
46
|
-
|
42
|
+
expiration_date.past?
|
47
43
|
end
|
48
44
|
|
49
45
|
def unexpired
|
@@ -51,12 +47,12 @@ class Invitation < ApplicationRecord
|
|
51
47
|
self
|
52
48
|
end
|
53
49
|
|
54
|
-
def self.generate_code
|
55
|
-
SecureRandom.urlsafe_base64 4
|
56
|
-
end
|
57
|
-
|
58
50
|
private
|
59
51
|
|
52
|
+
def self.code_size
|
53
|
+
4
|
54
|
+
end
|
55
|
+
|
60
56
|
def course_name
|
61
57
|
course.name
|
62
58
|
end
|
data/app/models/message.rb
CHANGED
data/app/models/notification.rb
CHANGED
data/app/models/organization.rb
CHANGED
@@ -11,7 +11,7 @@ class Organization < ApplicationRecord
|
|
11
11
|
serialize :settings, Mumuki::Domain::Organization::Settings
|
12
12
|
serialize :theme, Mumuki::Domain::Organization::Theme
|
13
13
|
|
14
|
-
markdown_on :description, :display_description, :page_description
|
14
|
+
markdown_on :description, :display_description, :page_description, :faqs
|
15
15
|
teaser_on :display_description
|
16
16
|
|
17
17
|
validate :ensure_consistent_public_login
|
@@ -138,6 +138,10 @@ class Organization < ApplicationRecord
|
|
138
138
|
self[:progressive_display_lookahead] = lookahead.to_i.positive? ? lookahead : nil
|
139
139
|
end
|
140
140
|
|
141
|
+
def activity_start_date(default_date)
|
142
|
+
[default_date, in_preparation_until&.to_date].compact.max
|
143
|
+
end
|
144
|
+
|
141
145
|
# ==============
|
142
146
|
# Display fields
|
143
147
|
# ==============
|
data/app/models/topic.rb
CHANGED
@@ -50,18 +50,13 @@ class Topic < Content
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def pending_lessons(user)
|
53
|
-
|
54
|
-
.
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
and assignments.submission_status in (
|
61
|
-
#{Mumuki::Domain::Status::Submission::Passed.to_i},
|
62
|
-
#{Mumuki::Domain::Status::Submission::ManualEvaluationPending.to_i}
|
63
|
-
)")
|
64
|
-
.where('assignments.id is null')
|
53
|
+
Exercise
|
54
|
+
.with_pending_assignments_for(
|
55
|
+
user,
|
56
|
+
lessons
|
57
|
+
.includes(:guide)
|
58
|
+
.references(:guide)
|
59
|
+
.joins('left join exercises exercises on exercises.guide_id = guides.id'))
|
65
60
|
.group('guides.id', 'lessons.number', 'lessons.id')
|
66
61
|
end
|
67
62
|
|
data/app/models/user.rb
CHANGED
@@ -3,6 +3,7 @@ class User < ApplicationRecord
|
|
3
3
|
include WithProfile,
|
4
4
|
WithUserNavigation,
|
5
5
|
WithReminders,
|
6
|
+
WithNotifications,
|
6
7
|
WithDiscussionCreation,
|
7
8
|
Awardee,
|
8
9
|
Disabling,
|
@@ -34,6 +35,8 @@ class User < ApplicationRecord
|
|
34
35
|
|
35
36
|
has_many :exams, through: :exam_authorizations
|
36
37
|
|
38
|
+
has_many :certificates
|
39
|
+
|
37
40
|
enum gender: %i(female male other unspecified)
|
38
41
|
belongs_to :avatar, polymorphic: true, optional: true
|
39
42
|
|
@@ -51,6 +54,10 @@ class User < ApplicationRecord
|
|
51
54
|
last_guide.try(:lesson)
|
52
55
|
end
|
53
56
|
|
57
|
+
def messages_in_organization(organization = Organization.current)
|
58
|
+
messages.where('assignments.organization': organization)
|
59
|
+
end
|
60
|
+
|
54
61
|
def passed_submissions_count_in(organization)
|
55
62
|
assignments.where(top_submission_status: Mumuki::Domain::Status::Submission::Passed.to_i, organization: organization).count
|
56
63
|
end
|
@@ -75,10 +82,6 @@ class User < ApplicationRecord
|
|
75
82
|
assignments.where(status: Mumuki::Domain::Status::Submission::Passed.to_i)
|
76
83
|
end
|
77
84
|
|
78
|
-
def unread_messages
|
79
|
-
messages.where read: false
|
80
|
-
end
|
81
|
-
|
82
85
|
def visit!(organization)
|
83
86
|
update!(last_organization: organization) if organization != last_organization
|
84
87
|
end
|
@@ -220,7 +223,7 @@ class User < ApplicationRecord
|
|
220
223
|
end
|
221
224
|
|
222
225
|
def next_exercise_at(guide)
|
223
|
-
guide.pending_exercises(self).order('
|
226
|
+
guide.pending_exercises(self).order('exercises.number asc').first
|
224
227
|
end
|
225
228
|
|
226
229
|
def run_submission!(submission, assignment, evaluation)
|
@@ -278,6 +281,26 @@ class User < ApplicationRecord
|
|
278
281
|
end
|
279
282
|
end
|
280
283
|
|
284
|
+
def formal_first_name
|
285
|
+
verified_first_name || first_name
|
286
|
+
end
|
287
|
+
|
288
|
+
def formal_last_name
|
289
|
+
verified_last_name || last_name
|
290
|
+
end
|
291
|
+
|
292
|
+
def formal_full_name
|
293
|
+
"#{formal_first_name} #{formal_last_name}"
|
294
|
+
end
|
295
|
+
|
296
|
+
def certificates_in_organization(organization = Organization.current)
|
297
|
+
certificates.where certificate_program: CertificateProgram.where(organization: organization)
|
298
|
+
end
|
299
|
+
|
300
|
+
def certificated_in?(certificate_program)
|
301
|
+
certificates.where(certificate_program: certificate_program).exists?
|
302
|
+
end
|
303
|
+
|
281
304
|
private
|
282
305
|
|
283
306
|
def welcome_to_new_organizations!
|
data/app/models/user_stats.rb
CHANGED
@@ -10,7 +10,39 @@ class UserStats < ApplicationRecord
|
|
10
10
|
self.stats_for(user).exp
|
11
11
|
end
|
12
12
|
|
13
|
+
def activity(date_range = nil)
|
14
|
+
date_filter = { submitted_at: date_range }.compact
|
15
|
+
{
|
16
|
+
exercises: {
|
17
|
+
solved_count: organization_exercises
|
18
|
+
.joins(:assignments)
|
19
|
+
.where(assignments: { top_submission_status: [:passed, :skipped], submitter: user }.merge(date_filter))
|
20
|
+
.count,
|
21
|
+
count: organization_exercises.count},
|
22
|
+
|
23
|
+
messages: messages_in_discussions_count(date_range)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
13
27
|
def add_exp!(points)
|
14
28
|
self.exp += points
|
15
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def messages_in_discussions_count(date_range = nil)
|
34
|
+
date_filter = { date: date_range }.compact
|
35
|
+
result = Message.joins(:discussion)
|
36
|
+
.where({sender: user.uid, discussions: { organization: organization }}.merge(date_filter))
|
37
|
+
.group(:approved)
|
38
|
+
.count
|
39
|
+
unapproved = result[false] || 0
|
40
|
+
approved = result[true] || 0
|
41
|
+
|
42
|
+
{ count: unapproved + approved, approved: approved }
|
43
|
+
end
|
44
|
+
|
45
|
+
def organization_exercises
|
46
|
+
@organization_exercises ||= organization.exercises
|
47
|
+
end
|
16
48
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateCertificatePrograms < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :certificate_programs do |t|
|
4
|
+
t.string :title
|
5
|
+
t.string :template_html_erb
|
6
|
+
t.text :description
|
7
|
+
t.string :background_image_url
|
8
|
+
t.references :organization, index: true
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateCertificates < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :certificates do |t|
|
4
|
+
t.references :user, index: true
|
5
|
+
t.references :certificate_program, index: true
|
6
|
+
t.datetime :start_date
|
7
|
+
t.datetime :end_date
|
8
|
+
t.string :code
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -2,6 +2,8 @@ require_relative './factories/api_client_factory'
|
|
2
2
|
require_relative './factories/assignments_factory'
|
3
3
|
require_relative './factories/avatar_factory'
|
4
4
|
require_relative './factories/book_factory'
|
5
|
+
require_relative './factories/certificate_factory'
|
6
|
+
require_relative './factories/certificate_program_factory'
|
5
7
|
require_relative './factories/chapter_factory'
|
6
8
|
require_relative './factories/complement_factory'
|
7
9
|
require_relative './factories/course_factory'
|
@@ -16,6 +18,7 @@ require_relative './factories/lesson_factory'
|
|
16
18
|
require_relative './factories/login_settings_factory'
|
17
19
|
require_relative './factories/medal_factory'
|
18
20
|
require_relative './factories/message_factory'
|
21
|
+
require_relative './factories/notification_factory'
|
19
22
|
require_relative './factories/organization_factory'
|
20
23
|
require_relative './factories/term_factory'
|
21
24
|
require_relative './factories/topic_factory'
|
@@ -4,4 +4,17 @@ FactoryBot.define do
|
|
4
4
|
description { Faker::Lorem.sentence(word_count: 30) }
|
5
5
|
slug { "mumuki/mumuki-test-book-#{SecureRandom.uuid}" }
|
6
6
|
end
|
7
|
+
|
8
|
+
factory :book_with_full_tree, parent: :book do
|
9
|
+
transient do
|
10
|
+
children_factor { 3 }
|
11
|
+
exercises { create_list(:exercise, children_factor) }
|
12
|
+
lessons { create_list(:lesson, children_factor, exercises: exercises) }
|
13
|
+
chapters { create_list(:chapter, children_factor, lessons: lessons) }
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:build) do |book, evaluator|
|
17
|
+
book.chapters = evaluator.chapters
|
18
|
+
end
|
19
|
+
end
|
7
20
|
end
|
@@ -29,7 +29,8 @@ FactoryBot.define do
|
|
29
29
|
book { create(:book, name: 'test', slug: 'mumuki/mumuki-the-book') }
|
30
30
|
end
|
31
31
|
|
32
|
-
factory :another_test_organization, parent: :test_organization
|
32
|
+
factory :another_test_organization, parent: :test_organization do
|
33
|
+
name { 'another-test' }
|
33
34
|
book { create(:book, name: 'another-test', slug: 'mumuki/mumuki-another-book') }
|
34
35
|
end
|
35
36
|
|
@@ -40,10 +40,10 @@ class Mumuki::Domain::Organization::Settings < Mumukit::Platform::Model
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def disabled?
|
43
|
-
disabled_from.present? && disabled_from
|
43
|
+
disabled_from.present? && disabled_from.past?
|
44
44
|
end
|
45
45
|
|
46
46
|
def in_preparation?
|
47
|
-
in_preparation_until.present? && in_preparation_until
|
47
|
+
in_preparation_until.present? && in_preparation_until.future?
|
48
48
|
end
|
49
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 9.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '7.0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '7.0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: mumukit-sync
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -249,6 +249,8 @@ files:
|
|
249
249
|
- app/models/assignment.rb
|
250
250
|
- app/models/avatar.rb
|
251
251
|
- app/models/book.rb
|
252
|
+
- app/models/certificate.rb
|
253
|
+
- app/models/certificate_program.rb
|
252
254
|
- app/models/chapter.rb
|
253
255
|
- app/models/complement.rb
|
254
256
|
- app/models/concerns/assistable.rb
|
@@ -280,12 +282,14 @@ files:
|
|
280
282
|
- app/models/concerns/with_discussions.rb
|
281
283
|
- app/models/concerns/with_editor.rb
|
282
284
|
- app/models/concerns/with_expectations.rb
|
285
|
+
- app/models/concerns/with_generated_code.rb
|
283
286
|
- app/models/concerns/with_language.rb
|
284
287
|
- app/models/concerns/with_layout.rb
|
285
288
|
- app/models/concerns/with_locale.rb
|
286
289
|
- app/models/concerns/with_medal.rb
|
287
290
|
- app/models/concerns/with_messages.rb
|
288
291
|
- app/models/concerns/with_name.rb
|
292
|
+
- app/models/concerns/with_notifications.rb
|
289
293
|
- app/models/concerns/with_number.rb
|
290
294
|
- app/models/concerns/with_preferences.rb
|
291
295
|
- app/models/concerns/with_profile.rb
|
@@ -650,7 +654,11 @@ files:
|
|
650
654
|
- db/migrate/20210118180941_create_exam_authorization_request.rb
|
651
655
|
- db/migrate/20210118194904_create_notification.rb
|
652
656
|
- db/migrate/20210119160440_add_prevent_manual_evaluation_content_to_organizations.rb
|
657
|
+
- db/migrate/20210119174504_create_certificate_programs.rb
|
658
|
+
- db/migrate/20210119174835_create_certificates.rb
|
653
659
|
- db/migrate/20210119190204_create_exam_registration_exam_join_table.rb
|
660
|
+
- db/migrate/20210301210530_add_period_start_and_end_to_course.rb
|
661
|
+
- db/migrate/20210302181654_add_faqs_to_organizations.rb
|
654
662
|
- lib/mumuki/domain.rb
|
655
663
|
- lib/mumuki/domain/area.rb
|
656
664
|
- lib/mumuki/domain/engine.rb
|
@@ -679,6 +687,8 @@ files:
|
|
679
687
|
- lib/mumuki/domain/factories/assignments_factory.rb
|
680
688
|
- lib/mumuki/domain/factories/avatar_factory.rb
|
681
689
|
- lib/mumuki/domain/factories/book_factory.rb
|
690
|
+
- lib/mumuki/domain/factories/certificate_factory.rb
|
691
|
+
- lib/mumuki/domain/factories/certificate_program_factory.rb
|
682
692
|
- lib/mumuki/domain/factories/chapter_factory.rb
|
683
693
|
- lib/mumuki/domain/factories/complement_factory.rb
|
684
694
|
- lib/mumuki/domain/factories/course_factory.rb
|
@@ -693,6 +703,7 @@ files:
|
|
693
703
|
- lib/mumuki/domain/factories/login_settings_factory.rb
|
694
704
|
- lib/mumuki/domain/factories/medal_factory.rb
|
695
705
|
- lib/mumuki/domain/factories/message_factory.rb
|
706
|
+
- lib/mumuki/domain/factories/notification_factory.rb
|
696
707
|
- lib/mumuki/domain/factories/organization_factory.rb
|
697
708
|
- lib/mumuki/domain/factories/term_factory.rb
|
698
709
|
- lib/mumuki/domain/factories/topic_factory.rb
|