mumuki-domain 9.22.1 → 9.23.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: 138e6386f4e43861b313756d9ee01943ab84d4beef60faf7936f587ac4e40f82
4
- data.tar.gz: 54afa2c2e250eec1de884cdf64568ec6d6c113508119884a6e96bfb7d91376f0
3
+ metadata.gz: 91e7710d2d997039351f464c293d25fea0b8de59208431647e209dfaa67dad9c
4
+ data.tar.gz: eb4e1571ef6795874fda3a4871692af496fd322ad00009190cce5d3ee92c4fd2
5
5
  SHA512:
6
- metadata.gz: f52a72a3f090f95962572aa1cc17697ce4c1cec4608cb25dfbebf74db8f394349750868027865ef9f3cba9fd9564a8598875e4e17231e41b38bae06ed0abbec3
7
- data.tar.gz: 2b4e6faed9348156829d672cc4ab98a093348f33831a14aec6ed5b197ba44277ad1a8bdbf4bd2667a6b95e6b1c274fd798eadf92979cb7876a0092108a28e6b2
6
+ metadata.gz: 037fbb869e63fa550782f8fbb5c46993b3b901ca1c529d235f98982d86a450afcb7dcc47b1fd5cf39b2a3349c9993be9adc6c52d0a45cd95729a9b45a5d315ce
7
+ data.tar.gz: e2f2997b8479047321fcad632dabb65d0a4f2e24dabbe820da1150dcf38fc922add4a68666faed106930fb7e2dfe4a4c2cec26d3653cfe7c19bd3fda9ef7e16b
@@ -0,0 +1,29 @@
1
+ module WithDeletedUser
2
+ def self.prepended(base)
3
+ super
4
+ base.before_destroy :forbid_destroy!, if: :deleted_user?
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ def deleted_user?
9
+ self == User.deleted_user
10
+ end
11
+
12
+ def abbreviated_name
13
+ return super unless deleted_user?
14
+
15
+ I18n.t(:deleted_user, locale: (Organization.current.locale rescue 'en'))
16
+ end
17
+
18
+ module ClassMethods
19
+ def deleted_user
20
+ @deleted_user ||= User.create_with(@buried_profile).find_or_create_by(uid: 'deleted:shibi')
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def forbid_destroy!
27
+ raise '"Deleted User" shibi cannot be destroyed'
28
+ end
29
+ end
@@ -142,7 +142,7 @@ class Discussion < ApplicationRecord
142
142
  end
143
143
 
144
144
  def responses_count
145
- visible_messages.where('sender <> ? OR sender_id <> ?', initiator.uid, initiator.id).count
145
+ visible_messages.where.not(sender: initiator).count
146
146
  end
147
147
 
148
148
  def has_responses?
@@ -135,10 +135,6 @@ class Message < ApplicationRecord
135
135
  'message'
136
136
  end
137
137
 
138
- def sender
139
- super || User.locate!(self[:sender])
140
- end
141
-
142
138
  private
143
139
 
144
140
  def approve!(user)
data/app/models/user.rb CHANGED
@@ -6,20 +6,30 @@ class User < ApplicationRecord
6
6
  WithNotifications,
7
7
  WithDiscussionCreation,
8
8
  Awardee,
9
- Disabling,
10
9
  WithTermsAcceptance,
11
10
  WithPreferences,
12
11
  Onomastic,
13
12
  Mumuki::Domain::Helpers::User
14
13
 
14
+ prepend WithDeletedUser
15
+
15
16
  serialize :permissions, Mumukit::Auth::Permissions
16
17
  serialize :ignored_notifications, Array
17
18
 
18
- has_many :notifications
19
- has_many :assignments, foreign_key: :submitter_id
20
- has_many :indicators
21
- has_many :user_stats, class_name: 'UserStats'
22
- has_many :direct_messages, -> { order(created_at: :desc) }, class_name: 'Message', source: :messages, through: :assignments
19
+ before_destroy :clean_belongings!
20
+
21
+ has_many :api_clients, dependent: :delete_all
22
+ has_many :assignments, foreign_key: :submitter_id, dependent: :delete_all
23
+ has_many :certificates, dependent: :delete_all
24
+ has_many :exam_authorizations, dependent: :delete_all
25
+ has_many :exam_authorization_requests, dependent: :delete_all
26
+ has_many :notifications, dependent: :delete_all
27
+ has_many :indicators, dependent: :delete_all
28
+ has_many :user_stats, class_name: 'UserStats', dependent: :delete_all
29
+
30
+ has_many :discussions, foreign_key: :initiator_id
31
+ has_many :forum_messages, -> { where.not(discussion_id: nil) }, class_name: 'Message', foreign_key: :sender_id
32
+ has_many :direct_messages, -> { order(created_at: :desc) }, through: :assignments, source: :messages
23
33
 
24
34
  has_many :submitted_exercises, through: :assignments, class_name: 'Exercise', source: :exercise
25
35
 
@@ -34,12 +44,8 @@ class User < ApplicationRecord
34
44
 
35
45
  has_one :last_guide, through: :last_exercise, source: :guide
36
46
 
37
- has_many :exam_authorizations
38
-
39
47
  has_many :exams, through: :exam_authorizations
40
48
 
41
- has_many :certificates
42
-
43
49
  enum gender: %i(female male other unspecified)
44
50
  belongs_to :avatar, polymorphic: true, optional: true
45
51
 
@@ -156,7 +162,6 @@ class User < ApplicationRecord
156
162
  update! accepts_reminders: false
157
163
  end
158
164
 
159
-
160
165
  def attach!(role, course)
161
166
  add_permission! role, course.slug
162
167
  save_and_notify!
@@ -341,8 +346,10 @@ class User < ApplicationRecord
341
346
  ignored_notifications.include? notification.subject
342
347
  end
343
348
 
344
- def forum_messages
345
- Message.where(sender: self).or(Message.where('sender = ?', uid)).where.not(discussion_id: nil)
349
+ def clean_belongings!
350
+ discussions.update_all initiator_id: User.deleted_user.id
351
+ forum_messages.update_all sender_id: User.deleted_user.id
352
+ direct_messages.where(sender: self).delete_all
346
353
  end
347
354
 
348
355
  private
@@ -380,10 +387,6 @@ class User < ApplicationRecord
380
387
  :uid
381
388
  end
382
389
 
383
- def self.unsubscription_verifier
384
- Rails.application.message_verifier(:unsubscribe)
385
- end
386
-
387
390
  def self.create_if_necessary(user)
388
391
  user[:uid] ||= user[:email]
389
392
  where(uid: user[:uid]).first_or_create(user)
@@ -0,0 +1,5 @@
1
+ class RemoveSenderUidFromMessages < ActiveRecord::Migration[5.1]
2
+ def change
3
+ remove_column :messages, :sender, :string
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '9.22.1'
3
+ VERSION = '9.23.0'
4
4
  end
5
5
  end
data/lib/mumuki/domain.rb CHANGED
@@ -1,4 +1,5 @@
1
- require "mumuki/domain/engine"
1
+ require 'email_validator/strict'
2
+ require 'mumuki/domain/engine'
2
3
 
3
4
  require 'mumukit/core'
4
5
  require 'mumukit/core/activemodel'
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.22.1
4
+ version: 9.23.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-04 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.1.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: email_validator
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: mumukit-auth
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -279,6 +293,7 @@ files:
279
293
  - app/models/concerns/with_assignments.rb
280
294
  - app/models/concerns/with_assignments_batch.rb
281
295
  - app/models/concerns/with_case_insensitive_search.rb
296
+ - app/models/concerns/with_deleted_user.rb
282
297
  - app/models/concerns/with_description.rb
283
298
  - app/models/concerns/with_discussion_creation.rb
284
299
  - app/models/concerns/with_discussion_creation/subscription.rb
@@ -690,6 +705,7 @@ files:
690
705
  - db/migrate/20210929223144_add_authorization_requests_limit_to_exam_registration.rb
691
706
  - db/migrate/20211004062332_reference_sender_via_id_in_messages.rb
692
707
  - db/migrate/20211020224011_add_from_moderator_to_messages.rb
708
+ - db/migrate/20211104182009_remove_sender_uid_from_messages.rb
693
709
  - lib/mumuki/domain.rb
694
710
  - lib/mumuki/domain/area.rb
695
711
  - lib/mumuki/domain/engine.rb