Class: UserService::Delete
- Inherits:
-
Object
- Object
- UserService::Delete
- Includes:
- DefaultErrorContainer
- 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.
10 11 12 |
# File 'app/services/user_service/delete.rb', line 10 def reason @reason end |
#user ⇒ Object
Returns the value of attribute user.
10 11 12 |
# File 'app/services/user_service/delete.rb', line 10 def user @user end |
Instance Method Details
#delete_account ⇒ Object
32 33 34 35 36 37 |
# File 'app/services/user_service/delete.rb', line 32 def delete_account delete_account! rescue StandardError => e APMErrorHandler.report(e) false end |
#delete_account! ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/services/user_service/delete.rb', line 48 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
24 25 26 27 28 29 30 |
# File 'app/services/user_service/delete.rb', line 24 def suspend suspend! rescue StandardError => e errors.add(:base, e) APMErrorHandler.report(e) false end |
#suspend! ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/services/user_service/delete.rb', line 39 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
17 18 19 20 21 22 |
# File 'app/services/user_service/delete.rb', line 17 def valid? return false if user.blank? return false if errors.present? true end |