-
Notifications
You must be signed in to change notification settings - Fork 37
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
WIP - initial gdpr erase command. #375
Open
lakinwecker
wants to merge
4
commits into
Lichess4545:master
Choose a base branch
from
lakinwecker:anonymize-command
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import sys | ||
|
||
from django.utils.crypto import get_random_string | ||
from django.core.management import BaseCommand | ||
from django.utils import timezone | ||
from django.contrib.auth.models import User | ||
from django.utils import timezone | ||
|
||
from heltour.tournament.models import ( | ||
LeagueModerator, | ||
LoginToken, | ||
ModRequest, | ||
Player, | ||
PrivateUrlAuth, | ||
Registration, | ||
) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Anonymizes a user within the 4545 league database." | ||
|
||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('username', nargs=1, type=str) | ||
|
||
def handle(self, *args, **options): | ||
# TODO: revisions probably need to be updated. | ||
# TODO: comments might have player names in it? | ||
username = options['username'][0] | ||
try: | ||
player = Player.objects.get(lichess_username__iexact=username.lower()) | ||
except Player.DoesNotExist: | ||
sys.exit(f"Unable to find player with username: {username}") | ||
|
||
if player.account_status not in ['normal', 'closed']: | ||
sys.exit(f"Unable to GDPR erase for legitimate interests") | ||
|
||
rando = get_random_string(8) | ||
anon_username = f"ghost_{rando}" | ||
anon_email = f"ghost_{rando}@example.com" | ||
anon_slack = f"ghost_{rando}" | ||
player.lichess_username = anon_username | ||
player.rating = 1500 | ||
player.games_played = 0 | ||
player.email = anon_email | ||
player.is_active = False | ||
player.slack_user_id = '' | ||
player.timezone_offset = None | ||
player.oauth_token = None | ||
player.profile = '' | ||
player.gdpr_erased = True | ||
player.save() | ||
|
||
LeagueModerator.objects \ | ||
.filter(player=player) \ | ||
.delete() | ||
|
||
PrivateUrlAuth.objects \ | ||
.filter(authenticated_user__iexact=username.lower()) \ | ||
.delete() | ||
|
||
ModRequest.objects \ | ||
.filter(requester=player) \ | ||
.delete() | ||
|
||
Registration.objects \ | ||
.filter(lichess_username__iexact=username.lower()) \ | ||
.update( | ||
lichess_username=anon_username, | ||
slack_username=anon_slack, | ||
email=anon_email, | ||
|
||
classical_rating=1500, | ||
peak_classical_rating=1500, | ||
|
||
has_played_20_games=True, | ||
already_in_slack_group=False, | ||
previous_season_alternate='new', | ||
|
||
can_commit=True, | ||
friends='', | ||
avoid='', | ||
agreed_to_rules=True, | ||
alternate_preference='full_time', | ||
weeks_unavailable='', | ||
section_preference=None, | ||
validation_ok=True, | ||
validation_warning=False, | ||
) | ||
|
||
LoginToken.objects \ | ||
.filter(lichess_username__iexact=username.lower()) \ | ||
.delete() | ||
|
||
|
||
now = timezone.now() | ||
User.objects \ | ||
.filter(username__iexact=username.lower()) \ | ||
.update( | ||
username=anon_username, | ||
email='', | ||
first_name='', | ||
last_name='', | ||
is_staff=False, | ||
is_active=False, | ||
is_superuser=False, | ||
last_login=now, | ||
date_joined=now, | ||
) | ||
|
||
print(f"{username} has been gdpr erased") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2.13 on 2021-04-11 13:51 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('tournament', '0189_auto_20210221_0424'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='player', | ||
name='gdpr_erased', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the players information will be scrubbed, do we need this filter? Why not get the player and have a hint that the information is gdpr scrubbed? (maybe it is a GDPR restriction that's why I'm asking :P)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this page will list out all of the games they played and teams they were part of. This allows someone who is interested to work out who they were. The scrubbing is intended to stop that. So we made the decision to remove this page to make it harder to work out who they are.