-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into move-account-deletion-email
- Loading branch information
Showing
21 changed files
with
520 additions
and
189 deletions.
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 |
---|---|---|
|
@@ -6,6 +6,9 @@ coverage: | |
patch: | ||
default: | ||
target: 90% | ||
project: | ||
default: | ||
target: 90% | ||
|
||
ignore: | ||
- "portal/tests/*.py" | ||
|
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
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
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
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
29 changes: 29 additions & 0 deletions
29
cfl_common/common/migrations/0049_anonymise_orphan_users.py
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,29 @@ | ||
from django.apps.registry import Apps | ||
from django.db import migrations | ||
|
||
from portal.views.api import __anonymise_user | ||
|
||
|
||
def anonymise_orphan_users(apps: Apps, *args): | ||
""" | ||
Users should never exist without a user-type linked to them. Anonymise all | ||
instances of User objects without a Teacher or Student instance. | ||
""" | ||
User = apps.get_model("auth", "User") | ||
|
||
active_orphan_users = User.objects.filter( | ||
new_teacher__isnull=True, new_student__isnull=True, is_active=True | ||
) | ||
|
||
for active_orphan_user in active_orphan_users: | ||
__anonymise_user(active_orphan_user) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [("common", "0048_unique_school_names")] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=anonymise_orphan_users, reverse_code=migrations.RunPython.noop | ||
), | ||
] |
30 changes: 30 additions & 0 deletions
30
cfl_common/common/migrations/0050_anonymise_orphan_schools.py
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,30 @@ | ||
from uuid import uuid4 | ||
|
||
from django.apps.registry import Apps | ||
from django.db import migrations | ||
|
||
|
||
def anonymise_orphan_schools(apps: Apps, *args): | ||
""" | ||
Schools without any teachers or students should be anonymised (inactive). | ||
Mark all active orphan schools as inactive. | ||
""" | ||
School = apps.get_model("common", "School") | ||
|
||
active_orphan_schools = School.objects.filter(teacher_school__isnull=True) | ||
|
||
for active_orphan_school in active_orphan_schools: | ||
active_orphan_school.name = uuid4().hex | ||
active_orphan_school.is_active = False | ||
active_orphan_school.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [("common", "0049_anonymise_orphan_users")] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=anonymise_orphan_schools, | ||
reverse_code=migrations.RunPython.noop, | ||
), | ||
] |
Oops, something went wrong.