mumuki-domain 8.3.1 → 8.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05e92b25906e2bdad81e9af37f88d03423ce78e18e60e911883e1fd9933056d4
4
- data.tar.gz: 3fc2d20e7199cd604ba3462a5755084ed1ed9bbcf4b434d71bd3ed340677d650
3
+ metadata.gz: 945a8212dc38bd06d9ce3a7ba70f58fd5ea3fc2ae7076c81727ef2bdfee05979
4
+ data.tar.gz: 79dbe9e02af53932d78b403777c3d03f92dff40844047ce40052a43dbbb361c4
5
5
  SHA512:
6
- metadata.gz: 8b75c52aeec6f2403888816619740882acf061c684d09f71fd52094c9cc2b13561203433b13eaca1499a4d7c6f7046e596d3e01d95ac0e02e983bf1107fc2923
7
- data.tar.gz: 56ed033125bb4eea0d39ba693dca8e142532846159dea3e68329f3b79984ac201a3852ec6019c9428f2696d1e900583c09cd55f8b80c38215fe02ebefd014ed0
6
+ metadata.gz: a59255b4f0dcf4bb464dea4d0c1efb86cd28b3ce85b7e3f0ba2d74ad735505d82d795425bc704dd7b8e2e0bcb45a4a6ebd6e26d6f942971b4149ee0b09dd21c2
7
+ data.tar.gz: a904b0a41d0c04b09f3dc5afbc4abaf4a228112f57d4f7279798be91a9405b2a9a5bf4d7f0962c55773f3be0add354fecd5ba0e5cc0d5c2e3c91c2b3cea3a38f
@@ -263,6 +263,10 @@ class Assignment < Progress
263
263
  update! misplaced: value if value != misplaced?
264
264
  end
265
265
 
266
+ def self.build_for(user, exercise, organization)
267
+ Assignment.new submitter: user, exercise: exercise, organization: organization
268
+ end
269
+
266
270
  private
267
271
 
268
272
  def duplicates_key
@@ -13,7 +13,8 @@ module GuideContainer
13
13
  :first_exercise,
14
14
  :next_exercise,
15
15
  :stats_for,
16
- :exercises_count, to: :guide
16
+ :exercises_count,
17
+ :assignments_for, to: :guide
17
18
  end
18
19
 
19
20
  def index_usage!(organization = Organization.current)
@@ -19,6 +19,7 @@ module WithAssignments
19
19
  end
20
20
 
21
21
  # TODO: When the organization is used in this one, please change guide.pending_exercises
22
+ # TODO: Please do the same on WithAssignmentsBatch
22
23
  def find_assignment_for(user, _organization)
23
24
  assignments.find_by(submitter: user)
24
25
  end
@@ -0,0 +1,31 @@
1
+ # WithAssignmentsBatch mirrors the WithAssignment mixin
2
+ # but implements operations in batches, so that they outperform
3
+ # their counterparts
4
+ module WithAssignmentsBatch
5
+ extend ActiveSupport::Concern
6
+
7
+ def find_assignments_for(user, _organization = Organization.current, &block)
8
+ block = block_given? ? block : lambda { |it, _e| it }
9
+
10
+ return exercises.map { |it| block.call nil, it } unless user
11
+
12
+ pairs = exercises.map { |it| [it.id, [nil, it]] }.to_h
13
+ Assignment.where(submitter: user, exercise: exercises).each do |it|
14
+ pairs[it.exercise_id][0] = it
15
+ end
16
+
17
+ pairs.values.map { |assignment, exercise| block.call assignment, exercise }
18
+ end
19
+
20
+ def statuses_for(user, organization = Organization.current)
21
+ find_assignments_for user, organization do |it|
22
+ it&.status || Mumuki::Domain::Status::Submission::Pending
23
+ end
24
+ end
25
+
26
+ def assignments_for(user, organization = Organization.current)
27
+ find_assignments_for user, organization do |it, exercise|
28
+ it || Assignment.build_for(user, exercise, organization)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module WithPreferences
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ composed_of :preferences, mapping: %w(uppercase_mode uppercase_mode), constructor: :from_attributes
6
+ end
7
+ end
@@ -6,7 +6,8 @@ class Guide < Content
6
6
 
7
7
  include WithStats,
8
8
  WithExpectations,
9
- WithLanguage
9
+ WithLanguage,
10
+ WithAssignmentsBatch
10
11
 
11
12
  markdown_on :corollary, :sources, :learn_more, :teacher_info
12
13
 
@@ -0,0 +1,17 @@
1
+ class Preferences
2
+ include ActiveModel::Model
3
+
4
+ def self.attributes
5
+ [:uppercase_mode]
6
+ end
7
+
8
+ attr_accessor *self.attributes
9
+
10
+ def self.from_attributes(*args)
11
+ new self.attributes.zip(args).to_h
12
+ end
13
+
14
+ def uppercase?
15
+ uppercase_mode
16
+ end
17
+ end
@@ -11,6 +11,10 @@ class Stats
11
11
  failed + pending == 0
12
12
  end
13
13
 
14
+ def almost_done?
15
+ failed + pending <= 1
16
+ end
17
+
14
18
  def started?
15
19
  submitted > 0
16
20
  end
@@ -50,18 +50,19 @@ class Topic < Content
50
50
  end
51
51
 
52
52
  def pending_lessons(user)
53
- guides.
54
- joins('left join public.exercises exercises
55
- on exercises.guide_id = guides.id').
56
- joins("left join public.assignments assignments
53
+ lessons
54
+ .includes(:guide)
55
+ .references(:guide)
56
+ .joins('left join exercises exercises on exercises.guide_id = guides.id')
57
+ .joins("left join assignments assignments
57
58
  on assignments.exercise_id = exercises.id
58
59
  and assignments.submitter_id = #{user.id}
59
60
  and assignments.submission_status in (
60
61
  #{Mumuki::Domain::Status::Submission::Passed.to_i},
61
62
  #{Mumuki::Domain::Status::Submission::ManualEvaluationPending.to_i}
62
- )").
63
- where('assignments.id is null').
64
- group('public.guides.id', 'lessons.number').map(&:lesson)
63
+ )")
64
+ .where('assignments.id is null')
65
+ .group('guides.id', 'lessons.number', 'lessons.id')
65
66
  end
66
67
 
67
68
  private
@@ -7,6 +7,7 @@ class User < ApplicationRecord
7
7
  Awardee,
8
8
  Disabling,
9
9
  WithTermsAcceptance,
10
+ WithPreferences,
10
11
  Mumuki::Domain::Helpers::User
11
12
 
12
13
  serialize :permissions, Mumukit::Auth::Permissions
@@ -211,7 +212,7 @@ class User < ApplicationRecord
211
212
  end
212
213
 
213
214
  def build_assignment(exercise, organization)
214
- assignments.build(exercise: exercise, organization: organization)
215
+ Assignment.build_for(self, exercise, organization)
215
216
  end
216
217
 
217
218
  def pending_siblings_at(content)
@@ -1,7 +1,7 @@
1
1
  module WithStats
2
2
  def stats_for(user)
3
3
  return unless user.present?
4
- Stats.from_statuses exercises.map { |it| it.status_for(user) }
4
+ Stats.from_statuses statuses_for(user)
5
5
  end
6
6
 
7
7
  def started?(user)
@@ -0,0 +1,5 @@
1
+ class AddUppercaseModeToUser < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :users, :uppercase_mode, :boolean
4
+ end
5
+ end
@@ -107,7 +107,7 @@ module Mumuki::Domain
107
107
  end
108
108
 
109
109
  def build_assignment(exercise, organization)
110
- Assignment.new exercise: exercise, organization: organization, submitter: self
110
+ Assignment.build_for(self, exercise, organization)
111
111
  end
112
112
 
113
113
  def pending_siblings_at(content)
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '8.3.1'
3
+ VERSION = '8.4.0'
4
4
  end
5
5
  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: 8.3.1
4
+ version: 8.4.0
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-01-21 00:00:00.000000000 Z
11
+ date: 2021-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -270,6 +270,7 @@ files:
270
270
  - app/models/concerns/submittable/triable.rb
271
271
  - app/models/concerns/topic_container.rb
272
272
  - app/models/concerns/with_assignments.rb
273
+ - app/models/concerns/with_assignments_batch.rb
273
274
  - app/models/concerns/with_case_insensitive_search.rb
274
275
  - app/models/concerns/with_description.rb
275
276
  - app/models/concerns/with_discussion_creation.rb
@@ -286,6 +287,7 @@ files:
286
287
  - app/models/concerns/with_messages.rb
287
288
  - app/models/concerns/with_name.rb
288
289
  - app/models/concerns/with_number.rb
290
+ - app/models/concerns/with_preferences.rb
289
291
  - app/models/concerns/with_profile.rb
290
292
  - app/models/concerns/with_progress.rb
291
293
  - app/models/concerns/with_randomizations.rb
@@ -326,6 +328,7 @@ files:
326
328
  - app/models/message.rb
327
329
  - app/models/notification.rb
328
330
  - app/models/organization.rb
331
+ - app/models/preferences.rb
329
332
  - app/models/progress.rb
330
333
  - app/models/stats.rb
331
334
  - app/models/subscription.rb
@@ -642,6 +645,7 @@ files:
642
645
  - db/migrate/20201027134205_add_immersible_to_organization.rb
643
646
  - db/migrate/20201027152806_create_terms.rb
644
647
  - db/migrate/20201130163114_add_banned_from_forum_to_users.rb
648
+ - db/migrate/20210111125810_add_uppercase_mode_to_user.rb
645
649
  - db/migrate/20210114200545_create_exam_registrations.rb
646
650
  - db/migrate/20210118180941_create_exam_authorization_request.rb
647
651
  - db/migrate/20210118194904_create_notification.rb