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 +4 -4
- data/app/models/application_record.rb +1 -1
- data/app/models/concerns/navigation/terminal_navigation.rb +4 -0
- data/app/models/concerns/with_soft_deletion.rb +16 -0
- data/app/models/discussion.rb +9 -5
- data/app/models/exam_authorization_request.rb +11 -0
- data/app/models/exercise.rb +7 -2
- data/app/models/message.rb +3 -2
- data/app/models/user.rb +20 -2
- data/app/models/user_stats.rb +2 -2
- data/db/migrate/20210318191512_add_deletion_fields_to_message.rb +7 -0
- data/lib/mumuki/domain/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b78b493d9f7e6314a746e22d17fe33c140dada6e77a9af84da850098180a1677
|
4
|
+
data.tar.gz: 9ed9017804d844c8a24540dcdf5c32d4ad78d8a28b186e3df1dbd83b845ff5cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
32
|
+
define_method(field) { self[field]&.map { |it| it.deep_symbolize_keys } }
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -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
|
data/app/models/discussion.rb
CHANGED
@@ -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 =
|
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
|
-
|
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
|
-
|
132
|
+
visible_messages.exists? || description.present?
|
129
133
|
end
|
130
134
|
|
131
135
|
def responses_count
|
132
|
-
|
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!
|
data/app/models/exercise.rb
CHANGED
@@ -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
|
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/message.rb
CHANGED
@@ -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, :
|
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!
|
data/app/models/user_stats.rb
CHANGED
@@ -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 = {
|
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
|
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.
|
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-
|
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
|