mumuki-domain 9.19.0 → 9.22.1

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: bcb85dd95292fca604bdfd6f77560b37650766ede8bfbf1b7afe9caf4a105efd
4
- data.tar.gz: ed1292935f907bde74fe777fd48de3d61ef87c5f62e6db4c3c7c0ae50c5ce3de
3
+ metadata.gz: 138e6386f4e43861b313756d9ee01943ab84d4beef60faf7936f587ac4e40f82
4
+ data.tar.gz: 54afa2c2e250eec1de884cdf64568ec6d6c113508119884a6e96bfb7d91376f0
5
5
  SHA512:
6
- metadata.gz: fcc442e31b9f5b510c8a5a99d78bcbd98b8a0f36b828badeb64e25e8eaeecb3d910c7348da4b263047f52e5c6bd9ad6ee8412cfcfdf932cee5418a2ee48cfb7c
7
- data.tar.gz: 6f888100f4dc2b1f9c332c3f8b9ebc257c1eb3aa2534c7db85bd0b4f4328f9fc2cd24f8da23ecbd04bb1dab8edd56ad236dac2dd6505ea8451ee5c5b6212c570
6
+ metadata.gz: f52a72a3f090f95962572aa1cc17697ce4c1cec4608cb25dfbebf74db8f394349750868027865ef9f3cba9fd9564a8598875e4e17231e41b38bae06ed0abbec3
7
+ data.tar.gz: 2b4e6faed9348156829d672cc4ab98a093348f33831a14aec6ed5b197ba44277ad1a8bdbf4bd2667a6b95e6b1c274fd798eadf92979cb7876a0092108a28e6b2
@@ -186,8 +186,8 @@ class Assignment < Progress
186
186
  language: {only: [:name]}},
187
187
  },
188
188
  exercise: {only: [:name, :number]},
189
- submitter: {only: [:email, :social_id, :uid], methods: [:name, :profile_picture]}}).
190
- deep_merge(
189
+ submitter: {only: [:email, :social_id, :uid], methods: [:name, :profile_picture]}})
190
+ .deep_merge(
191
191
  'organization' => Organization.current.name,
192
192
  'sid' => submission_id,
193
193
  'created_at' => submitted_at || updated_at,
@@ -202,6 +202,7 @@ class Assignment < Progress
202
202
  'position' => navigable_parent.try(:number),
203
203
  'chapter' => guide.chapter.as_json(only: [:id], methods: [:name])
204
204
  }})
205
+ .merge({'randomized_values' => randomized_values.presence}.compact)
205
206
  end
206
207
 
207
208
  def tips
@@ -10,6 +10,6 @@ module Gamified
10
10
  end
11
11
 
12
12
  def net_experience
13
- submission_status.exp_given - top_submission_status.exp_given
13
+ submitter.currently_in_exam? ? 0 : (submission_status.exp_given - top_submission_status.exp_given)
14
14
  end
15
15
  end
@@ -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
 
@@ -0,0 +1,14 @@
1
+ module WithScopedQueries::Limit
2
+ def self.query_by(params, current_scope, _)
3
+ if params[:limit].present?
4
+ max_limit = [params[:limit].to_i, 25].min
5
+ current_scope.limit(max_limit)
6
+ else
7
+ current_scope
8
+ end
9
+ end
10
+
11
+ def self.add_queriable_attributes_to(klass, _)
12
+ klass.queriable_attributes.merge!(limit: :limit)
13
+ end
14
+ end
@@ -1,10 +1,14 @@
1
1
  module WithScopedQueries::Page
2
2
  def self.query_by(params, current_scope, _)
3
- page_param = params[:page] || 1
4
- current_scope.page(page_param).per(10)
3
+ if params[:limit].present?
4
+ current_scope
5
+ else
6
+ page_param = params[:page] || 1
7
+ current_scope.page(page_param).per(10)
8
+ end
5
9
  end
6
10
 
7
11
  def self.add_queriable_attributes_to(klass, _)
8
- klass.queriable_attributes.merge!(page: :page)
12
+ klass.queriable_attributes.merge!(page: [:page, :limit])
9
13
  end
10
14
  end
@@ -1,7 +1,7 @@
1
1
  module WithScopedQueries
2
2
  extend ActiveSupport::Concern
3
3
 
4
- SCOPING_METHODS = [Filter, Sort, Page]
4
+ SCOPING_METHODS = [Filter, Sort, Page, Limit]
5
5
 
6
6
  included do
7
7
  class_attribute :queriable_attributes, instance_writer: false
@@ -22,14 +22,16 @@ class Discussion < ApplicationRecord
22
22
  .or(where(responsible_moderator_at: nil)) }
23
23
  scope :pending_review, -> { where(status: :pending_review) }
24
24
  scope :unread_first, -> { includes(:subscriptions).reorder('subscriptions.read', created_at: :desc) }
25
+ scope :by_recent, -> (_) { where('created_at > ?', Time.now - 6.months)}
25
26
 
26
27
  after_create :subscribe_initiator!
27
28
 
28
29
  markdown_on :description
29
30
 
30
31
  sortable :responses_count, :upvotes_count, :created_at, default: :created_at_desc
31
- filterable :status, :language, :requires_attention
32
+ filterable :status, :language, :requires_attention, :recent
32
33
  pageable
34
+ limitable
33
35
 
34
36
  delegate :language, to: :item
35
37
  delegate :to_discussion_status, to: :status
@@ -101,7 +103,7 @@ class Discussion < ApplicationRecord
101
103
  end
102
104
 
103
105
  def submit_message!(message, user)
104
- message.merge!(sender: user.uid)
106
+ message.merge!(sender: user)
105
107
  messages.create(message)
106
108
  user.subscribe_to! self
107
109
  mark_subscriptions_as_unread!(user)
@@ -140,7 +142,7 @@ class Discussion < ApplicationRecord
140
142
  end
141
143
 
142
144
  def responses_count
143
- visible_messages.where.not(sender: initiator.uid).count
145
+ visible_messages.where('sender <> ? OR sender_id <> ?', initiator.uid, initiator.id).count
144
146
  end
145
147
 
146
148
  def has_responses?
@@ -4,18 +4,20 @@ 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
 
14
+ before_create :mark_from_moderator!
13
15
  after_save :update_counters_cache!
14
16
 
15
17
  markdown_on :content
16
18
 
17
19
  # Visible messages are those that can be publicly seen
18
- # in forums. non-direct messages are never visible.
20
+ # in forums. Direct messages are never visible.
19
21
  scope :visible, -> () do
20
22
  where.not(deletion_motive: :self_deleted)
21
23
  .or(where(deletion_motive: nil))
@@ -49,19 +51,15 @@ class Message < ApplicationRecord
49
51
  end
50
52
 
51
53
  def from_initiator?
52
- sender_user == discussion&.initiator
54
+ sender == discussion&.initiator
53
55
  end
54
56
 
55
57
  def from_moderator?
56
- sender_user.moderator_here?
58
+ from_moderator || sender.moderator_here?
57
59
  end
58
60
 
59
61
  def from_user?(user)
60
- sender_user == user
61
- end
62
-
63
- def sender_user
64
- User.find_by(uid: sender)
62
+ sender == user
65
63
  end
66
64
 
67
65
  def authorized?(user)
@@ -74,9 +72,10 @@ class Message < ApplicationRecord
74
72
 
75
73
  def to_resource_h
76
74
  as_json(except: [:id, :type, :discussion_id, :approved, :approved_at, :approved_by_id,
77
- :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],
78
77
  include: {exercise: {only: [:bibliotheca_id]}})
79
- .merge(organization: Organization.current.name)
78
+ .merge(organization: Organization.current.name, sender: sender.uid)
80
79
  end
81
80
 
82
81
  def read!
@@ -103,6 +102,10 @@ class Message < ApplicationRecord
103
102
  approved? || from_moderator?
104
103
  end
105
104
 
105
+ def mark_from_moderator!
106
+ self.from_moderator = from_moderator?
107
+ end
108
+
106
109
  def update_counters_cache!
107
110
  discussion&.update_counters!
108
111
  end
@@ -122,7 +125,7 @@ class Message < ApplicationRecord
122
125
  def self.import_from_resource_h!(resource_h)
123
126
  if resource_h['submission_id'].present?
124
127
  assignment = Assignment.find_by(submission_id: resource_h['submission_id'])
125
- assignment&.receive_answer! sender: resource_h['message']['sender'],
128
+ assignment&.receive_answer! sender: User.locate!(resource_h['message']['sender']),
126
129
  content: resource_h['message']['content']
127
130
  end
128
131
  end
@@ -132,6 +135,10 @@ class Message < ApplicationRecord
132
135
  'message'
133
136
  end
134
137
 
138
+ def sender
139
+ super || User.locate!(self[:sender])
140
+ end
141
+
135
142
  private
136
143
 
137
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
@@ -0,0 +1,5 @@
1
+ class AddFromModeratorToMessages < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :messages, :from_moderator, :boolean
4
+ end
5
+ end
@@ -1,6 +1,6 @@
1
1
  FactoryBot.define do
2
-
3
2
  factory :message do
4
3
  content { Faker::Lorem.sentence(word_count: 3) }
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.19.0'
3
+ VERSION = '9.22.1'
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.19.0
4
+ version: 9.22.1
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-19 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
@@ -306,6 +306,7 @@ files:
306
306
  - app/models/concerns/with_responsible_moderator.rb
307
307
  - app/models/concerns/with_scoped_queries.rb
308
308
  - app/models/concerns/with_scoped_queries/filter.rb
309
+ - app/models/concerns/with_scoped_queries/limit.rb
309
310
  - app/models/concerns/with_scoped_queries/page.rb
310
311
  - app/models/concerns/with_scoped_queries/sort.rb
311
312
  - app/models/concerns/with_slug.rb
@@ -687,6 +688,8 @@ files:
687
688
  - db/migrate/20210719145706_add_new_fields_to_notifications.rb
688
689
  - db/migrate/20210803175124_add_ignored_notifications_to_users.rb
689
690
  - db/migrate/20210929223144_add_authorization_requests_limit_to_exam_registration.rb
691
+ - db/migrate/20211004062332_reference_sender_via_id_in_messages.rb
692
+ - db/migrate/20211020224011_add_from_moderator_to_messages.rb
690
693
  - lib/mumuki/domain.rb
691
694
  - lib/mumuki/domain/area.rb
692
695
  - lib/mumuki/domain/engine.rb