implements first version of user.erase
This commit is contained in:
@@ -26,6 +26,7 @@ class User < ActiveRecord::Base
|
||||
validates :username, presence: true, unless: :organization?
|
||||
validates :username, uniqueness: true, unless: :organization?
|
||||
validates :document_number, uniqueness: { scope: :document_type }, allow_nil: true
|
||||
|
||||
validate :validate_username_length
|
||||
|
||||
validates :official_level, inclusion: {in: 0..5}
|
||||
@@ -145,6 +146,22 @@ class User < ActiveRecord::Base
|
||||
Proposal.hide_all proposal_ids
|
||||
end
|
||||
|
||||
def erase(erase_reason = nil)
|
||||
self.update(
|
||||
erase_reason: erase_reason,
|
||||
username: nil,
|
||||
email: "",
|
||||
unconfirmed_email: nil,
|
||||
document_number: nil,
|
||||
phone_number: nil,
|
||||
encrypted_password: "",
|
||||
confirmation_token: nil,
|
||||
reset_password_token: nil,
|
||||
email_verification_token: nil
|
||||
)
|
||||
|
||||
self.hide
|
||||
end
|
||||
|
||||
def email_provided?
|
||||
!!(email && email !~ OMNIAUTH_EMAIL_REGEX) ||
|
||||
|
||||
@@ -302,4 +302,35 @@ describe User do
|
||||
|
||||
end
|
||||
|
||||
describe "#erase" do
|
||||
it "anonymizes a user and marks him as hidden" do
|
||||
user = create(:user,
|
||||
username: "manolo",
|
||||
unconfirmed_email: "a@a.com",
|
||||
document_number: "1234",
|
||||
phone_number: "5678",
|
||||
encrypted_password: "foobar",
|
||||
confirmation_token: "token1",
|
||||
reset_password_token: "token2",
|
||||
email_verification_token: "token3")
|
||||
user.erase('a test')
|
||||
user.reload
|
||||
|
||||
expect(user.erase_reason).to eq('a test')
|
||||
|
||||
expect(user.username).to be_nil
|
||||
|
||||
expect(user.email).to be_empty
|
||||
expect(user.unconfirmed_email).to be_nil
|
||||
expect(user.document_number).to be_nil
|
||||
expect(user.phone_number).to be_nil
|
||||
|
||||
expect(user.encrypted_password).to be_empty
|
||||
|
||||
expect(user.confirmation_token).to be_nil
|
||||
expect(user.reset_password_token).to be_nil
|
||||
expect(user.email_verification_token).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user