mumuki-domain 7.6.1 → 7.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/assignment.rb +2 -0
- data/app/models/book.rb +4 -2
- data/app/models/concerns/contextualization.rb +1 -1
- data/app/models/concerns/navigation/siblings_navigation.rb +2 -2
- data/app/models/concerns/submittable/solvable.rb +9 -3
- data/app/models/concerns/submittable/submittable.rb +1 -1
- data/app/models/concerns/with_assignments.rb +1 -1
- data/app/models/concerns/with_discussions.rb +9 -6
- data/app/models/concerns/with_layout.rb +5 -1
- data/app/models/concerns/with_progress.rb +1 -1
- data/app/models/concerns/with_scoped_queries.rb +9 -9
- data/app/models/concerns/with_scoped_queries/page.rb +1 -1
- data/app/models/concerns/with_scoped_queries/sort.rb +6 -1
- data/app/models/course.rb +13 -7
- data/app/models/discussion.rb +51 -13
- data/app/models/exam.rb +53 -23
- data/app/models/exam/passing_criterion.rb +53 -0
- data/app/models/exercise/challenge.rb +1 -1
- data/app/models/exercise/problem.rb +6 -0
- data/app/models/exercise/reading.rb +4 -0
- data/app/models/guide.rb +1 -1
- data/app/models/invitation.rb +7 -1
- data/app/models/message.rb +28 -4
- data/app/models/organization.rb +7 -11
- data/app/models/user.rb +64 -0
- data/db/migrate/20200601203033_add_course_to_exam.rb +5 -0
- data/db/migrate/20200605161350_add_passing_criterions_to_exam.rb +6 -0
- data/db/migrate/20200702165503_add_messages_count_to_discussion.rb +6 -0
- data/db/migrate/20200728162727_add_not_actually_a_question_field_to_messages.rb +5 -0
- data/db/migrate/20200728163038_add_requires_moderator_response_to_discussions.rb +5 -0
- data/db/migrate/20200730221001_add_trusted_for_forum_to_user.rb +5 -0
- data/db/migrate/20200731081757_add_last_moderator_access_fields_to_discussion.rb +6 -0
- data/db/migrate/20200804191643_add_incognito_mode_enabled_to_organization.rb +5 -0
- data/lib/mumuki/domain.rb +1 -0
- data/lib/mumuki/domain/factories/course_factory.rb +2 -0
- data/lib/mumuki/domain/factories/discussion_factory.rb +2 -2
- data/lib/mumuki/domain/factories/exam_factory.rb +1 -0
- data/lib/mumuki/domain/factories/message_factory.rb +1 -6
- data/lib/mumuki/domain/incognito.rb +112 -0
- data/lib/mumuki/domain/locales/activerecord/es-CL.yml +59 -0
- data/lib/mumuki/domain/locales/console_submission/es-CL.yml +3 -0
- data/lib/mumuki/domain/organization/profile.rb +2 -1
- data/lib/mumuki/domain/organization/settings.rb +12 -9
- data/lib/mumuki/domain/status/discussion/discussion.rb +0 -8
- data/lib/mumuki/domain/submission/base.rb +11 -1
- data/lib/mumuki/domain/submission/solution.rb +3 -1
- data/lib/mumuki/domain/version.rb +1 -1
- metadata +19 -8
@@ -0,0 +1,53 @@
|
|
1
|
+
class Exam::PassingCriterion
|
2
|
+
|
3
|
+
attr_reader :value
|
4
|
+
|
5
|
+
def initialize(value)
|
6
|
+
@value = value
|
7
|
+
end
|
8
|
+
|
9
|
+
def type
|
10
|
+
self.class.name.demodulize.underscore
|
11
|
+
end
|
12
|
+
|
13
|
+
def as_json
|
14
|
+
{type: type, value: value}
|
15
|
+
end
|
16
|
+
|
17
|
+
def ensure_valid!
|
18
|
+
raise "Invalid criterion value #{value} for #{type}" unless valid_passing_grade?
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse(type, value)
|
22
|
+
parse_criterion_type(type, value)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse_criterion_type(type, value)
|
26
|
+
"Exam::PassingCriterion::#{type.camelize}".constantize.new(value)
|
27
|
+
rescue
|
28
|
+
raise "Invalid criterion type #{type}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class Exam::PassingCriterion::None < Exam::PassingCriterion
|
34
|
+
def initialize(_)
|
35
|
+
@value = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def valid_passing_grade?
|
39
|
+
!value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Exam::PassingCriterion::Percentage < Exam::PassingCriterion
|
44
|
+
def valid_passing_grade?
|
45
|
+
value.between? 0, 100
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Exam::PassingCriterion::PassedExercises < Exam::PassingCriterion
|
50
|
+
def valid_passing_grade?
|
51
|
+
value >= 0
|
52
|
+
end
|
53
|
+
end
|
@@ -45,6 +45,12 @@ class Problem < QueriableChallenge
|
|
45
45
|
own_expectations.present? || own_custom_expectations.present?
|
46
46
|
end
|
47
47
|
|
48
|
+
# Sets the layout. This method accepts input_kids as a synonym of input_primary
|
49
|
+
# for historical reasons
|
50
|
+
def layout=(layout)
|
51
|
+
self[:layout] = layout.like?(:input_kids) ? :input_primary : layout
|
52
|
+
end
|
53
|
+
|
48
54
|
private
|
49
55
|
|
50
56
|
def ensure_evaluation_criteria
|
data/app/models/guide.rb
CHANGED
data/app/models/invitation.rb
CHANGED
@@ -2,12 +2,18 @@ class Invitation < ApplicationRecord
|
|
2
2
|
include Mumuki::Domain::Syncable
|
3
3
|
|
4
4
|
belongs_to :course
|
5
|
+
|
6
|
+
validate :ensure_not_expired, on: :create
|
5
7
|
validates_uniqueness_of :code
|
6
8
|
|
7
9
|
defaults do
|
8
10
|
self.code ||= self.class.generate_code
|
9
11
|
end
|
10
12
|
|
13
|
+
def ensure_not_expired
|
14
|
+
errors.add(:base, :invitation_expired) if expired?
|
15
|
+
end
|
16
|
+
|
11
17
|
def import_from_resource_h!(json)
|
12
18
|
update! json.merge(course: Course.locate!(json[:course]))
|
13
19
|
end
|
@@ -25,7 +31,7 @@ class Invitation < ApplicationRecord
|
|
25
31
|
end
|
26
32
|
|
27
33
|
def to_resource_h
|
28
|
-
{
|
34
|
+
{code: code, course: course_slug, expiration_date: expiration_date}
|
29
35
|
end
|
30
36
|
|
31
37
|
def navigation_end?
|
data/app/models/message.rb
CHANGED
@@ -6,6 +6,10 @@ class Message < ApplicationRecord
|
|
6
6
|
|
7
7
|
validates_presence_of :content, :sender
|
8
8
|
validates_presence_of :submission_id, :unless => :discussion_id?
|
9
|
+
|
10
|
+
after_save :update_counters_cache!
|
11
|
+
after_destroy :update_counters_cache!
|
12
|
+
|
9
13
|
markdown_on :content
|
10
14
|
|
11
15
|
def notify!
|
@@ -16,6 +20,10 @@ class Message < ApplicationRecord
|
|
16
20
|
sender_user == discussion&.initiator
|
17
21
|
end
|
18
22
|
|
23
|
+
def from_moderator?
|
24
|
+
sender_user.moderator_here?
|
25
|
+
end
|
26
|
+
|
19
27
|
def from_user?(user)
|
20
28
|
sender_user == user
|
21
29
|
end
|
@@ -33,9 +41,9 @@ class Message < ApplicationRecord
|
|
33
41
|
end
|
34
42
|
|
35
43
|
def to_resource_h
|
36
|
-
as_json(except: [:id, :type, :discussion_id, :approved],
|
44
|
+
as_json(except: [:id, :type, :discussion_id, :approved, :not_actually_a_question],
|
37
45
|
include: {exercise: {only: [:bibliotheca_id]}})
|
38
|
-
|
46
|
+
.merge(organization: Organization.current.name)
|
39
47
|
end
|
40
48
|
|
41
49
|
def read!
|
@@ -46,11 +54,27 @@ class Message < ApplicationRecord
|
|
46
54
|
toggle! :approved
|
47
55
|
end
|
48
56
|
|
57
|
+
def toggle_not_actually_a_question!
|
58
|
+
toggle! :not_actually_a_question
|
59
|
+
end
|
60
|
+
|
61
|
+
def validated?
|
62
|
+
approved? || from_moderator?
|
63
|
+
end
|
64
|
+
|
65
|
+
def update_counters_cache!
|
66
|
+
discussion&.update_counters!
|
67
|
+
end
|
68
|
+
|
69
|
+
def question?
|
70
|
+
from_initiator? && !not_actually_a_question?
|
71
|
+
end
|
72
|
+
|
49
73
|
def self.parse_json(json)
|
50
74
|
message = json.delete 'message'
|
51
75
|
json
|
52
|
-
|
53
|
-
|
76
|
+
.except('uid', 'exercise_id')
|
77
|
+
.merge(message)
|
54
78
|
end
|
55
79
|
|
56
80
|
def self.read_all!
|
data/app/models/organization.rb
CHANGED
@@ -18,6 +18,7 @@ class Organization < ApplicationRecord
|
|
18
18
|
has_many :usages
|
19
19
|
|
20
20
|
validates_presence_of :contact_email, :locale
|
21
|
+
validates_presence_of :welcome_email_template, if: :greet_new_users?
|
21
22
|
validates :name, uniqueness: true,
|
22
23
|
presence: true,
|
23
24
|
format: { with: Mumukit::Platform::Organization.anchored_valid_name_regex }
|
@@ -105,17 +106,8 @@ class Organization < ApplicationRecord
|
|
105
106
|
# ask for help in this organization
|
106
107
|
#
|
107
108
|
# Warning: this method does not strictly check user's permission
|
108
|
-
def ask_for_help_enabled?(user
|
109
|
-
report_issue_enabled? || community_link.present? ||
|
110
|
-
end
|
111
|
-
|
112
|
-
# Tells if the given user can
|
113
|
-
# create discussion in this organization
|
114
|
-
#
|
115
|
-
# This is true only when this organization has a forum and the user
|
116
|
-
# has the discusser pseudo-permission
|
117
|
-
def can_create_discussions?(user = nil)
|
118
|
-
forum_enabled? && (!user || user.discusser_of?(self))
|
109
|
+
def ask_for_help_enabled?(user)
|
110
|
+
report_issue_enabled? || community_link.present? || user.can_discuss_in?(self)
|
119
111
|
end
|
120
112
|
|
121
113
|
def import_from_resource_h!(resource_h)
|
@@ -136,6 +128,10 @@ class Organization < ApplicationRecord
|
|
136
128
|
update! progressive_display_lookahead: lookahead
|
137
129
|
end
|
138
130
|
|
131
|
+
def display_name
|
132
|
+
name.gsub(/\W/, ' ').titleize
|
133
|
+
end
|
134
|
+
|
139
135
|
private
|
140
136
|
|
141
137
|
def ensure_consistent_public_login
|
data/app/models/user.rb
CHANGED
@@ -39,6 +39,8 @@ class User < ApplicationRecord
|
|
39
39
|
before_validation :set_uid!
|
40
40
|
validates :uid, presence: true
|
41
41
|
|
42
|
+
after_save :welcome_to_new_organizations!, if: :gained_access_to_new_orga?
|
43
|
+
|
42
44
|
resource_fields :uid, :social_id, :email, :permissions, :verified_first_name, :verified_last_name, *profile_fields
|
43
45
|
|
44
46
|
def last_lesson
|
@@ -169,8 +171,70 @@ class User < ApplicationRecord
|
|
169
171
|
sequence[0..count + lookahead - 1]
|
170
172
|
end
|
171
173
|
|
174
|
+
# Tells if the given user can discuss in an organization
|
175
|
+
#
|
176
|
+
# This is true only when this organization has the forum enabled and the user
|
177
|
+
# has the discusser pseudo-permission and the discusser is trusted
|
178
|
+
def can_discuss_in?(organization)
|
179
|
+
organization.forum_enabled? && discusser_of?(organization) && trusted_as_discusser_in?(organization)
|
180
|
+
end
|
181
|
+
|
182
|
+
def trusted_as_discusser_in?(organization)
|
183
|
+
trusted_for_forum? || !organization.forum_only_for_trusted?
|
184
|
+
end
|
185
|
+
|
186
|
+
def can_discuss_here?
|
187
|
+
can_discuss_in? Organization.current
|
188
|
+
end
|
189
|
+
|
190
|
+
def name_initials
|
191
|
+
name.split.map(&:first).map(&:capitalize).join(' ')
|
192
|
+
end
|
193
|
+
|
194
|
+
def progress_at(content, organization)
|
195
|
+
Indicator.find_or_initialize_by(user: self, organization: organization, content: content)
|
196
|
+
end
|
197
|
+
|
198
|
+
def build_assignment(exercise, organization)
|
199
|
+
assignments.build(exercise: exercise, organization: organization)
|
200
|
+
end
|
201
|
+
|
202
|
+
def pending_siblings_at(content)
|
203
|
+
content.pending_siblings_for(self)
|
204
|
+
end
|
205
|
+
|
206
|
+
def next_exercise_at(guide)
|
207
|
+
guide.pending_exercises(self).order('public.exercises.number asc').first
|
208
|
+
end
|
209
|
+
|
210
|
+
def run_submission!(submission, assignment, evaluation)
|
211
|
+
submission.run! assignment, evaluation
|
212
|
+
end
|
213
|
+
|
214
|
+
def incognito?
|
215
|
+
false
|
216
|
+
end
|
217
|
+
|
172
218
|
private
|
173
219
|
|
220
|
+
def welcome_to_new_organizations!
|
221
|
+
new_accessible_organizations.each do |organization|
|
222
|
+
UserMailer.welcome_email(self, organization).deliver_later if organization.greet_new_users?
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def gained_access_to_new_orga?
|
227
|
+
new_accessible_organizations.present?
|
228
|
+
end
|
229
|
+
|
230
|
+
def new_accessible_organizations
|
231
|
+
return [] unless saved_change_to_permissions?
|
232
|
+
|
233
|
+
old, new = saved_change_to_permissions
|
234
|
+
new_organizations = (new.any_granted_organizations - old.any_granted_organizations).to_a
|
235
|
+
Organization.where(name: new_organizations)
|
236
|
+
end
|
237
|
+
|
174
238
|
def set_uid!
|
175
239
|
self.uid ||= email
|
176
240
|
end
|
data/lib/mumuki/domain.rb
CHANGED
@@ -2,8 +2,10 @@ FactoryBot.define do
|
|
2
2
|
factory :course do
|
3
3
|
period { '2016' }
|
4
4
|
shifts { %w(morning) }
|
5
|
+
code { "k1234-#{SecureRandom.uuid}" }
|
5
6
|
days { %w(monday wednesday) }
|
6
7
|
description { 'test' }
|
7
8
|
organization_id { 1 }
|
9
|
+
slug { "#{Organization.current.name}/#{period}-#{code}" }
|
8
10
|
end
|
9
11
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :discussion do
|
3
|
-
title {
|
4
|
-
description {
|
3
|
+
title { Faker::Lorem.sentence(word_count: 2) }
|
4
|
+
description { Faker::Lorem.sentence(word_count: 5) }
|
5
5
|
initiator { create(:user) }
|
6
6
|
item { create(:exercise) }
|
7
7
|
organization { Organization.current rescue nil }
|
@@ -1,11 +1,6 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
|
3
3
|
factory :message do
|
4
|
-
|
5
|
-
assignment
|
6
|
-
submission_id { assignment.id }
|
7
|
-
sender { Faker::Internet.email }
|
8
|
-
type { 'success' }
|
9
|
-
content { Faker::Lorem.sentence(3) }
|
4
|
+
content { Faker::Lorem.sentence(word_count: 3) }
|
10
5
|
end
|
11
6
|
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Mumuki::Domain
|
2
|
+
class IncognitoClass
|
3
|
+
|
4
|
+
def incognito?
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
# ============
|
9
|
+
# Permissions
|
10
|
+
# ============
|
11
|
+
|
12
|
+
def ensure_enabled!
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_student_granted_organizations?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def teacher_here?
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def teacher_of?(*)
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def profile_completed?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def writer?
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def moderator_here?
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
def can_discuss_here?
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
# ========
|
44
|
+
# Visiting
|
45
|
+
# ========
|
46
|
+
|
47
|
+
def visit!(*)
|
48
|
+
end
|
49
|
+
|
50
|
+
# ========
|
51
|
+
# Progress
|
52
|
+
# ========
|
53
|
+
|
54
|
+
def next_exercise_at(guide)
|
55
|
+
guide.exercises.first
|
56
|
+
end
|
57
|
+
|
58
|
+
# def completed_containers_with_lookahead(*)
|
59
|
+
# raise 'Unsupported operation. Userless mode and progressive display modes are incompatible'
|
60
|
+
# end
|
61
|
+
|
62
|
+
def progress_at(content, organization)
|
63
|
+
Indicator.new content: content, organization: organization
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_assignment(exercise, organization)
|
67
|
+
Assignment.new exercise: exercise, organization: organization, submitter: self
|
68
|
+
end
|
69
|
+
|
70
|
+
def pending_siblings_at(content)
|
71
|
+
[]
|
72
|
+
end
|
73
|
+
|
74
|
+
# ============
|
75
|
+
# ActiveRecord
|
76
|
+
# ============
|
77
|
+
|
78
|
+
def id
|
79
|
+
'<incognito>'
|
80
|
+
end
|
81
|
+
|
82
|
+
def is_a?(other)
|
83
|
+
other.is_a?(Class) && other.name == 'User' || super
|
84
|
+
end
|
85
|
+
|
86
|
+
def _read_attribute(key)
|
87
|
+
return id if key == 'id'
|
88
|
+
raise "unknown attribute #{key}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.primary_key
|
92
|
+
'id'
|
93
|
+
end
|
94
|
+
|
95
|
+
# ==========
|
96
|
+
# Evaluation
|
97
|
+
# ==========
|
98
|
+
|
99
|
+
def interpolations
|
100
|
+
[]
|
101
|
+
end
|
102
|
+
|
103
|
+
def run_submission!(submission, assignment, evaluation)
|
104
|
+
results = submission.dry_run! assignment, evaluation
|
105
|
+
assignment.assign_attributes results
|
106
|
+
results
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
Incognito = IncognitoClass.new
|
112
|
+
end
|