Class: UserService::Delete
- Inherits:
-
Object
- Object
- UserService::Delete
- Includes:
- DefaultErrorContainer, ElasticAPM::SpanHelpers
- Defined in:
- app/services/user_service/delete.rb
Overview
This class is used to delete user account when user delete their account, we will not remove their account but we will mark them as deleted, and anonymize their data we will remove their data from user table, and move it to archive DB we will also remove their reviews, and change their name, email, and phone
Instance Attribute Summary collapse
-
#reason ⇒ Object
Returns the value of attribute reason.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #delete_account ⇒ Object
- #delete_account! ⇒ Object
-
#initialize(user_id, reason) ⇒ Delete
constructor
A new instance of Delete.
- #suspend ⇒ Object
- #suspend! ⇒ Object
- #valid? ⇒ Boolean
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Constructor Details
Instance Attribute Details
#reason ⇒ Object
Returns the value of attribute reason.
12 13 14 |
# File 'app/services/user_service/delete.rb', line 12 def reason @reason end |
#user ⇒ Object
Returns the value of attribute user.
12 13 14 |
# File 'app/services/user_service/delete.rb', line 12 def user @user end |
Instance Method Details
#delete_account ⇒ Object
36 37 38 39 40 41 |
# File 'app/services/user_service/delete.rb', line 36 def delete_account delete_account! rescue StandardError => e APMErrorHandler.report(e) false end |
#delete_account! ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/services/user_service/delete.rb', line 55 def delete_account! status = false ActiveRecord::Base.transaction do begin archive_user change_password remove_reviews invalidate_account rescue StandardError => e APMErrorHandler.report e raise ActiveRecord::Rollback end status = true end status end |
#suspend ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/services/user_service/delete.rb', line 27 def suspend suspend! rescue StandardError => e errors.add(:base, e) APMErrorHandler.report(e) false end |
#suspend! ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'app/services/user_service/delete.rb', line 44 def suspend! raise StandardError, I18n.t('views.user.invalid_deletion_reason') if reason.blank? change_password remove_all_token delete_account_worker notify_support end |
#valid? ⇒ Boolean
19 20 21 22 23 24 |
# File 'app/services/user_service/delete.rb', line 19 def valid? return false if user.blank? return false if errors.present? true end |