mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-23 15:24:57 +08:00
Merge pull request #6802 from aignatov-bio/ai-sci-9868-fix-user-deletion
Fix user deletion [SCI-9868]
This commit is contained in:
commit
ea4eb6f785
1 changed files with 0 additions and 20 deletions
|
@ -321,7 +321,6 @@ class User < ApplicationRecord
|
||||||
has_many :hidden_repository_cell_reminders, dependent: :destroy
|
has_many :hidden_repository_cell_reminders, dependent: :destroy
|
||||||
|
|
||||||
before_validation :downcase_email!
|
before_validation :downcase_email!
|
||||||
before_destroy :destroy_notifications
|
|
||||||
|
|
||||||
def name
|
def name
|
||||||
full_name
|
full_name
|
||||||
|
@ -635,25 +634,6 @@ class User < ApplicationRecord
|
||||||
self.email = email.downcase
|
self.email = email.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_notifications
|
|
||||||
# Find all notifications where user is the only reference
|
|
||||||
# on the notification, and destroy all such notifications
|
|
||||||
# (user_notifications are destroyed when notification is
|
|
||||||
# destroyed). We try to do this efficiently (hence in_groups_of).
|
|
||||||
nids_all = notifications.pluck(:id)
|
|
||||||
nids_all.in_groups_of(1000, false) do |nids|
|
|
||||||
Notification
|
|
||||||
.where(id: nids)
|
|
||||||
.joins(:user_notifications)
|
|
||||||
.group('notifications.id')
|
|
||||||
.having('count(notification_id) <= 1')
|
|
||||||
.destroy_all
|
|
||||||
end
|
|
||||||
|
|
||||||
# Now, simply destroy all user notification relations left
|
|
||||||
user_notifications.destroy_all
|
|
||||||
end
|
|
||||||
|
|
||||||
def clear_view_cache
|
def clear_view_cache
|
||||||
Rails.cache.delete_matched(%r{^views\/users\/#{id}-})
|
Rails.cache.delete_matched(%r{^views\/users\/#{id}-})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue