-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: non school teachers cannot be admins
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
cfl_common/common/migrations/0056_set_non_school_teachers_as_non_admins.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,26 @@ | ||
from django.apps.registry import Apps | ||
from django.db import migrations | ||
|
||
|
||
def set_non_school_teachers_as_non_admins(apps: Apps, *args): | ||
Teacher = apps.get_model("common", "Teacher") | ||
|
||
Teacher.objects.filter( | ||
new_user__is_active=True, | ||
is_admin=True, | ||
school__isnull=True, | ||
).update(is_admin=False) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("common", "0055_alter_schoolteacherinvitation_token"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=set_non_school_teachers_as_non_admins, | ||
reverse_code=migrations.RunPython.noop, | ||
), | ||
] |
19 changes: 19 additions & 0 deletions
19
cfl_common/common/migrations/0057_teacher_teacher__is_admin.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,19 @@ | ||
# Generated by Django 4.2.17 on 2025-01-13 17:34 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("common", "0056_set_non_school_teachers_as_non_admins"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddConstraint( | ||
model_name="teacher", | ||
constraint=models.CheckConstraint( | ||
check=models.Q(("is_admin", True), ("school__isnull", True), _negated=True), name="teacher__is_admin" | ||
), | ||
), | ||
] |
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