-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple allowed users for PermitArea (HPH-36) (#276)
Add support for allowing sharing of the PermitAreas between operators and the enforcer. Previously it was possible to use each PermitArea for just a single enforcer or operator. This was especially problematic, because the PermitArea codes were unique within enforcement domains so it was not even possible to create duplicate areas with the same identifiers.
- Loading branch information
Showing
18 changed files
with
172 additions
and
52 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 2.2.15 on 2023-11-23 18:03 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("parkings", "0045_parkingarea_name"), | ||
] | ||
|
||
operations = [ | ||
# Allow null values temporarily to make the migrations | ||
# reversible (the field will be removed in the following | ||
# migrations so it doesn't matter for the forward direction) | ||
migrations.AlterField( | ||
model_name="permitarea", | ||
name="permitted_user", | ||
field=models.ForeignKey( | ||
on_delete=models.SET_NULL, | ||
null=True, | ||
to=settings.AUTH_USER_MODEL, | ||
verbose_name="permitted_user", | ||
), | ||
), | ||
|
||
# Add the new field | ||
migrations.AddField( | ||
model_name="permitarea", | ||
name="allowed_users", | ||
field=models.ManyToManyField( | ||
help_text="Users who are allowed to create permits to this area.", | ||
related_name="allowed_permit_areas", | ||
to=settings.AUTH_USER_MODEL, | ||
verbose_name="allowed users", | ||
), | ||
), | ||
] |
29 changes: 29 additions & 0 deletions
29
parkings/migrations/0047_populate_permitarea_allowed_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 @@ | ||
# Migration to populate the PermitArea.allowed_users field | ||
|
||
from django.db import migrations | ||
|
||
|
||
def populate_allowed_users_from_permitted_user(apps, schema_editor): | ||
permit_area_model = apps.get_model("parkings", "PermitArea") | ||
for permit_area in permit_area_model.objects.all(): | ||
permit_area.allowed_users.add(permit_area.permitted_user) | ||
|
||
|
||
def populate_permitted_user_from_allowed_users(apps, schema_editor): | ||
permit_area_model = apps.get_model("parkings", "PermitArea") | ||
for permit_area in permit_area_model.objects.all(): | ||
permit_area.permitted_user = permit_area.allowed_users.first() | ||
permit_area.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("parkings", "0046_permitarea_allowed_users"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
populate_permitted_user_from_allowed_users, | ||
populate_permitted_user_from_allowed_users, | ||
), | ||
] |
16 changes: 16 additions & 0 deletions
16
parkings/migrations/0048_remove_permitarea_permitted_user.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,16 @@ | ||
# Generated by Django 2.2.15 on 2023-11-23 18:14 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("parkings", "0047_populate_permitarea_allowed_users"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="permitarea", | ||
name="permitted_user", | ||
), | ||
] |
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
Oops, something went wrong.