Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

implement clearing identities #4002

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions gratipay/models/participant/mixins/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,30 @@ def set_identity_verification(self, country_id, is_verified):
add_event(cursor, 'participant', payload)


def clear_identity(self, country_id):
"""Clear the participant's national identity record for a given country.

:param int country_id: an ``id`` from the ``countries`` table

"""
with self.db.get_cursor() as cursor:
identity_id = cursor.one("""

DELETE
FROM participant_identities
WHERE participant_id=%(participant_id)s
AND country_id=%(country_id)s
RETURNING id

""", dict(locals(), participant_id=self.id))
payload = dict( id=self.id
, identity_id=identity_id
, country_id=country_id
, action='clear identity'
)
add_event(cursor, 'participant', payload)


# Rekeying
# ========

Expand Down
1 change: 0 additions & 1 deletion sql/branch.sql

This file was deleted.

5 changes: 5 additions & 0 deletions sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,8 @@ CREATE TRIGGER enforce_email_for_participant_identity
BEFORE INSERT ON participant_identities
FOR EACH ROW
EXECUTE PROCEDURE fail_if_no_email();


-- https://github.com/gratipay/gratipay.com/pull/4031

ALTER TABLE participant_identities ADD COLUMN is_verified boolean NOT NULL DEFAULT false;
25 changes: 25 additions & 0 deletions tests/py/test_participant_identities.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,31 @@ def test_siv_still_logs_an_event_when_noop(self):
)


# ci - clear_identity

def test_ci_clears_identity(self):
self.crusher.store_identity_info(self.TT, 'nothing-enforced', {'name': 'Crusher'})
assert self.crusher.clear_identity(self.TT) is None
assert self.crusher.list_identity_metadata() == []

def test_ci_is_a_noop_when_there_is_no_identity(self):
assert self.crusher.clear_identity(self.TT) is None
assert self.crusher.list_identity_metadata() == []

def test_ci_logs_an_event(self):
iid = self.crusher.store_identity_info(self.TT, 'nothing-enforced', {'name': 'Crusher'})
self.crusher.clear_identity(self.TT)
self.assert_events( self.crusher.id
, [iid, iid]
, [self.TT, self.TT]
, ['insert identity', 'clear identity']
)

def test_ci_still_logs_an_event_when_noop(self):
self.crusher.clear_identity(self.TT)
self.assert_events(self.crusher.id, [None], [self.TT], ['clear identity'])


# fine - fail_if_no_email

def test_fine_fails_if_no_email(self):
Expand Down
2 changes: 1 addition & 1 deletion www/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1958
1959