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 +4 -4
- data/app/models/concerns/with_discussion_creation/subscription.rb +1 -1
- data/app/models/discussion.rb +9 -4
- data/app/models/exam_authorization_request.rb +1 -1
- data/app/models/exam_registration.rb +5 -1
- data/app/models/exam_registration/authorization_criterion.rb +7 -3
- data/app/models/message.rb +5 -0
- data/app/models/notification.rb +13 -1
- data/app/models/organization.rb +4 -0
- data/app/models/user.rb +9 -1
- data/db/migrate/20210719145706_add_new_fields_to_notifications.rb +8 -0
- data/db/migrate/20210803175124_add_ignored_notifications_to_users.rb +5 -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: 641d60f1b417f2fa2a9d05fbdd0357b3415a42a222b8a38ab989c63baf5b064b
|
4
|
+
data.tar.gz: db353f1f369e0ae15f0349c2448d476e302921ef36479236408d74bada703f29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
11
|
+
subscriptions.where(discussion: Organization.current.discussions)
|
12
12
|
end
|
13
13
|
|
14
14
|
def subscribed_to?(discussion)
|
data/app/models/discussion.rb
CHANGED
@@ -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, -> {
|
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
|
100
|
-
subscriptions.where.not(user: user).
|
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
|
-
|
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.
|
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.
|
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
|
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
|
59
|
-
|
62
|
+
def meets_criterion?(user, organization)
|
63
|
+
user.passed_submissions_count_in(organization) >= value
|
60
64
|
end
|
61
65
|
end
|
data/app/models/message.rb
CHANGED
data/app/models/notification.rb
CHANGED
@@ -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
|
data/app/models/organization.rb
CHANGED
@@ -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
|
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.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-
|
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
|