-
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.
Merge pull request #941 from readthedocs/davidfischer/roles-advertise…
…rs-publishers Add roles for advertisers and publishers
- Loading branch information
Showing
18 changed files
with
677 additions
and
70 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 |
---|---|---|
|
@@ -36,6 +36,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 | ||
|
@@ -1467,6 +1468,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) | ||
|
@@ -1476,6 +1485,7 @@ def __init__(self, *args, **kwargs): | |
"", | ||
Field("name"), | ||
Field("email", placeholder="[email protected]"), | ||
Field("role"), | ||
css_class="my-3", | ||
), | ||
Submit("submit", "Send invite"), | ||
|
Oops, something went wrong.