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

WIP - initial gdpr erase command. #375

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
111 changes: 111 additions & 0 deletions heltour/tournament/management/commands/gdpr_erase.py
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")
18 changes: 18 additions & 0 deletions heltour/tournament/migrations/0190_player_gdpr_erased.py
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),
),
]
1 change: 1 addition & 0 deletions heltour/tournament/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ class Player(_BaseModel):
# duplicate them here.
# Note: a case-insensitive unique index for lichess_username is added via migration to the DB
lichess_username = models.CharField(max_length=255, validators=[username_validator])
gdpr_erased = models.BooleanField(default=False)
rating = models.PositiveIntegerField(blank=True, null=True)
games_played = models.PositiveIntegerField(blank=True, null=True)
email = models.CharField(max_length=255, blank=True)
Expand Down
6 changes: 4 additions & 2 deletions heltour/tournament/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ def lone_view(self, round_number=None, team_number=None):

class ICalPlayerView(BaseView, ICalMixin):
def view(self, username):
player = get_object_or_404(Player, lichess_username__iexact=username)
player = get_object_or_404(
Player, lichess_username__iexact=username, gdpr_erased=False)

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)

Copy link
Collaborator Author

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.

calendar_title = "{} Chess Games".format(player.lichess_username)
uid_component = 'all'
pairings = player.pairings.exclude(scheduled_time=None)
Expand Down Expand Up @@ -1483,7 +1484,8 @@ def view(self):

class PlayerProfileView(LeagueView):
def view(self, username):
player = get_object_or_404(Player, lichess_username__iexact=username)
player = get_object_or_404(
Player, lichess_username__iexact=username, gdpr_erased=False)

def game_count(season):
if season.league.competitor_type == 'team':
Expand Down