mumuki-domain 9.1.1 → 9.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: 469928d18be5b255deb12fc4bf34681d5be7c4fd8ce1d19943e5d931152f89b6
4
- data.tar.gz: 36afde0edf8b67cdfb86fd3f6b4b31df496a4a8e33081ca2f8497e34395a64a4
3
+ metadata.gz: ddd0081f4ed25d268fe17c327be9b5b343a21b2491eb737db4ee837fb16eead8
4
+ data.tar.gz: 7e34398bd300598d749d628af5ae31a49985ff62f8dda2ce2598169197cacc2d
5
5
  SHA512:
6
- metadata.gz: 4f803662c7ac490c3531cb7adba534d871efb9e4b54bde3eb9f294971da09794834842892fbbc420d9fc4d231bb51372a76b0b06f021ac70f2fd74f844933284
7
- data.tar.gz: 3001b4fa192a0065ed973d70b066612af5b739d1d144a41b037c89136fa06d9289f5d1e1c922063bf045502cab6aa8c02a8c238987ad34563ef0db92712f517c
6
+ metadata.gz: 87e8fbb20f42949df631f2696c1d10a0c40744b7f84a1c7b705e525a8f2120a1e1ce5a58231a9bb9c2faa4987bd031eba01d3eb01a3e407f7202c4469eaeda72
7
+ data.tar.gz: 9196ae6c744c474853ffb027cf86f015546539ef994f83c62f27199123e54dbda3372fbd141a22f86c349270a0d14b1e6cdf3fdda47f3476bc6cd594ceb6e742
@@ -29,7 +29,7 @@ class ApplicationRecord < ActiveRecord::Base
29
29
  def self.serialize_symbolized_hash_array(*keys)
30
30
  keys.each do |field|
31
31
  serialize field
32
- define_method(field) { self[field]&.map { |it| it.symbolize_keys } }
32
+ define_method(field) { self[field]&.map { |it| it.deep_symbolize_keys } }
33
33
  end
34
34
  end
35
35
 
@@ -18,4 +18,8 @@ module TerminalNavigation
18
18
  def siblings
19
19
  []
20
20
  end
21
+
22
+ def next_for(_user)
23
+ nil
24
+ end
21
25
  end
@@ -0,0 +1,19 @@
1
+ module WithPgLock
2
+ ##
3
+ # Lock PG table, reload model and execute callback if
4
+ # criterion is met
5
+ #
6
+ def with_pg_lock(callback, criterion = proc { true })
7
+ # Some notes:
8
+ #
9
+ # * nowait is a postgre specific option and may not work with other databases
10
+ # * nowait will raise an exception if the lock can not be acquired
11
+ # * we are using a double check lock pattern to reduce lock acquisition
12
+ with_lock('for update nowait') do
13
+ reload
14
+ callback.call if criterion.call
15
+ end if criterion.call
16
+ rescue
17
+ nil
18
+ end
19
+ end
@@ -1,5 +1,6 @@
1
1
  module WithReminders
2
2
  extend ActiveSupport::Concern
3
+ include WithPgLock
3
4
 
4
5
  def build_reminder
5
6
  mailer = UserMailer.new
@@ -18,23 +19,13 @@ module WithReminders
18
19
  end
19
20
 
20
21
  # Try to send a reminder, by acquiring a database lock for update
21
- # the aproppriate record. This object can't be updated as long as
22
+ # the appropriate record. This object can't be updated as long as
22
23
  # the reminder is being sent.
23
24
  #
24
25
  # This method is aimed to be sent across multiple servers or processed concurrently
25
26
  # and still not send duplicate mails
26
27
  def try_remind_with_lock!
27
- # Some notes:
28
- #
29
- # * nowait is a postgre specific option and may not work with other databases
30
- # * nowait will raise an exception if the lock can not be acquired
31
- # * we are using a double check lock pattern to reduce lock acquisition
32
- with_lock('for update nowait') do
33
- reload
34
- remind! if should_remind?
35
- end if should_remind?
36
- rescue
37
- nil
28
+ with_pg_lock proc { remind! }, proc { should_remind? }
38
29
  end
39
30
 
40
31
  private
@@ -28,7 +28,7 @@ class Discussion < ApplicationRecord
28
28
  delegate :language, to: :item
29
29
  delegate :to_discussion_status, to: :status
30
30
 
31
- MODERATOR_REVIEW_AVERAGE_TIME = 10.minutes
31
+ MODERATOR_REVIEW_AVERAGE_TIME = 17.minutes
32
32
 
33
33
  scope :for_user, -> (user) do
34
34
  if user.try(:moderator_here?)
@@ -21,7 +21,7 @@ class ExamAuthorizationRequest < ApplicationRecord
21
21
  def icon
22
22
  case status.to_sym
23
23
  when :pending
24
- { class: 'info-circle', type: 'info' }
24
+ { class: 'hourglass', type: 'info' }
25
25
  when :approved
26
26
  { class: 'check-circle', type: 'success' }
27
27
  when :rejected
@@ -1,4 +1,5 @@
1
1
  class ExamRegistration < ApplicationRecord
2
+ include WithPgLock
2
3
  include WithTimedEnablement
3
4
  include TerminalNavigation
4
5
 
@@ -16,6 +17,8 @@ class ExamRegistration < ApplicationRecord
16
17
 
17
18
  alias_attribute :name, :description
18
19
 
20
+ scope :should_process, -> { where(processed: false).where(arel_table[:end_time].lt(Time.now)) }
21
+
19
22
  def authorization_criterion
20
23
  @authorization_criterion ||= ExamRegistration::AuthorizationCriterion.parse(authorization_criterion_type, authorization_criterion_value)
21
24
  end
@@ -40,11 +43,21 @@ class ExamRegistration < ApplicationRecord
40
43
  registrees.where.not(id: Notification.notified_users_ids_for(self, self.organization))
41
44
  end
42
45
 
46
+ # Try to process authorization request, by acquiring a database lock for update
47
+ # the appropriate record.
48
+ #
49
+ # This method is aimed to be sent across multiple servers or processed concurrently
50
+ # and still not send duplicate mails
43
51
  def process_requests!
52
+ with_pg_lock proc { process_authorization_requests! }, proc { !processed? }
53
+ end
54
+
55
+ def process_authorization_requests!
44
56
  authorization_requests.each do |it|
45
57
  process_request! it
46
58
  it.try_authorize!
47
59
  end
60
+ update! processed: true
48
61
  end
49
62
 
50
63
  def authorization_request_for(user)
@@ -29,7 +29,7 @@ class Exercise < ApplicationRecord
29
29
  defaults { self.submissions_count = 0 }
30
30
 
31
31
  def self.default_scope
32
- where(manual_evaluation: false) if Organization.safe_current&.prevent_manual_evaluation_content
32
+ where(manual_evaluation: false) if hide_manual_evaluation?
33
33
  end
34
34
 
35
35
  alias_method :progress_for, :assignment_for
@@ -256,6 +256,10 @@ class Exercise < ApplicationRecord
256
256
  layouts.keys[0]
257
257
  end
258
258
 
259
+ def self.hide_manual_evaluation?
260
+ Organization.safe_current&.prevent_manual_evaluation_content
261
+ end
262
+
259
263
  def self.with_pending_assignments_for(user, relation)
260
264
  relation.
261
265
  joins("left join assignments assignments
@@ -266,6 +270,7 @@ class Exercise < ApplicationRecord
266
270
  #{Mumuki::Domain::Status::Submission::Passed.to_i},
267
271
  #{Mumuki::Domain::Status::Submission::ManualEvaluationPending.to_i}
268
272
  )").
269
- where('assignments.id is null')
273
+ where('assignments.id is null').
274
+ where(('exercises.manual_evaluation = false' if hide_manual_evaluation?))
270
275
  end
271
276
  end
data/app/models/user.rb CHANGED
@@ -16,6 +16,8 @@ class User < ApplicationRecord
16
16
 
17
17
  has_many :notifications
18
18
  has_many :assignments, foreign_key: :submitter_id
19
+ has_many :indicators
20
+ has_many :user_stats, class_name: 'UserStats'
19
21
  has_many :messages, -> { order(created_at: :desc) }, through: :assignments
20
22
 
21
23
  has_many :submitted_exercises, through: :assignments, class_name: 'Exercise', source: :exercise
@@ -312,6 +314,18 @@ class User < ApplicationRecord
312
314
  UserMailer.certificate(certificate).deliver_later
313
315
  end
314
316
 
317
+ def clear_progress_for!(organization)
318
+ location = { organization: organization }.compact
319
+
320
+ target_assignments = assignments.where(location)
321
+
322
+ messages.where(assignment: target_assignments).delete_all
323
+
324
+ target_assignments.delete_all
325
+ indicators.where(location).delete_all
326
+ user_stats.where(location).delete_all
327
+ end
328
+
315
329
  private
316
330
 
317
331
  def welcome_to_new_organizations!
@@ -31,9 +31,9 @@ class UserStats < ApplicationRecord
31
31
  private
32
32
 
33
33
  def messages_in_discussions_count(date_range = nil)
34
- date_filter = { date: date_range }.compact
34
+ date_filter = { created_at: date_range }.compact
35
35
  result = Message.joins(:discussion)
36
- .where({sender: user.uid, discussions: { organization: organization }}.merge(date_filter))
36
+ .where({sender: user.uid, deletion_motive: nil, discussions: { organization: organization }}.merge(date_filter))
37
37
  .group(:approved)
38
38
  .count
39
39
  unapproved = result[false] || 0
@@ -0,0 +1,5 @@
1
+ class AddProcessedFlagToExamRegistration < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :exam_registrations, :processed, :boolean, default: false
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '9.1.1'
3
+ VERSION = '9.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: 9.1.1
4
+ version: 9.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-04-30 00:00:00.000000000 Z
11
+ date: 2021-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -291,6 +291,7 @@ files:
291
291
  - app/models/concerns/with_name.rb
292
292
  - app/models/concerns/with_notifications.rb
293
293
  - app/models/concerns/with_number.rb
294
+ - app/models/concerns/with_pg_lock.rb
294
295
  - app/models/concerns/with_preferences.rb
295
296
  - app/models/concerns/with_profile.rb
296
297
  - app/models/concerns/with_progress.rb
@@ -666,6 +667,7 @@ files:
666
667
  - db/migrate/20210318194559_add_dates_to_certificate_program.rb
667
668
  - db/migrate/20210318195238_rename_certificate_dates.rb
668
669
  - db/migrate/20210330175706_create_exam_registration_user_join_table.rb
670
+ - db/migrate/20210512200453_add_processed_flag_to_exam_registration.rb
669
671
  - lib/mumuki/domain.rb
670
672
  - lib/mumuki/domain/area.rb
671
673
  - lib/mumuki/domain/engine.rb