mumuki-domain 9.4.0 → 9.8.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: ddd0081f4ed25d268fe17c327be9b5b343a21b2491eb737db4ee837fb16eead8
4
- data.tar.gz: 7e34398bd300598d749d628af5ae31a49985ff62f8dda2ce2598169197cacc2d
3
+ metadata.gz: 27f2a30ca00c41bffa5a3673fe92328ee1b0565d27a8e3e2ac34e40e791ac2ca
4
+ data.tar.gz: be141181663a286b037540f0a7b553a190d20b254429eff0e9f64263f60bbfc4
5
5
  SHA512:
6
- metadata.gz: 87e8fbb20f42949df631f2696c1d10a0c40744b7f84a1c7b705e525a8f2120a1e1ce5a58231a9bb9c2faa4987bd031eba01d3eb01a3e407f7202c4469eaeda72
7
- data.tar.gz: 9196ae6c744c474853ffb027cf86f015546539ef994f83c62f27199123e54dbda3372fbd141a22f86c349270a0d14b1e6cdf3fdda47f3476bc6cd594ceb6e742
6
+ metadata.gz: 9c5bb7a56c9fb93812146a45e21c74e438036812243c3566f01baf1916d0fce49c0be5a3153c0c973122d45e4b5556eddc64602f794fd2c838669470208b6032
7
+ data.tar.gz: 2eb10bc2416e79bb20e05bf4eea458ea834aa68fa5e14af7d4e45043e3c49827961de4d35eaf7a2b0fb34fb4360b2654a85fada4056bd7ba3f22f32c4aaf7703
@@ -103,6 +103,21 @@ class ApplicationRecord < ActiveRecord::Base
103
103
  end
104
104
  end
105
105
 
106
+ def self.with_pg_retry(&block)
107
+ retries ||= 0
108
+ transaction(&block)
109
+ rescue ActiveRecord::StatementInvalid => e
110
+ retries += 1
111
+
112
+ raise e if retries > 2
113
+ if %w(PG::ConnectionBad PG::UnableToSend).any? { |it| e.message.include? it }
114
+ warn "Postgres connection failed. Retrying in 5 seconds..."
115
+ sleep 5
116
+ ActiveRecord::Base.connection.verify!
117
+ retry
118
+ end
119
+ end
120
+
106
121
  def self.numbered(*associations)
107
122
  class_eval do
108
123
  associations.each do |it|
@@ -7,7 +7,8 @@ module WithNotifications
7
7
 
8
8
  def unread_notifications
9
9
  # TODO: message and discussion should trigger a notification instead of being one
10
- all = notifications.where(read: false) + unread_messages + unread_discussions
10
+ # include message notifications once they are properly implemented
11
+ all = notifications.where(read: false) + unread_discussions
11
12
  all.sort_by(&:created_at).reverse
12
13
  end
13
14
 
@@ -0,0 +1,51 @@
1
+ module WithResponsibleModerator
2
+ extend ActiveSupport::Concern
3
+
4
+ MODERATOR_MAX_RESPONSIBLE_TIME = 45.minutes
5
+
6
+ def toggle_responsible!(moderator)
7
+ if responsible?(moderator)
8
+ no_responsible!
9
+ elsif no_current_responsible?
10
+ responsible! moderator
11
+ end
12
+ end
13
+
14
+ def any_responsible?
15
+ responsible_moderator_at.present? && (responsible_moderator_at + MODERATOR_MAX_RESPONSIBLE_TIME).future?
16
+ end
17
+
18
+ def no_current_responsible?
19
+ !any_responsible?
20
+ end
21
+
22
+ def responsible?(moderator)
23
+ any_responsible? && responsible_moderator_by == moderator
24
+ end
25
+
26
+ def current_responsible_visible_for?(user)
27
+ user&.moderator_here? && any_responsible?
28
+ end
29
+
30
+ def can_toggle_responsible?(user)
31
+ can_have_responsible? && user_can_be_responsible?(user)
32
+ end
33
+
34
+ private
35
+
36
+ def responsible!(moderator)
37
+ update! responsible_moderator_at: Time.now, responsible_moderator_by: moderator
38
+ end
39
+
40
+ def no_responsible!
41
+ update! responsible_moderator_at: nil, responsible_moderator_by: nil
42
+ end
43
+
44
+ def user_can_be_responsible?(user)
45
+ user&.moderator_here? && (no_current_responsible? || responsible?(user))
46
+ end
47
+
48
+ def can_have_responsible?
49
+ opened? || pending_review?
50
+ end
51
+ end
@@ -1,11 +1,11 @@
1
1
  class Discussion < ApplicationRecord
2
- include WithDiscussionStatus, WithScopedQueries, Contextualization
2
+ include WithDiscussionStatus, WithScopedQueries, Contextualization, WithResponsibleModerator
3
3
 
4
4
  belongs_to :item, polymorphic: true
5
5
  has_many :messages, -> { order(:created_at) }, dependent: :destroy
6
6
  belongs_to :initiator, class_name: 'User'
7
7
 
8
- belongs_to :last_moderator_access_by, class_name: 'User', optional: true
8
+ belongs_to :responsible_moderator_by, class_name: 'User', optional: true
9
9
  belongs_to :status_updated_by, class_name: 'User', optional: true
10
10
 
11
11
  belongs_to :exercise, foreign_type: :exercise, foreign_key: 'item_id'
@@ -15,21 +15,24 @@ class Discussion < ApplicationRecord
15
15
 
16
16
  scope :by_language, -> (language) { includes(:exercise).joins(exercise: :language).where(languages: {name: language}) }
17
17
  scope :order_by_responses_count, -> (direction) { reorder(validated_messages_count: direction, messages_count: opposite(direction)) }
18
- scope :by_requires_moderator_response, -> (boolean) { where(requires_moderator_response: boolean.to_boolean) }
18
+ scope :by_requires_attention, -> (boolean) { opened_and_requires_moderator_response(boolean).or(pending_review).no_responsible_moderator }
19
+ scope :opened_and_requires_moderator_response, -> (boolean) { where(requires_moderator_response: boolean.to_boolean)
20
+ .where(status: :opened) }
21
+ scope :no_responsible_moderator, -> { where('responsible_moderator_at < ?', Time.now - MODERATOR_MAX_RESPONSIBLE_TIME)
22
+ .or(where(responsible_moderator_at: nil)) }
23
+ scope :pending_review, -> { where(status: :pending_review) }
19
24
 
20
25
  after_create :subscribe_initiator!
21
26
 
22
27
  markdown_on :description
23
28
 
24
29
  sortable :responses_count, :upvotes_count, :created_at, default: :created_at_desc
25
- filterable :status, :language, :requires_moderator_response
30
+ filterable :status, :language, :requires_attention
26
31
  pageable
27
32
 
28
33
  delegate :language, to: :item
29
34
  delegate :to_discussion_status, to: :status
30
35
 
31
- MODERATOR_REVIEW_AVERAGE_TIME = 17.minutes
32
-
33
36
  scope :for_user, -> (user) do
34
37
  if user.try(:moderator_here?)
35
38
  all
@@ -81,7 +84,7 @@ class Discussion < ApplicationRecord
81
84
  end
82
85
 
83
86
  def friendly
84
- initiator.name
87
+ initiator.abbreviated_name
85
88
  end
86
89
 
87
90
  def subscription_for(user)
@@ -101,6 +104,7 @@ class Discussion < ApplicationRecord
101
104
  messages.create(message)
102
105
  user.subscribe_to! self
103
106
  unread_subscriptions(user)
107
+ no_responsible! if responsible?(user)
104
108
  end
105
109
 
106
110
  def authorized?(user)
@@ -125,6 +129,8 @@ class Discussion < ApplicationRecord
125
129
  update! status: status,
126
130
  status_updated_by: user,
127
131
  status_updated_at: Time.now
132
+
133
+ no_responsible! if responsible?(user)
128
134
  end
129
135
  end
130
136
 
@@ -144,6 +150,14 @@ class Discussion < ApplicationRecord
144
150
  validated_messages_count > 0
145
151
  end
146
152
 
153
+ def requires_attention_for?(user)
154
+ user&.moderator_here? && requires_attention?
155
+ end
156
+
157
+ def requires_attention?
158
+ no_current_responsible? && status.requires_attention_for?(self)
159
+ end
160
+
147
161
  def subscribe_initiator!
148
162
  initiator.subscribe_to! self
149
163
  end
@@ -163,25 +177,6 @@ class Discussion < ApplicationRecord
163
177
  requires_moderator_response: !has_moderator_response
164
178
  end
165
179
 
166
- def update_last_moderator_access!(user)
167
- if user&.moderator_here? && !last_moderator_access_visible_for?(user)
168
- update! last_moderator_access_at: Time.now,
169
- last_moderator_access_by: user
170
- end
171
- end
172
-
173
- def being_accessed_by_moderator?
174
- last_moderator_access_at.present? && (last_moderator_access_at + MODERATOR_REVIEW_AVERAGE_TIME).future?
175
- end
176
-
177
- def last_moderator_access_visible_for?(user)
178
- show_last_moderator_access_for?(user) && being_accessed_by_moderator?
179
- end
180
-
181
- def show_last_moderator_access_for?(user)
182
- user&.moderator_here? && last_moderator_access_by != user
183
- end
184
-
185
180
  def self.debatable_for(klazz, params)
186
181
  debatable_id = params[:"#{klazz.underscore}_id"]
187
182
  klazz.constantize.find(debatable_id)
@@ -11,7 +11,7 @@ class UserStats < ApplicationRecord
11
11
  end
12
12
 
13
13
  def activity(date_range = nil)
14
- date_filter = { submitted_at: date_range }.compact
14
+ date_filter = { updated_at: date_range }.compact
15
15
  {
16
16
  exercises: {
17
17
  solved_count: organization_exercises
@@ -0,0 +1,6 @@
1
+ class RenameLastModeratorAccess < ActiveRecord::Migration[5.1]
2
+ def change
3
+ rename_column :discussions, :last_moderator_access_by_id, :responsible_moderator_by_id
4
+ rename_column :discussions, :last_moderator_access_at, :responsible_moderator_at
5
+ end
6
+ end
@@ -6,6 +6,7 @@ FactoryBot.define do
6
6
  locale { 'en' }
7
7
  settings {}
8
8
  name { 'an-organization' }
9
+ time_zone { 'UTC' }
9
10
  book
10
11
  end
11
12
 
@@ -13,7 +13,8 @@ class Mumuki::Domain::Organization::Profile < Mumukit::Platform::Model
13
13
  :community_link,
14
14
  :errors_explanations,
15
15
  :welcome_email_template,
16
- :welcome_email_sender
16
+ :welcome_email_sender,
17
+ :time_zone
17
18
 
18
19
  def locale_json
19
20
  locale_h.to_json
@@ -38,4 +39,9 @@ class Mumuki::Domain::Organization::Profile < Mumukit::Platform::Model
38
39
  def open_graph_image_url
39
40
  @open_graph_image_url ||= Mumukit::Platform.laboratory.url_for("logo-alt.png") # Best image size: 256x256
40
41
  end
42
+
43
+ def time_zone
44
+ @time_zone || 'Buenos Aires'
45
+ end
46
+
41
47
  end
@@ -46,4 +46,5 @@ class Mumuki::Domain::Organization::Settings < Mumukit::Platform::Model
46
46
  def in_preparation?
47
47
  in_preparation_until.present? && in_preparation_until.future?
48
48
  end
49
+
49
50
  end
@@ -12,4 +12,8 @@ module Mumuki::Domain::Status::Discussion::Closed
12
12
  def self.iconize
13
13
  {class: :danger, type: 'times-circle'}
14
14
  end
15
+
16
+ def self.requires_attention_for?(_)
17
+ false
18
+ end
15
19
  end
@@ -28,4 +28,8 @@ module Mumuki::Domain::Status::Discussion::Opened
28
28
  def self.should_be_shown?(*)
29
29
  true
30
30
  end
31
+
32
+ def self.requires_attention_for?(discussion)
33
+ discussion.requires_moderator_response?
34
+ end
31
35
  end
@@ -12,4 +12,8 @@ module Mumuki::Domain::Status::Discussion::PendingReview
12
12
  def self.iconize
13
13
  {class: :info, type: 'hourglass'}
14
14
  end
15
+
16
+ def self.requires_attention_for?(_)
17
+ true
18
+ end
15
19
  end
@@ -16,4 +16,8 @@ module Mumuki::Domain::Status::Discussion::Solved
16
16
  def self.should_be_shown?(*)
17
17
  true
18
18
  end
19
+
20
+ def self.requires_attention_for?(_)
21
+ false
22
+ end
19
23
  end
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '9.4.0'
3
+ VERSION = '9.8.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.4.0
4
+ version: 9.8.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-06-03 00:00:00.000000000 Z
11
+ date: 2021-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -297,6 +297,7 @@ files:
297
297
  - app/models/concerns/with_progress.rb
298
298
  - app/models/concerns/with_randomizations.rb
299
299
  - app/models/concerns/with_reminders.rb
300
+ - app/models/concerns/with_responsible_moderator.rb
300
301
  - app/models/concerns/with_scoped_queries.rb
301
302
  - app/models/concerns/with_scoped_queries/filter.rb
302
303
  - app/models/concerns/with_scoped_queries/page.rb
@@ -668,6 +669,7 @@ files:
668
669
  - db/migrate/20210318195238_rename_certificate_dates.rb
669
670
  - db/migrate/20210330175706_create_exam_registration_user_join_table.rb
670
671
  - db/migrate/20210512200453_add_processed_flag_to_exam_registration.rb
672
+ - db/migrate/20210518100153_rename_last_moderator_access.rb
671
673
  - lib/mumuki/domain.rb
672
674
  - lib/mumuki/domain/area.rb
673
675
  - lib/mumuki/domain/engine.rb