Skip to content

Commit

Permalink
Make more fields blank for the admin pages
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding authored and john-westcott-iv committed Jan 18, 2024
1 parent 7c821fc commit 906b2e2
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
12 changes: 6 additions & 6 deletions ansible_base/authentication/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Migration(migrations.Migration):
('create_objects', models.BooleanField(default=True, help_text='Allow authenticator to create objects (users, teams, organizations)')),
('users_unique', models.BooleanField(default=False, help_text='Are users from this source the same as users from another source with the same id')),
('remove_users', models.BooleanField(default=True, help_text='When a user authenticates from this source should they be removed from any other groups they were previously added to')),
('configuration', models.JSONField(default=dict, help_text='The required configuration for this source')),
('configuration', models.JSONField(default=dict, blank=True, help_text='The required configuration for this source')),
('type', models.CharField(editable=False, help_text='The type of authentication service this is', max_length=256)),
('order', models.IntegerField(default=1, help_text='The order in which an authenticator will be tried. This only pertains to username/password authenticators')),
('slug', models.SlugField(default=None, editable=False, help_text='An immutable identifier for the authenticator', max_length=1024, unique=True)),
Expand All @@ -48,9 +48,9 @@ class Migration(migrations.Migration):
('name', models.CharField(help_text='The name of this resource', max_length=512)),
('revoke', models.BooleanField(default=False, help_text='If a user does not meet this rule should we revoke the permission')),
('map_type', models.CharField(choices=[('team', 'team'), ('is_superuser', 'is_superuser'), ('is_system_auditor', 'is_system_auditor'), ('allow', 'allow'), ('organization', 'organization')], default='team', help_text='What does the map work on, a team, a user flag or is this an allow rule', max_length=17)),
('team', models.CharField(default=None, help_text='A team name this rule works on', max_length=512, null=True)),
('organization', models.CharField(default=None, help_text='An organization name this rule works on', max_length=512, null=True)),
('triggers', models.JSONField(default=dict, help_text='Trigger information for this rule')),
('team', models.CharField(default=None, blank=True, help_text='A team name this rule works on', max_length=512, null=True)),
('organization', models.CharField(default=None, blank=True, help_text='An organization name this rule works on', max_length=512, null=True)),
('triggers', models.JSONField(default=dict, blank=True, help_text='Trigger information for this rule')),
('order', models.PositiveIntegerField(default=0, help_text='The order in which this rule should be processed, smaller numbers are of higher precedence. Items with the same order will be executed in random order')),
('authenticator', models.ForeignKey(help_text='The authenticator this mapping belongs to', on_delete=django.db.models.deletion.CASCADE, to='authentication.authenticator')),
('created_by', models.ForeignKey(default=None, editable=False, help_text='The user who created this resource', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='%(app_label)s_%(class)s_created+', to=settings.AUTH_USER_MODEL)),
Expand All @@ -65,8 +65,8 @@ class Migration(migrations.Migration):
('extra_data', models.JSONField(default=dict)),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('claims', models.JSONField(default=dict)),
('last_login_map_results', models.JSONField(default=list)),
('claims', models.JSONField(default=dict, blank=True)),
('last_login_map_results', models.JSONField(default=list, blank=True)),
('access_allowed', models.BooleanField(default=None, null=True)),
('provider', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='authenticator_user', to='authentication.authenticator', to_field='slug')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='authenticator_user', to=settings.AUTH_USER_MODEL)),
Expand Down
2 changes: 1 addition & 1 deletion ansible_base/authentication/models/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Authenticator(UniqueNamedCommonModel):
remove_users = fields.BooleanField(
default=True, help_text="When a user authenticates from this source should they be removed from any other groups they were previously added to"
)
configuration = prevent_search(JSONField(default=dict, help_text="The required configuration for this source"))
configuration = prevent_search(JSONField(default=dict, help_text="The required configuration for this source", blank=True))
type = fields.CharField(
editable=False,
max_length=256,
Expand Down
3 changes: 3 additions & 0 deletions ansible_base/authentication/models/authenticator_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ class Meta:
max_length=512,
null=True,
default=None,
blank=True,
help_text='A team name this rule works on',
)
organization = models.CharField(
max_length=512,
null=True,
default=None,
blank=True,
help_text='An organization name this rule works on',
)
triggers = models.JSONField(
null=False,
default=dict,
blank=True,
help_text="Trigger information for this rule",
)
order = models.PositiveIntegerField(
Expand Down
4 changes: 2 additions & 2 deletions ansible_base/authentication/models/social_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class AuthenticatorUser(AbstractUserSocialAuth):
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="authenticator_user", on_delete=models.CASCADE)
# TODO: set self.authenticated based on the provider that is passed to this method.
# the provider should be the name of the Authenticator model instance
claims = models.JSONField(default=dict, null=False)
last_login_map_results = models.JSONField(default=list, null=False)
claims = models.JSONField(default=dict, null=False, blank=True)
last_login_map_results = models.JSONField(default=list, null=False, blank=True)
# This field tracks if a user passed or failed an allow map
access_allowed = models.BooleanField(default=None, null=True)

Expand Down
6 changes: 3 additions & 3 deletions ansible_base/authentication/serializers/authenticator_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def validate(self, data) -> dict:
map_type = data.get('map_type', None)
team = data.get('team', None)
org = data.get('organization', None)
if map_type == 'team' and not team:
if map_type == 'team' and (not team or team == ''):
errors["team"] = "You must specify a team with the selected map type"
if map_type == 'team' and not org:
if map_type == 'team' and (not org or org == ''):
errors["organization"] = "You must specify an organization with the selected map type"
if map_type == 'organization' and not org:
if map_type == 'organization' and (not org or org == ''):
errors["organization"] = "You must specify an organization with the selected map type"

if not data.get('order', None):
Expand Down
2 changes: 2 additions & 0 deletions ansible_base/lib/abstract_models/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class Meta:
description = models.TextField(
null=False,
default="",
blank=True,
help_text=_("The organization description."),
)

users = models.ManyToManyField(
settings.AUTH_USER_MODEL,
related_name="organizations",
blank=True,
help_text=_("The list of users in this organization."),
)
6 changes: 3 additions & 3 deletions test_app/migrations/0002_team_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class Migration(migrations.Migration):
('created_on', models.DateTimeField(default=None, editable=False, help_text='The date/time this resource was created')),
('modified_on', models.DateTimeField(default=None, editable=False, help_text='The date/time this resource was created')),
('name', models.CharField(help_text='The name of this resource', max_length=512, unique=True)),
('description', models.TextField(default='', help_text='The organization description.')),
('description', models.TextField(default='', blank=True, help_text='The organization description.')),
('created_by', models.ForeignKey(default=None, editable=False, help_text='The user who created this resource', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='%(app_label)s_%(class)s_created+', to=settings.AUTH_USER_MODEL)),
('modified_by', models.ForeignKey(default=None, editable=False, help_text='The user who last modified this resource', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='%(app_label)s_%(class)s_modified+', to=settings.AUTH_USER_MODEL)),
('teams', models.ManyToManyField(help_text='The list of teams in this organization.', related_name='organizations', to='test_app.team')),
('users', models.ManyToManyField(help_text='The list of users in this organization.', related_name='organizations', to=settings.AUTH_USER_MODEL)),
('teams', models.ManyToManyField(help_text='The list of teams in this organization.', blank=True, related_name='organizations', to='test_app.team')),
('users', models.ManyToManyField(help_text='The list of users in this organization.', blank=True, related_name='organizations', to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
Expand Down
4 changes: 2 additions & 2 deletions test_app/tests/authentication/views/test_authenticator_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_authenticator_map_invalid_map_type(admin_api_client, local_authenticato
'is_superuser',
{'name': 'Rule 1', 'map_type': 'team', 'triggers': {'always': {}}, 'order': 1, 'organization': 'foobar-org', 'team': ''},
'team',
"This field may not be blank.",
"You must specify a team with the selected map type",
id="map_type=team, team param is empty string",
),
pytest.param(
Expand All @@ -126,7 +126,7 @@ def test_authenticator_map_invalid_map_type(admin_api_client, local_authenticato
'is_superuser',
{'name': 'Rule 1', 'map_type': 'team', 'triggers': {'always': {}}, 'order': 1, 'team': 'foobar-team', 'organization': ''},
'organization',
"This field may not be blank.",
"You must specify an organization with the selected map type",
id="map_type=team, organization param is empty string",
),
pytest.param(
Expand Down

0 comments on commit 906b2e2

Please sign in to comment.