mumuki-domain 9.10.0 → 9.11.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: 51a03f1d01bc567c0b91939577bd7fad54968380794122c8f93a6355b4d2fd87
4
- data.tar.gz: e953f4fdca9d236bfef4e9ab6d9543fec286229b668cf071830d6c98f38bfa39
3
+ metadata.gz: 641d60f1b417f2fa2a9d05fbdd0357b3415a42a222b8a38ab989c63baf5b064b
4
+ data.tar.gz: db353f1f369e0ae15f0349c2448d476e302921ef36479236408d74bada703f29
5
5
  SHA512:
6
- metadata.gz: 46ef5320c51569aab17dda636d81fcba3cc27cbbf7e9f22f78c96a67b97aa1f7f3d25127c9cd7bded347a5764a91b970c1ec5809c84bb904930d61212cd81cda
7
- data.tar.gz: c3ffff05f15964f1bac7ea31adc0e5c78e09ce7ccc47dee8f95347205b692aa93be2c0f79ed9162fbf27a664eb60e205eeaf7f078e5456b5356a2e73b4db7f2f
6
+ metadata.gz: b8d1d6c40137d84dd7bf3d4c12c406ce88914efb9cce0a231a4ec1758e9b30ac61c881d940c0890a58dfaec3f69eefad432c67de3c88bef11950be1953f71ded
7
+ data.tar.gz: 6e784be9dc46359358a831aae422ebadca1840cc9516d664aaa2d16b3100350dd8887a6dba2b1fa064a697b7a2443848cba238f5692caec72113c45a01ffd035
@@ -8,7 +8,7 @@ module WithDiscussionCreation::Subscription
8
8
  end
9
9
 
10
10
  def subscriptions_in_organization
11
- subscriptions.joins(:discussion).where(discussion: discussions_in_organization)
11
+ subscriptions.where(discussion: Organization.current.discussions)
12
12
  end
13
13
 
14
14
  def subscribed_to?(discussion)
@@ -21,7 +21,7 @@ class Discussion < ApplicationRecord
21
21
  scope :no_responsible_moderator, -> { where('responsible_moderator_at < ?', Time.now - MODERATOR_MAX_RESPONSIBLE_TIME)
22
22
  .or(where(responsible_moderator_at: nil)) }
23
23
  scope :pending_review, -> { where(status: :pending_review) }
24
- scope :unread_first, -> { (includes(:subscriptions).reorder('subscriptions.read')) }
24
+ scope :unread_first, -> { includes(:subscriptions).reorder('subscriptions.read', created_at: :desc) }
25
25
 
26
26
  after_create :subscribe_initiator!
27
27
 
@@ -96,15 +96,15 @@ class Discussion < ApplicationRecord
96
96
  upvotes.find_by(user: user)
97
97
  end
98
98
 
99
- def unread_subscriptions(user)
100
- subscriptions.where.not(user: user).map(&:unread!)
99
+ def mark_subscriptions_as_unread!(user)
100
+ subscriptions.where.not(user: user).each(&:unread!)
101
101
  end
102
102
 
103
103
  def submit_message!(message, user)
104
104
  message.merge!(sender: user.uid)
105
105
  messages.create(message)
106
106
  user.subscribe_to! self
107
- unread_subscriptions(user)
107
+ mark_subscriptions_as_unread!(user)
108
108
  no_responsible! if responsible?(user)
109
109
  end
110
110
 
@@ -183,6 +183,11 @@ class Discussion < ApplicationRecord
183
183
  klazz.constantize.find(debatable_id)
184
184
  end
185
185
 
186
+ # TODO remove this once discussions generate notifications
187
+ def subject
188
+ 'discussion'
189
+ end
190
+
186
191
  private
187
192
 
188
193
  def messages_by_updated_at(direction = :desc)
@@ -32,6 +32,6 @@ class ExamAuthorizationRequest < ApplicationRecord
32
32
  private
33
33
 
34
34
  def notify_user!
35
- Notification.create! organization: organization, user: user, target: self if saved_change_to_status?
35
+ Notification.create_and_notify_via_email! organization: organization, user: user, target: self, subject: 'exam_authorization_request_updated' if saved_change_to_status?
36
36
  end
37
37
  end
@@ -73,9 +73,13 @@ class ExamRegistration < ApplicationRecord
73
73
  registrees.include? user
74
74
  end
75
75
 
76
+ def meets_criterion?(user)
77
+ authorization_criterion.meets_criterion?(user, organization)
78
+ end
79
+
76
80
  private
77
81
 
78
82
  def notify_registree!(registree)
79
- Notification.create! organization: organization, user: registree, target: self
83
+ Notification.create_and_notify_via_email! organization: organization, user: registree, subject: :exam_registration, target: self
80
84
  end
81
85
  end
@@ -34,6 +34,10 @@ class ExamRegistration::AuthorizationCriterion
34
34
  rescue
35
35
  raise "Invalid criterion type #{type}"
36
36
  end
37
+
38
+ def meets_authorization_criteria?(authorization_request)
39
+ meets_criterion? authorization_request.user, authorization_request.organization
40
+ end
37
41
  end
38
42
 
39
43
  class ExamRegistration::AuthorizationCriterion::None < ExamRegistration::AuthorizationCriterion
@@ -45,7 +49,7 @@ class ExamRegistration::AuthorizationCriterion::None < ExamRegistration::Authori
45
49
  !value
46
50
  end
47
51
 
48
- def meets_authorization_criteria?(_authorization_request)
52
+ def meets_criterion?(_user, _organization)
49
53
  true
50
54
  end
51
55
  end
@@ -55,7 +59,7 @@ class ExamRegistration::AuthorizationCriterion::PassedExercises < ExamRegistrati
55
59
  value.positive?
56
60
  end
57
61
 
58
- def meets_authorization_criteria?(authorization_request)
59
- authorization_request.user.passed_submissions_count_in(authorization_request.organization) >= value
62
+ def meets_criterion?(user, organization)
63
+ user.passed_submissions_count_in(organization) >= value
60
64
  end
61
65
  end
@@ -127,6 +127,11 @@ class Message < ApplicationRecord
127
127
  end
128
128
  end
129
129
 
130
+ # TODO remove this once messages generate notifications
131
+ def subject
132
+ 'message'
133
+ end
134
+
130
135
  private
131
136
 
132
137
  def approve!(user)
@@ -1,8 +1,12 @@
1
1
  class Notification < ApplicationRecord
2
2
  belongs_to :user
3
3
  belongs_to :organization
4
- belongs_to :target, polymorphic: true
4
+ belongs_to :target, polymorphic: true, optional: true
5
5
 
6
+ enum subject: %i(
7
+ custom
8
+ exam_authorization_request_updated
9
+ exam_registration)
6
10
 
7
11
  scope :notified_users_ids_for, ->(target, organization=Organization.current) do
8
12
  where(target: target, organization: organization).pluck(:user_id)
@@ -11,4 +15,12 @@ class Notification < ApplicationRecord
11
15
  def mark_as_read!
12
16
  update read: true
13
17
  end
18
+
19
+ def self.create_and_notify_via_email!(args)
20
+ create!(args).tap(&:notify_via_email!)
21
+ end
22
+
23
+ def notify_via_email!
24
+ user.notify_via_email! self
25
+ end
14
26
  end
@@ -148,6 +148,10 @@ class Organization < ApplicationRecord
148
148
  [default_date, in_preparation_until&.to_date].compact.max
149
149
  end
150
150
 
151
+ def discussions
152
+ book.discussions_in_organization(self)
153
+ end
154
+
151
155
  # ==============
152
156
  # Display fields
153
157
  # ==============
data/app/models/user.rb CHANGED
@@ -13,7 +13,7 @@ class User < ApplicationRecord
13
13
  Mumuki::Domain::Helpers::User
14
14
 
15
15
  serialize :permissions, Mumukit::Auth::Permissions
16
-
16
+ serialize :ignored_notifications, Array
17
17
 
18
18
  has_many :notifications
19
19
  has_many :assignments, foreign_key: :submitter_id
@@ -315,6 +315,14 @@ class User < ApplicationRecord
315
315
  user_stats.where(location).delete_all
316
316
  end
317
317
 
318
+ def notify_via_email!(notification)
319
+ UserMailer.notification(notification).deliver_later unless ignores_notification? notification
320
+ end
321
+
322
+ def ignores_notification?(notification)
323
+ ignored_notifications.include? notification.subject
324
+ end
325
+
318
326
  private
319
327
 
320
328
  def welcome_to_new_organizations!
@@ -0,0 +1,8 @@
1
+ class AddNewFieldsToNotifications < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :notifications, :subject, :integer
4
+ add_column :notifications, :custom_title, :text
5
+ add_column :notifications, :custom_content_plain_text, :text
6
+ add_column :notifications, :custom_content_html, :text
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class AddIgnoredNotificationsToUsers < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :users, :ignored_notifications, :text
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '9.10.0'
3
+ VERSION = '9.11.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.10.0
4
+ version: 9.11.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-07-29 00:00:00.000000000 Z
11
+ date: 2021-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -672,6 +672,8 @@ files:
672
672
  - db/migrate/20210512200453_add_processed_flag_to_exam_registration.rb
673
673
  - db/migrate/20210518100153_rename_last_moderator_access.rb
674
674
  - db/migrate/20210707143002_add_assignment_id_to_message.rb
675
+ - db/migrate/20210719145706_add_new_fields_to_notifications.rb
676
+ - db/migrate/20210803175124_add_ignored_notifications_to_users.rb
675
677
  - lib/mumuki/domain.rb
676
678
  - lib/mumuki/domain/area.rb
677
679
  - lib/mumuki/domain/engine.rb