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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95912abc73b50f774b4e87873ea35afa3ce9016d4cf90ce9af6cfb9c88ea9c56
4
- data.tar.gz: 3d2cbbf7c128f280edb477d38ad3a37770943ba9a0e6809d54936c62efb54186
3
+ metadata.gz: 3822b6222097cb19717c7d6a76c97988f3993ef342b7e238a38ffbba6dbd7bb7
4
+ data.tar.gz: 2d6a733e2f9daf5d7c4fe6694f59ce1f5f7887067121d2af0a772be73e785b3a
5
5
  SHA512:
6
- metadata.gz: 54c74640cdef38c3aeec166b5fded89c82f4f867b37f83a2d0b3e24ef0bb4e0f0b707de265aaae9b56decfe6bdfadc6aa0448fb16506af72119ab3dca0e860c8
7
- data.tar.gz: 75949f754f836b0315f5e717532e02de38a8222819d2ae4441df4b524e7fda2c55f45a12696d034060f3a1754120c6707f1cc6d3b9682d591d6c9edd8521fa58
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
@@ -4,7 +4,7 @@ module WithMessages
4
4
  end
5
5
 
6
6
  def send_question!(question)
7
- message = build_message question.merge(sender: submitter.uid, read: true)
7
+ message = build_message question.merge(sender: submitter, read: true)
8
8
  message.save_and_notify!
9
9
  end
10
10
 
@@ -103,7 +103,7 @@ class Discussion < ApplicationRecord
103
103
  end
104
104
 
105
105
  def submit_message!(message, user)
106
- message.merge!(sender: user.uid)
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.not(sender: initiator.uid).count
145
+ visible_messages.where('sender <> ? OR sender_id <> ?', initiator.uid, initiator.id).count
146
146
  end
147
147
 
148
148
  def has_responses?
@@ -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, :sender
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. non-direct messages are never visible.
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
- sender_user == discussion&.initiator
54
+ sender == discussion&.initiator
54
55
  end
55
56
 
56
57
  def from_moderator?
57
- from_moderator || sender_user.moderator_here?
58
+ from_moderator || sender.moderator_here?
58
59
  end
59
60
 
60
61
  def from_user?(user)
61
- sender_user == user
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, :from_moderator],
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 :messages, -> { order(created_at: :desc) }, through: :assignments
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
- messages.where('assignments.organization': organization)
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
- self.verified_first_name ||= first_name
146
- self.verified_last_name ||= last_name
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
- messages.where(assignment: target_assignments).delete_all
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!
@@ -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 = Message.joins(:discussion)
36
- .where({sender: user.uid, deletion_motive: nil, discussions: { organization: organization }}.merge(date_filter))
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
@@ -0,0 +1,5 @@
1
+ class ReferenceSenderViaIdInMessages < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_reference :messages, :sender, index: true
4
+ end
5
+ end
@@ -1,6 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :message do
3
3
  content { Faker::Lorem.sentence(word_count: 3) }
4
- sender { create(:user).uid }
4
+ sender { create(:user) }
5
5
  end
6
6
  end
@@ -33,8 +33,4 @@ module Mumuki::Domain::Status::Discussion
33
33
  reachable_statuses_for_initiator(discussion)
34
34
  end
35
35
  end
36
-
37
- def as_json(_options={})
38
- to_s
39
- end
40
36
  end
@@ -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
@@ -25,6 +25,14 @@ module Mumuki::Domain::Status
25
25
  self.equal? parent.to_mumuki_status(other) rescue false
26
26
  end
27
27
 
28
+ def as_json(_options={})
29
+ to_s
30
+ end
31
+
32
+ def dup
33
+ self
34
+ end
35
+
28
36
  class_methods do
29
37
  def load(i)
30
38
  cast(i)
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '9.21.0'
3
+ VERSION = '9.22.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.21.0
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-10-28 00:00:00.000000000 Z
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