Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request account removal #447

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
100524d
Added user-level request-account-deletion support.
charles-cowart Jul 31, 2022
d4e53e5
Added unit-testing, cancel method.
charles-cowart Aug 1, 2022
b466adc
Added delete/ignore support, logging.
charles-cowart Aug 2, 2022
857754f
Added notification email for when an account is deleted
charles-cowart Aug 2, 2022
e61d607
Test removal of send_email()
charles-cowart Aug 2, 2022
a2ac112
Toggle disable_auth flag
charles-cowart Aug 2, 2022
6cadc8a
Reinstate send_mail()
charles-cowart Aug 2, 2022
c0f6b15
Remove disable_authentication from server_config.json
charles-cowart Aug 2, 2022
e1b35f9
Bugfix
charles-cowart Aug 2, 2022
cb31db9
Undo send_email()
charles-cowart Aug 2, 2022
2954b83
Revert "Bugfix"
charles-cowart Aug 2, 2022
8df7639
Reapplied fixes
charles-cowart Aug 2, 2022
252a10f
Formatting changes based on feedback.
charles-cowart Aug 3, 2022
5081cb1
Updated recent formatting changes
charles-cowart Aug 3, 2022
fffbe33
Updated based on feedback.
charles-cowart Aug 4, 2022
76f747b
Commented out send_mail() in allow_removal_request()
charles-cowart Aug 4, 2022
dedc72d
Uncommenting send_email() to obtain CI results
charles-cowart Aug 4, 2022
2fbabb3
Remove send notification email when deleting user
charles-cowart Aug 31, 2022
0709309
Removed vestigial email notification-related code
charles-cowart Aug 31, 2022
15b39a9
Rename 0101.sql to 0102.sql
charles-cowart Aug 31, 2022
825e42c
Merge branch 'master' into request_account_removal
charles-cowart Aug 31, 2022
93355ea
Update vioscreen_repo.py
charles-cowart Aug 31, 2022
288bc16
Resolve name conflict
charles-cowart Dec 13, 2022
9f1f00b
Merge branch 'master-overhaul' into request_account_removal
charles-cowart Dec 13, 2022
59612f0
Commits don't occur in repos
charles-cowart Dec 13, 2022
1a3b7f6
Account queue now records admin id instead of sub
charles-cowart Dec 13, 2022
4b8f945
Added unittests for removal_queue_repo.py
charles-cowart Dec 14, 2022
782423d
New cleanup code targets only ids created for testing
charles-cowart Dec 16, 2022
56f47b1
Endpoint added for cancel_request_remove_account()
charles-cowart Dec 16, 2022
885005d
Changed disposition to enum type
charles-cowart Jan 5, 2023
f3b9e45
Update server.py
cassidysymons Jan 6, 2023
9df1430
Update vioscreen_repo.py
cassidysymons Jan 6, 2023
490738e
Rename 0110.sql to 0111.sql
cassidysymons Jan 6, 2023
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
44 changes: 44 additions & 0 deletions microsetta_private_api/admin/admin_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from werkzeug.exceptions import Unauthorized
from microsetta_private_api.qiita import qclient
from microsetta_private_api.repo.interested_user_repo import InterestedUserRepo
from microsetta_private_api.repo.removal_queue_repo import RemovalQueueRepo


def search_barcode(token_info, sample_barcode):
Expand Down Expand Up @@ -614,6 +615,15 @@ def list_campaigns(token_info):
return jsonify(campaigns), 200


def list_removal_queue(token_info):
validate_admin_access(token_info)

with Transaction() as t:
repo = RemovalQueueRepo(t)
requests = repo.get_all_account_removal_requests()
return jsonify(requests), 200


def post_campaign_information(body, token_info):
validate_admin_access(token_info)

Expand Down Expand Up @@ -853,6 +863,40 @@ def delete_account(account_id, token_info):
return None, 204


def ignore_removal_request(account_id, token_info):
validate_admin_access(token_info)

with Transaction() as t:
rq_repo = RemovalQueueRepo(t)
try:
# remove the user from the queue, noting the admin who allowed it
# and the time the action was performed.
rq_repo.update_queue(account_id, token_info['email'], 'ignored')
t.commit()
except RepoException as e:
raise e

return None, 204


def allow_removal_request(account_id, token_info):
validate_admin_access(token_info)

with Transaction() as t:
rq_repo = RemovalQueueRepo(t)

try:
# remove the user from the queue, noting the admin who allowed it
# and the time the action was performed.
rq_repo.update_queue(account_id, token_info['email'], 'deleted')
t.commit()
except RepoException as e:
raise e

# delete the user
return delete_account(account_id, token_info)


def get_vioscreen_sample_to_user(token_info):
validate_admin_access(token_info)
with Transaction() as t:
Expand Down
9 changes: 9 additions & 0 deletions microsetta_private_api/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
read_account, update_account, check_email_match, _verify_jwt,
_verify_jwt_mock
)

from ._removal_queue import (
check_request_remove_account, request_remove_account,
cancel_request_remove_account
)

from ._consent import (
render_consent_doc,
check_consent_signature,
Expand Down Expand Up @@ -69,6 +75,9 @@
'read_account',
'update_account',
'check_email_match',
'request_remove_account',
'cancel_request_remove_account',
'check_request_remove_account',
'render_consent_doc',
'create_source',
'read_source',
Expand Down
3 changes: 0 additions & 3 deletions microsetta_private_api/api/_account.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import uuid

import jwt
from flask import jsonify
from jwt import InvalidTokenError

from werkzeug.exceptions import Unauthorized, Forbidden, NotFound

from microsetta_private_api.api.literals import AUTHROCKET_PUB_KEY, \
INVALID_TOKEN_MSG, JWT_ISS_CLAIM_KEY, JWT_SUB_CLAIM_KEY, \
JWT_EMAIL_CLAIM_KEY, ACCT_NOT_FOUND_MSG, CRONJOB_PUB_KEY
Expand Down
39 changes: 39 additions & 0 deletions microsetta_private_api/api/_removal_queue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from flask import jsonify
from microsetta_private_api.repo.transaction import Transaction
from microsetta_private_api.repo.removal_queue_repo import RemovalQueueRepo
from microsetta_private_api.api._account import _validate_account_access


def check_request_remove_account(account_id, token_info):
# raises 401 if method fails
_validate_account_access(token_info, account_id)

with Transaction() as t:
rq_repo = RemovalQueueRepo(t)
status = rq_repo.check_request_remove_account(account_id)
result = {'account_id': account_id, 'status': status}
return jsonify(result), 200


def request_remove_account(account_id, token_info):
# raises 401 if method fails
_validate_account_access(token_info, account_id)

with Transaction() as t:
rq_repo = RemovalQueueRepo(t)
rq_repo.request_remove_account(account_id)
t.commit()

return jsonify(code=200, message="Request Accepted"), 200


def cancel_request_remove_account(account_id, token_info):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify this has an endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Endpoint added. I apparently added cancel_request_remove_account () for completeness. The UI doesn't use this functionality because we didn't want the user to cancel a request once they made it, and do it again. The UI will instead show a 'Your account deletion request is being reviewed.' msg instead.

# raises 401 if method fails
_validate_account_access(token_info, account_id)

with Transaction() as t:
rq_repo = RemovalQueueRepo(t)
rq_repo.cancel_request_remove_account(account_id)
t.commit()

return jsonify(code=200, message="Request Accepted"), 200
90 changes: 90 additions & 0 deletions microsetta_private_api/api/microsetta_private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,51 @@ paths:
'422':
$ref: '#/components/responses/422UnprocessableEntity'

'/accounts/{account_id}/removal_queue':
get:
operationId: microsetta_private_api.api.check_request_remove_account
tags:
- Account
summary: Verify user requested account to be removed
description: Verify user requested account to be removed
parameters:
- $ref: '#/components/parameters/account_id'
responses:
'200':
description: Successfully requested for removal request status
'401':
$ref: '#/components/responses/401Unauthorized'
put:
operationId: microsetta_private_api.api.request_remove_account
tags:
- Account
summary: Request account to be removed
description: Request account to be removed
parameters:
- $ref: '#/components/parameters/account_id'
responses:
'200':
description: Successfully requested for account to be removed
'401':
$ref: '#/components/responses/401Unauthorized'
'422':
$ref: '#/components/responses/422UnprocessableEntity'
delete:
operationId: microsetta_private_api.api.cancel_request_remove_account
tags:
- Account
summary: Cancel request for account to be removed
description: Cancel request for account to be removed
parameters:
- $ref: '#/components/parameters/account_id'
responses:
'200':
description: Successfully canceled request
'401':
$ref: '#/components/responses/401Unauthorized'
'422':
$ref: '#/components/responses/422UnprocessableEntity'

'/accounts/{account_id}/check_duplicate_source':
post:
operationId: microsetta_private_api.api.check_duplicate_source_name
Expand Down Expand Up @@ -2128,6 +2173,51 @@ paths:
'401':
$ref: '#/components/responses/401Unauthorized'

'/admin/account_removal/{account_id}':
put:
operationId: microsetta_private_api.admin.admin_impl.ignore_removal_request
tags:
- Admin
parameters:
- $ref: '#/components/parameters/account_id'
responses:
'200':
description: Removes account from queue w/out deleting it.
content:
application/json:
schema:
type: array
delete:
operationId: microsetta_private_api.admin.admin_impl.allow_removal_request
tags:
- Admin
parameters:
- $ref: '#/components/parameters/account_id'
responses:
'200':
description: Updates queue, log before calling delete_account()
content:
application/json:
schema:
type: array

'/admin/account_removal/list':
get:
operationId: microsetta_private_api.admin.admin_impl.list_removal_queue
tags:
- Admin
summary: Return a list of all account removal requests
description: Return a list of all account removal requests
responses:
'200':
description: Array of account removal requests
content:
application/json:
schema:
type: array
'401':
$ref: '#/components/responses/401Unauthorized'

'/admin/scan/{sample_barcode}':
post:
# Note: We might want to be able to differentiate system administrator operations
Expand Down
Loading