mumuki-domain 8.5.0 → 8.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8de3b061fa4456ea064c8a2d782b6e78f4f4685c022b58b21942095f7fbbf838
4
- data.tar.gz: 34c7fc5d21ebb806bda2b59faf5a54c2389545fbc4b5ad66bc89bc7c3a3dd8f8
3
+ metadata.gz: 0fc67d5d416345806e5d570dae375114d9bd32e3be5af26485a926c9957d10f2
4
+ data.tar.gz: cb223b383c8f176ac852091b8cf79ed2f496404bc75d1d7dcc3ccfbde70e49f2
5
5
  SHA512:
6
- metadata.gz: 9de9ccc06eeb08ad7fc4eb18b0bad4b93d095343135900e0199587efdba3a10182fe902653c828baed7ef16f1adf52913c3747d844aa19a636946b3a9d05cc44
7
- data.tar.gz: 17d913971689eceb1aeb165dbc8c6eec0e8ea4b314097c1ea9a5d8da2e9ed1c9cb46bb5c347db11d8f74b516cc2feb72b38ff79b67eade1510d4b20498617d71
6
+ metadata.gz: 3a891889e37c9fd9a55c383f2ffe6aa2f9368193bb7550ba34d9253fb8fbab3534be85ac6acc8a162f02907059acc57da14658ee6df7ad19ad93523ee1ef998d
7
+ data.tar.gz: e830934dd132b0bada6f45348249f06d170438c98fbb07528fa1e608397b40945485adeb4a79e732d701371e4196a9fae22c5e4ba68ef983a71dc7ae40236704
@@ -129,6 +129,12 @@ class ApplicationRecord < ActiveRecord::Base
129
129
  end
130
130
  end
131
131
 
132
+ def self.enum_prefixed_translations_for(selector)
133
+ send(selector.to_s.pluralize).map do |key, _|
134
+ [I18n.t("#{selector}_#{key}", default: key.to_sym), key]
135
+ end
136
+ end
137
+
132
138
  private
133
139
 
134
140
  def raise_foreign_key_error!
@@ -0,0 +1,17 @@
1
+ module WithNotifications
2
+ extend ActiveSupport::Concern
3
+
4
+ def unread_messages
5
+ messages.where read: false
6
+ end
7
+
8
+ def unread_notifications
9
+ # TODO: message and discussion should trigger a notification instead of being one
10
+ all = notifications.where(read: false) + unread_messages + unread_discussions
11
+ all.sort_by(&:created_at).reverse
12
+ end
13
+
14
+ def read_notification!(target)
15
+ notifications.find_by(target: target)&.mark_as_read!
16
+ end
17
+ end
@@ -48,6 +48,10 @@ class Discussion < ApplicationRecord
48
48
  nil
49
49
  end
50
50
 
51
+ def target
52
+ self
53
+ end
54
+
51
55
  def used_in?(organization)
52
56
  organization == self.organization
53
57
  end
@@ -1,7 +1,10 @@
1
1
  class ExamAuthorizationRequest < ApplicationRecord
2
+ include TerminalNavigation
3
+
2
4
  belongs_to :exam
3
5
  belongs_to :user
4
6
  belongs_to :organization
7
+ belongs_to :exam_registration
5
8
 
6
9
  enum status: %i(pending approved rejected)
7
10
 
@@ -11,6 +14,10 @@ class ExamAuthorizationRequest < ApplicationRecord
11
14
  exam.authorize! user if approved?
12
15
  end
13
16
 
17
+ def name
18
+ exam_registration.description
19
+ end
20
+
14
21
  private
15
22
 
16
23
  def notify_user!
@@ -1,9 +1,10 @@
1
1
  class ExamRegistration < ApplicationRecord
2
2
  include WithTimedEnablement
3
+ include TerminalNavigation
3
4
 
4
5
  belongs_to :organization
5
6
  has_and_belongs_to_many :exams
6
- has_many :authorization_requests, class_name: 'ExamAuthorizationRequest', through: :exams
7
+ has_many :authorization_requests, class_name: 'ExamAuthorizationRequest'
7
8
 
8
9
  enum authorization_criterion_type: %i(none passed_exercises), _prefix: :authorization_criterion
9
10
 
@@ -11,6 +12,8 @@ class ExamRegistration < ApplicationRecord
11
12
 
12
13
  delegate :meets_authorization_criteria?, :process_request!, to: :authorization_criterion
13
14
 
15
+ alias_attribute :name, :description
16
+
14
17
  def authorization_criterion
15
18
  @authorization_criterion ||= ExamRegistration::AuthorizationCriterion.parse(authorization_criterion_type, authorization_criterion_value)
16
19
  end
@@ -30,6 +33,11 @@ class ExamRegistration < ApplicationRecord
30
33
  end
31
34
  end
32
35
 
36
+ def authorization_request_for(user)
37
+ authorization_requests.find_by(user: user) ||
38
+ ExamAuthorizationRequest.new(exam_registration: self, organization: organization)
39
+ end
40
+
33
41
  private
34
42
 
35
43
  def notify_user!(user)
@@ -70,6 +70,10 @@ class Message < ApplicationRecord
70
70
  from_initiator? && !not_actually_a_question?
71
71
  end
72
72
 
73
+ def target
74
+ self
75
+ end
76
+
73
77
  def self.parse_json(json)
74
78
  message = json.delete 'message'
75
79
  json
@@ -2,4 +2,8 @@ class Notification < ApplicationRecord
2
2
  belongs_to :user
3
3
  belongs_to :organization
4
4
  belongs_to :target, polymorphic: true
5
+
6
+ def mark_as_read!
7
+ update read: true
8
+ end
5
9
  end
data/app/models/user.rb CHANGED
@@ -3,6 +3,7 @@ class User < ApplicationRecord
3
3
  include WithProfile,
4
4
  WithUserNavigation,
5
5
  WithReminders,
6
+ WithNotifications,
6
7
  WithDiscussionCreation,
7
8
  Awardee,
8
9
  Disabling,
@@ -75,10 +76,6 @@ class User < ApplicationRecord
75
76
  assignments.where(status: Mumuki::Domain::Status::Submission::Passed.to_i)
76
77
  end
77
78
 
78
- def unread_messages
79
- messages.where read: false
80
- end
81
-
82
79
  def visit!(organization)
83
80
  update!(last_organization: organization) if organization != last_organization
84
81
  end
@@ -16,6 +16,7 @@ require_relative './factories/lesson_factory'
16
16
  require_relative './factories/login_settings_factory'
17
17
  require_relative './factories/medal_factory'
18
18
  require_relative './factories/message_factory'
19
+ require_relative './factories/notification_factory'
19
20
  require_relative './factories/organization_factory'
20
21
  require_relative './factories/term_factory'
21
22
  require_relative './factories/topic_factory'
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :notification do
3
+ organization { Organization.current }
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '8.5.0'
3
+ VERSION = '8.6.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: 8.5.0
4
+ version: 8.6.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-02-04 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -286,6 +286,7 @@ files:
286
286
  - app/models/concerns/with_medal.rb
287
287
  - app/models/concerns/with_messages.rb
288
288
  - app/models/concerns/with_name.rb
289
+ - app/models/concerns/with_notifications.rb
289
290
  - app/models/concerns/with_number.rb
290
291
  - app/models/concerns/with_preferences.rb
291
292
  - app/models/concerns/with_profile.rb
@@ -693,6 +694,7 @@ files:
693
694
  - lib/mumuki/domain/factories/login_settings_factory.rb
694
695
  - lib/mumuki/domain/factories/medal_factory.rb
695
696
  - lib/mumuki/domain/factories/message_factory.rb
697
+ - lib/mumuki/domain/factories/notification_factory.rb
696
698
  - lib/mumuki/domain/factories/organization_factory.rb
697
699
  - lib/mumuki/domain/factories/term_factory.rb
698
700
  - lib/mumuki/domain/factories/topic_factory.rb