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 +4 -4
- data/app/models/application_record.rb +15 -0
- data/app/models/concerns/with_notifications.rb +2 -1
- data/app/models/concerns/with_responsible_moderator.rb +51 -0
- data/app/models/discussion.rb +21 -26
- data/app/models/user_stats.rb +1 -1
- data/db/migrate/20210518100153_rename_last_moderator_access.rb +6 -0
- data/lib/mumuki/domain/factories/organization_factory.rb +1 -0
- data/lib/mumuki/domain/organization/profile.rb +7 -1
- data/lib/mumuki/domain/organization/settings.rb +1 -0
- data/lib/mumuki/domain/status/discussion/closed.rb +4 -0
- data/lib/mumuki/domain/status/discussion/opened.rb +4 -0
- data/lib/mumuki/domain/status/discussion/pending_review.rb +4 -0
- data/lib/mumuki/domain/status/discussion/solved.rb +4 -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: 27f2a30ca00c41bffa5a3673fe92328ee1b0565d27a8e3e2ac34e40e791ac2ca
|
4
|
+
data.tar.gz: be141181663a286b037540f0a7b553a190d20b254429eff0e9f64263f60bbfc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
data/app/models/discussion.rb
CHANGED
@@ -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 :
|
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 :
|
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, :
|
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.
|
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)
|
data/app/models/user_stats.rb
CHANGED
@@ -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
|
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.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
|
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
|