mumuki-domain 9.21.0 → 9.22.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/concerns/with_discussion_status.rb +0 -1
- data/app/models/concerns/with_messages.rb +1 -1
- data/app/models/discussion.rb +2 -2
- data/app/models/message.rb +14 -12
- data/app/models/user.rb +15 -6
- data/app/models/user_stats.rb +2 -2
- data/db/migrate/20211004062332_reference_sender_via_id_in_messages.rb +5 -0
- data/lib/mumuki/domain/factories/message_factory.rb +1 -1
- data/lib/mumuki/domain/status/discussion/discussion.rb +0 -4
- data/lib/mumuki/domain/status/submission/submission.rb +0 -8
- data/lib/mumuki/domain/status.rb +8 -0
- data/lib/mumuki/domain/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3822b6222097cb19717c7d6a76c97988f3993ef342b7e238a38ffbba6dbd7bb7
|
4
|
+
data.tar.gz: 2d6a733e2f9daf5d7c4fe6694f59ce1f5f7887067121d2af0a772be73e785b3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0c4b744c65d518051715f839920c3adc7991bd747d26c6d75507335e8b26ce17842226cb3b2e5bac3acec3970f299b2f7b01b18271254f94aff286f62de8640
|
7
|
+
data.tar.gz: 26e47f01673258854896ca35468e7b5932514748c066f53c076cd06cfe06a2e92dc87ddd523eef97644e4e2e9d3e1e2fd2bde616c62dc0b06b3f63c884489427
|
@@ -4,7 +4,6 @@ module WithDiscussionStatus
|
|
4
4
|
included do
|
5
5
|
serialize :status, Mumuki::Domain::Status::Discussion
|
6
6
|
validates_presence_of :status
|
7
|
-
scope :by_status, -> (status) { where(status: status) }
|
8
7
|
end
|
9
8
|
|
10
9
|
delegate :closed?, :opened?, :solved?, :pending_review?, :reachable_statuses, to: :status
|
data/app/models/discussion.rb
CHANGED
@@ -103,7 +103,7 @@ class Discussion < ApplicationRecord
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def submit_message!(message, user)
|
106
|
-
message.merge!(sender: user
|
106
|
+
message.merge!(sender: user)
|
107
107
|
messages.create(message)
|
108
108
|
user.subscribe_to! self
|
109
109
|
mark_subscriptions_as_unread!(user)
|
@@ -142,7 +142,7 @@ class Discussion < ApplicationRecord
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def responses_count
|
145
|
-
visible_messages.where
|
145
|
+
visible_messages.where('sender <> ? OR sender_id <> ?', initiator.uid, initiator.id).count
|
146
146
|
end
|
147
147
|
|
148
148
|
def has_responses?
|
data/app/models/message.rb
CHANGED
@@ -4,10 +4,11 @@ class Message < ApplicationRecord
|
|
4
4
|
belongs_to :discussion, optional: true
|
5
5
|
belongs_to :assignment, optional: true
|
6
6
|
belongs_to :approved_by, class_name: 'User', optional: true
|
7
|
+
belongs_to :sender, class_name: 'User'
|
7
8
|
|
8
9
|
has_one :exercise, through: :assignment
|
9
10
|
|
10
|
-
validates_presence_of :content
|
11
|
+
validates_presence_of :content
|
11
12
|
validate :ensure_contextualized
|
12
13
|
|
13
14
|
before_create :mark_from_moderator!
|
@@ -16,7 +17,7 @@ class Message < ApplicationRecord
|
|
16
17
|
markdown_on :content
|
17
18
|
|
18
19
|
# Visible messages are those that can be publicly seen
|
19
|
-
# in forums.
|
20
|
+
# in forums. Direct messages are never visible.
|
20
21
|
scope :visible, -> () do
|
21
22
|
where.not(deletion_motive: :self_deleted)
|
22
23
|
.or(where(deletion_motive: nil))
|
@@ -50,19 +51,15 @@ class Message < ApplicationRecord
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def from_initiator?
|
53
|
-
|
54
|
+
sender == discussion&.initiator
|
54
55
|
end
|
55
56
|
|
56
57
|
def from_moderator?
|
57
|
-
from_moderator ||
|
58
|
+
from_moderator || sender.moderator_here?
|
58
59
|
end
|
59
60
|
|
60
61
|
def from_user?(user)
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
def sender_user
|
65
|
-
User.find_by(uid: sender)
|
62
|
+
sender == user
|
66
63
|
end
|
67
64
|
|
68
65
|
def authorized?(user)
|
@@ -75,9 +72,10 @@ class Message < ApplicationRecord
|
|
75
72
|
|
76
73
|
def to_resource_h
|
77
74
|
as_json(except: [:id, :type, :discussion_id, :approved, :approved_at, :approved_by_id,
|
78
|
-
:not_actually_a_question, :deletion_motive, :deleted_at, :deleted_by_id,
|
75
|
+
:not_actually_a_question, :deletion_motive, :deleted_at, :deleted_by_id,
|
76
|
+
:from_moderator, :sender_id],
|
79
77
|
include: {exercise: {only: [:bibliotheca_id]}})
|
80
|
-
.merge(organization: Organization.current.name)
|
78
|
+
.merge(organization: Organization.current.name, sender: sender.uid)
|
81
79
|
end
|
82
80
|
|
83
81
|
def read!
|
@@ -127,7 +125,7 @@ class Message < ApplicationRecord
|
|
127
125
|
def self.import_from_resource_h!(resource_h)
|
128
126
|
if resource_h['submission_id'].present?
|
129
127
|
assignment = Assignment.find_by(submission_id: resource_h['submission_id'])
|
130
|
-
assignment&.receive_answer! sender: resource_h['message']['sender'],
|
128
|
+
assignment&.receive_answer! sender: User.locate!(resource_h['message']['sender']),
|
131
129
|
content: resource_h['message']['content']
|
132
130
|
end
|
133
131
|
end
|
@@ -137,6 +135,10 @@ class Message < ApplicationRecord
|
|
137
135
|
'message'
|
138
136
|
end
|
139
137
|
|
138
|
+
def sender
|
139
|
+
super || User.locate!(self[:sender])
|
140
|
+
end
|
141
|
+
|
140
142
|
private
|
141
143
|
|
142
144
|
def approve!(user)
|
data/app/models/user.rb
CHANGED
@@ -19,7 +19,7 @@ class User < ApplicationRecord
|
|
19
19
|
has_many :assignments, foreign_key: :submitter_id
|
20
20
|
has_many :indicators
|
21
21
|
has_many :user_stats, class_name: 'UserStats'
|
22
|
-
has_many :
|
22
|
+
has_many :direct_messages, -> { order(created_at: :desc) }, class_name: 'Message', source: :messages, through: :assignments
|
23
23
|
|
24
24
|
has_many :submitted_exercises, through: :assignments, class_name: 'Exercise', source: :exercise
|
25
25
|
|
@@ -61,7 +61,7 @@ class User < ApplicationRecord
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def messages_in_organization(organization = Organization.current)
|
64
|
-
|
64
|
+
direct_messages.where('assignments.organization': organization)
|
65
65
|
end
|
66
66
|
|
67
67
|
def passed_submissions_count_in(organization)
|
@@ -141,9 +141,14 @@ class User < ApplicationRecord
|
|
141
141
|
super.merge(image_url: profile_picture)
|
142
142
|
end
|
143
143
|
|
144
|
-
def verify_name!
|
145
|
-
|
146
|
-
|
144
|
+
def verify_name!(force: false)
|
145
|
+
if force
|
146
|
+
self.verified_first_name = first_name
|
147
|
+
self.verified_last_name = last_name
|
148
|
+
else
|
149
|
+
self.verified_first_name ||= first_name
|
150
|
+
self.verified_last_name ||= last_name
|
151
|
+
end
|
147
152
|
save!
|
148
153
|
end
|
149
154
|
|
@@ -321,7 +326,7 @@ class User < ApplicationRecord
|
|
321
326
|
|
322
327
|
target_assignments = assignments.where(location)
|
323
328
|
|
324
|
-
|
329
|
+
direct_messages.where(assignment: target_assignments).delete_all
|
325
330
|
|
326
331
|
target_assignments.delete_all
|
327
332
|
indicators.where(location).delete_all
|
@@ -336,6 +341,10 @@ class User < ApplicationRecord
|
|
336
341
|
ignored_notifications.include? notification.subject
|
337
342
|
end
|
338
343
|
|
344
|
+
def forum_messages
|
345
|
+
Message.where(sender: self).or(Message.where('sender = ?', uid)).where.not(discussion_id: nil)
|
346
|
+
end
|
347
|
+
|
339
348
|
private
|
340
349
|
|
341
350
|
def welcome_to_new_organizations!
|
data/app/models/user_stats.rb
CHANGED
@@ -32,8 +32,8 @@ class UserStats < ApplicationRecord
|
|
32
32
|
|
33
33
|
def messages_in_discussions_count(date_range = nil)
|
34
34
|
date_filter = { created_at: date_range }.compact
|
35
|
-
result =
|
36
|
-
.where({
|
35
|
+
result = user.forum_messages.joins(:discussion)
|
36
|
+
.where({deletion_motive: nil, discussions: { organization: organization }}.merge(date_filter))
|
37
37
|
.group(:approved)
|
38
38
|
.count
|
39
39
|
unapproved = result[false] || 0
|
@@ -31,10 +31,6 @@ module Mumuki::Domain::Status::Submission
|
|
31
31
|
group.iconize
|
32
32
|
end
|
33
33
|
|
34
|
-
def as_json(_options={})
|
35
|
-
to_s
|
36
|
-
end
|
37
|
-
|
38
34
|
def completed?
|
39
35
|
solved?
|
40
36
|
end
|
@@ -50,8 +46,4 @@ module Mumuki::Domain::Status::Submission
|
|
50
46
|
def exp_given
|
51
47
|
0
|
52
48
|
end
|
53
|
-
|
54
|
-
def dup
|
55
|
-
self
|
56
|
-
end
|
57
49
|
end
|
data/lib/mumuki/domain/status.rb
CHANGED
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.22.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-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -688,6 +688,7 @@ files:
|
|
688
688
|
- db/migrate/20210719145706_add_new_fields_to_notifications.rb
|
689
689
|
- db/migrate/20210803175124_add_ignored_notifications_to_users.rb
|
690
690
|
- db/migrate/20210929223144_add_authorization_requests_limit_to_exam_registration.rb
|
691
|
+
- db/migrate/20211004062332_reference_sender_via_id_in_messages.rb
|
691
692
|
- db/migrate/20211020224011_add_from_moderator_to_messages.rb
|
692
693
|
- lib/mumuki/domain.rb
|
693
694
|
- lib/mumuki/domain/area.rb
|