-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add roles for advertisers and publishers
- Add 3 permission levels for advertisers and publishers - The migration will default everybody to the highest permission - Role permissions are checked in the UI and in the backend - Admin users can change publisher settings, and invite users. - Managers can edit things - Reporters can't change anything.
- Loading branch information
1 parent
795a0bf
commit 90a4a76
Showing
18 changed files
with
574 additions
and
63 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
70 changes: 70 additions & 0 deletions
70
adserver/auth/migrations/0009_user_advertiser_publisher_roles.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,70 @@ | ||
""" | ||
This migration was autocreated but has been customized. | ||
See: https://docs.djangoproject.com/en/5.0/howto/writing-migrations/#changing-a-manytomanyfield-to-use-a-through-model | ||
""" | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('adserver', '0098_rotation_aggregation'), | ||
('adserver_auth', '0008_data_flight_notifications'), | ||
] | ||
|
||
operations = [ | ||
migrations.SeparateDatabaseAndState( | ||
state_operations=[ | ||
migrations.CreateModel( | ||
name='UserAdvertiserMember', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
# We add this in a separate operation below | ||
# ('role', models.CharField(choices=[('Admin', 'Admin'), ('Manager', 'Manager'), ('Reporter', 'Reporter')], default='Admin', max_length=100)), | ||
('advertiser', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='adserver.advertiser')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'db_table': 'adserver_auth_user_advertisers', | ||
}, | ||
), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='advertisers', | ||
field=models.ManyToManyField(blank=True, through='adserver_auth.UserAdvertiserMember', to='adserver.advertiser'), | ||
), | ||
migrations.CreateModel( | ||
name='UserPublisherMember', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
# We add this in a separate operation below | ||
# ('role', models.CharField(choices=[('Admin', 'Admin'), ('Manager', 'Manager'), ('Reporter', 'Reporter')], default='Admin', max_length=100)), | ||
('publisher', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='adserver.publisher')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'db_table': 'adserver_auth_user_publishers', | ||
}, | ||
), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='publishers', | ||
field=models.ManyToManyField(blank=True, through='adserver_auth.UserPublisherMember', to='adserver.publisher'), | ||
), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name="useradvertisermember", | ||
name="role", | ||
field=models.CharField(choices=[('Admin', 'Admin'), ('Manager', 'Manager'), ('Reporter', 'Reporter')], default='Admin', max_length=100), | ||
), | ||
migrations.AddField( | ||
model_name="userpublishermember", | ||
name="role", | ||
field=models.CharField(choices=[('Admin', 'Admin'), ('Manager', 'Manager'), ('Reporter', 'Reporter')], default='Admin', max_length=100), | ||
), | ||
] |
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
from django.utils.translation import gettext | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from .auth.models import UserAdvertiserMember | ||
from .models import Advertisement | ||
from .models import Campaign | ||
from .models import Flight | ||
|
@@ -1322,6 +1323,14 @@ class InviteUserForm(forms.ModelForm): | |
without a duplicate being created. | ||
""" | ||
|
||
role = forms.ChoiceField( | ||
required=True, | ||
# This form works for both publishers and advertisers | ||
# Currently, the roles are the same for both | ||
# If that ever changes, this will need an update | ||
choices=((r, r) for r in UserAdvertiserMember.ROLES), | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
"""Add the form helper and customize the look of the form.""" | ||
super().__init__(*args, **kwargs) | ||
|
@@ -1331,6 +1340,7 @@ def __init__(self, *args, **kwargs): | |
"", | ||
Field("name"), | ||
Field("email", placeholder="[email protected]"), | ||
Field("role"), | ||
css_class="my-3", | ||
), | ||
Submit("submit", "Send invite"), | ||
|
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.