Remove roles when block or delete users
After a user assigned as a budget admin deletes their account or gets blocked by a moderator, the application throws an exception while loading the admin investment index page. As an erased user is not really deleted and neither its associated roles, the application was failing when trying to sort and administration without a username. In this case, the application was throwing an `ArgumentError: comparison of NilClass with String failed` exception. As a blocked user is not deleted or its roles, the application failed when trying to access the user name through the delegation in the Administrator. In this case, the application was throwing a `NoMethodError: undefined method `name' for nil:NilClass` exception.
This commit is contained in:
@@ -230,6 +230,7 @@ class User < ApplicationRecord
|
||||
Proposal.hide_all proposal_ids
|
||||
Budget::Investment.hide_all budget_investment_ids
|
||||
ProposalNotification.hide_all ProposalNotification.where(author_id: id).ids
|
||||
remove_roles
|
||||
end
|
||||
|
||||
def full_restore
|
||||
@@ -263,12 +264,21 @@ class User < ApplicationRecord
|
||||
unconfirmed_phone: nil
|
||||
)
|
||||
identities.destroy_all
|
||||
remove_roles
|
||||
end
|
||||
|
||||
def erased?
|
||||
erased_at.present?
|
||||
end
|
||||
|
||||
def remove_roles
|
||||
administrator&.destroy!
|
||||
valuator&.destroy!
|
||||
moderator&.destroy!
|
||||
manager&.destroy!
|
||||
sdg_manager&.destroy!
|
||||
end
|
||||
|
||||
def take_votes_if_erased_document(document_number, document_type)
|
||||
erased_user = User.erased.find_by(document_number: document_number,
|
||||
document_type: document_type)
|
||||
|
||||
Reference in New Issue
Block a user