mumuki-domain 9.1.0 → 9.3.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: 3d165cf9f919009ff75f9b6287e01df473ff786089c553651d0841911afb7375
4
- data.tar.gz: 6b746d09af5ab93422f9bd8091a0fb5d809f74422fb4ec6b6c4847af86896451
3
+ metadata.gz: b78b493d9f7e6314a746e22d17fe33c140dada6e77a9af84da850098180a1677
4
+ data.tar.gz: 9ed9017804d844c8a24540dcdf5c32d4ad78d8a28b186e3df1dbd83b845ff5cd
5
5
  SHA512:
6
- metadata.gz: 396f0b0743fd5d44e4bc5bea7b8e8ffedd34932df9f98b29334cef334ff6361fbdc769e81deec7213aaa1ad684acb627ca52ddf68bc3e6b88019d1195470f278
7
- data.tar.gz: 901f97fe4f6f6d1b8a6b916b9d90339d350d796d9c3e3f8b9a3c01bf9770a707a145370be8162eabcfa03490a2dff4cf77236de8ffc43ee2cc7d7414429f2743
6
+ metadata.gz: 84faddd371cc851bbb08155cddb140dd6a17eaa3920f73cf235950d3321f07be4dd4f44325708b582904ee4d1eac2b5c426be3afb7b82e566834d87686eec3b2
7
+ data.tar.gz: 93cf6080fba52bffbe3d7fafd4a3ed0121f55accaa8b1c7950e9512a4f409b9031288b51998ab7caff22ac161fd4c0d4c9fb663f369cafb00a42afcfe6ad5732
@@ -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,16 @@
1
+ module WithSoftDeletion
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ enum deletion_motive: %i(self_deleted inappropriate_content shares_solution discloses_personal_information)
6
+ belongs_to :deleted_by, class_name: 'User', optional: true
7
+ end
8
+
9
+ def soft_delete!(motive, deleter)
10
+ update! deletion_motive: motive, deleted_by: deleter, deleted_at: Time.now
11
+ end
12
+
13
+ def deleted?
14
+ deleted_at.present?
15
+ end
16
+ end
@@ -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?)
@@ -38,6 +38,10 @@ class Discussion < ApplicationRecord
38
38
  end
39
39
  end
40
40
 
41
+ def visible_messages
42
+ messages.where.not(deletion_motive: :self_deleted).or(messages.where(deletion_motive: nil))
43
+ end
44
+
41
45
  def try_solve!
42
46
  if opened?
43
47
  update! status: reachable_statuses_for(initiator).first
@@ -73,7 +77,7 @@ class Discussion < ApplicationRecord
73
77
  end
74
78
 
75
79
  def last_message_date
76
- messages.last&.created_at || created_at
80
+ visible_messages.last&.created_at || created_at
77
81
  end
78
82
 
79
83
  def friendly
@@ -125,11 +129,11 @@ class Discussion < ApplicationRecord
125
129
  end
126
130
 
127
131
  def has_messages?
128
- messages.exists? || description.present?
132
+ visible_messages.exists? || description.present?
129
133
  end
130
134
 
131
135
  def responses_count
132
- messages.where.not(sender: initiator.uid).count
136
+ visible_messages.where.not(sender: initiator.uid).count
133
137
  end
134
138
 
135
139
  def has_responses?
@@ -186,6 +190,6 @@ class Discussion < ApplicationRecord
186
190
  private
187
191
 
188
192
  def messages_by_updated_at(direction = :desc)
189
- messages.reorder(updated_at: direction)
193
+ messages.where(deletion_motive: nil).reorder(updated_at: direction)
190
194
  end
191
195
  end
@@ -18,6 +18,17 @@ class ExamAuthorizationRequest < ApplicationRecord
18
18
  exam_registration.description
19
19
  end
20
20
 
21
+ def icon
22
+ case status.to_sym
23
+ when :pending
24
+ { class: 'info-circle', type: 'info' }
25
+ when :approved
26
+ { class: 'check-circle', type: 'success' }
27
+ when :rejected
28
+ { class: 'times-circle', type: 'danger' }
29
+ end
30
+ end
31
+
21
32
  private
22
33
 
23
34
  def notify_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
@@ -1,4 +1,5 @@
1
1
  class Message < ApplicationRecord
2
+ include WithSoftDeletion
2
3
 
3
4
  belongs_to :discussion, optional: true
4
5
  belongs_to :assignment, foreign_key: :submission_id, primary_key: :submission_id, optional: true
@@ -10,7 +11,6 @@ class Message < ApplicationRecord
10
11
  validates_presence_of :submission_id, :unless => :discussion_id?
11
12
 
12
13
  after_save :update_counters_cache!
13
- after_destroy :update_counters_cache!
14
14
 
15
15
  markdown_on :content
16
16
 
@@ -43,7 +43,8 @@ class Message < ApplicationRecord
43
43
  end
44
44
 
45
45
  def to_resource_h
46
- as_json(except: [:id, :type, :discussion_id, :approved, :not_actually_a_question],
46
+ as_json(except: [:id, :type, :discussion_id, :approved, :approved_at, :approved_by_id,
47
+ :not_actually_a_question, :deletion_motive, :deleted_at, :deleted_by_id],
47
48
  include: {exercise: {only: [:bibliotheca_id]}})
48
49
  .merge(organization: Organization.current.name)
49
50
  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
@@ -211,6 +213,10 @@ class User < ApplicationRecord
211
213
  name.split.map(&:first).map(&:capitalize).join(' ')
212
214
  end
213
215
 
216
+ def abbreviated_name
217
+ "#{first_name} #{last_name.first.capitalize + '.' if last_name.present?}".strip
218
+ end
219
+
214
220
  def progress_at(content, organization)
215
221
  Indicator.find_or_initialize_by(user: self, organization: organization, content: content)
216
222
  end
@@ -283,11 +289,11 @@ class User < ApplicationRecord
283
289
  end
284
290
 
285
291
  def formal_first_name
286
- verified_first_name || first_name
292
+ verified_first_name.presence || first_name
287
293
  end
288
294
 
289
295
  def formal_last_name
290
- verified_last_name || last_name
296
+ verified_last_name.presence || last_name
291
297
  end
292
298
 
293
299
  def formal_full_name
@@ -308,6 +314,18 @@ class User < ApplicationRecord
308
314
  UserMailer.certificate(certificate).deliver_later
309
315
  end
310
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
+
311
329
  private
312
330
 
313
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,7 @@
1
+ class AddDeletionFieldsToMessage < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :messages, :deletion_motive, :integer
4
+ add_column :messages, :deleted_at, :datetime
5
+ add_reference :messages, :deleted_by, index: true
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '9.1.0'
3
+ VERSION = '9.3.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.0
4
+ version: 9.3.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-20 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -301,6 +301,7 @@ files:
301
301
  - app/models/concerns/with_scoped_queries/page.rb
302
302
  - app/models/concerns/with_scoped_queries/sort.rb
303
303
  - app/models/concerns/with_slug.rb
304
+ - app/models/concerns/with_soft_deletion.rb
304
305
  - app/models/concerns/with_target_audience.rb
305
306
  - app/models/concerns/with_terms_acceptance.rb
306
307
  - app/models/concerns/with_timed_enablement.rb
@@ -661,6 +662,7 @@ files:
661
662
  - db/migrate/20210302181654_add_faqs_to_organizations.rb
662
663
  - db/migrate/20210308145910_add_approved_by_and_at_to_message.rb
663
664
  - db/migrate/20210310195602_add_delete_account_token_to_user.rb
665
+ - db/migrate/20210318191512_add_deletion_fields_to_message.rb
664
666
  - db/migrate/20210318194559_add_dates_to_certificate_program.rb
665
667
  - db/migrate/20210318195238_rename_certificate_dates.rb
666
668
  - db/migrate/20210330175706_create_exam_registration_user_join_table.rb