mumuki-domain 9.4.0 → 9.5.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: ddd0081f4ed25d268fe17c327be9b5b343a21b2491eb737db4ee837fb16eead8
4
- data.tar.gz: 7e34398bd300598d749d628af5ae31a49985ff62f8dda2ce2598169197cacc2d
3
+ metadata.gz: 85f8e4d573ce0f6681d4e1924eecdf84e2967a033e3090c4a649f585e7587081
4
+ data.tar.gz: c0cc95b03d98873b09c462b34cc69c741b638f04f8fce6f184c28472853449b2
5
5
  SHA512:
6
- metadata.gz: 87e8fbb20f42949df631f2696c1d10a0c40744b7f84a1c7b705e525a8f2120a1e1ce5a58231a9bb9c2faa4987bd031eba01d3eb01a3e407f7202c4469eaeda72
7
- data.tar.gz: 9196ae6c744c474853ffb027cf86f015546539ef994f83c62f27199123e54dbda3372fbd141a22f86c349270a0d14b1e6cdf3fdda47f3476bc6cd594ceb6e742
6
+ metadata.gz: f92c8f47f514d0d5a38e5ce78dd93745591ce7344758c679439ee60388b5863e64e80b1061572b03c7842792dce189554fe7d986f49130940ad83faf8968bb8d
7
+ data.tar.gz: 6fb9c49eb8232748fb02fdb45866583a913c17416071af6de67cdf9cca2013a886d01c1df25035a17c54f09b7158d152312e3526c10355743659145aa9ac8208
@@ -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'
@@ -28,8 +28,6 @@ class Discussion < ApplicationRecord
28
28
  delegate :language, to: :item
29
29
  delegate :to_discussion_status, to: :status
30
30
 
31
- MODERATOR_REVIEW_AVERAGE_TIME = 17.minutes
32
-
33
31
  scope :for_user, -> (user) do
34
32
  if user.try(:moderator_here?)
35
33
  all
@@ -81,7 +79,7 @@ class Discussion < ApplicationRecord
81
79
  end
82
80
 
83
81
  def friendly
84
- initiator.name
82
+ initiator.abbreviated_name
85
83
  end
86
84
 
87
85
  def subscription_for(user)
@@ -101,6 +99,7 @@ class Discussion < ApplicationRecord
101
99
  messages.create(message)
102
100
  user.subscribe_to! self
103
101
  unread_subscriptions(user)
102
+ no_responsible! if responsible?(user)
104
103
  end
105
104
 
106
105
  def authorized?(user)
@@ -125,6 +124,8 @@ class Discussion < ApplicationRecord
125
124
  update! status: status,
126
125
  status_updated_by: user,
127
126
  status_updated_at: Time.now
127
+
128
+ no_responsible! if responsible?(user)
128
129
  end
129
130
  end
130
131
 
@@ -163,25 +164,6 @@ class Discussion < ApplicationRecord
163
164
  requires_moderator_response: !has_moderator_response
164
165
  end
165
166
 
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
167
  def self.debatable_for(klazz, params)
186
168
  debatable_id = params[:"#{klazz.underscore}_id"]
187
169
  klazz.constantize.find(debatable_id)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '9.4.0'
3
+ VERSION = '9.5.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.4.0
4
+ version: 9.5.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-06-03 00:00:00.000000000 Z
11
+ date: 2021-06-10 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