Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New account #265

Merged
merged 3 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ class ApiConfig(AppConfig):
def ready(self):
"""Create the anonymous user if they don't exist."""

if not 'test' in sys.argv:
post_migrate.connect(populate_models, sender=self)
if 'test' in sys.argv or 'loaddata' in sys.argv or 'flush' in sys.argv:
return
else:
post_migrate.connect(populate_models, sender=self)
5 changes: 4 additions & 1 deletion api/model/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ def associate_user_group(sender, instance, created, **kwargs):
if the user isn't anon or the already existent bco_drafter or bco_publisher.
"""

if not 'test' in sys.argv:
if 'test' in sys.argv or 'loaddata' in sys.argv:
return

else:
if created:
print(instance)
Group.objects.create(name=instance)
Expand Down
9 changes: 7 additions & 2 deletions api/model/prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,10 @@ def create_permissions_for_prefix(sender, instance=None, **kwargs):
# owner_user=User.objects.get(username='wheel')
# )

if not 'test' in sys.argv:
if 'test' in sys.argv or 'loaddata' in sys.argv:
return

else:
owner_user = User.objects.get(username=instance.owner_user)
owner_group = Group.objects.get(name=instance.owner_group_id)
drafters = Group.objects.get(name=instance.prefix.lower() + "_drafter")
Expand Down Expand Up @@ -720,7 +723,9 @@ def create_counter_for_prefix(sender, instance=None, created=False, **kwargs):
instance: api.model.prefix.Prefix
created: bool
"""
if not 'test' in sys.argv:
if 'test' in sys.argv or 'loaddata' in sys.argv or 'flush' in sys.argv:
return
else:
if created:
prefix_table.objects.create(n_objects=1, prefix=instance.prefix)

Expand Down
22 changes: 13 additions & 9 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Source: https://www.django-rest-framework.org/api-guide/authentication/#generating-tokens
"""

import sys
from django.db import models
from django.conf import settings
from django.contrib.auth.models import Group, User
Expand Down Expand Up @@ -125,15 +126,18 @@ def create_auth_token(sender, instance=None, created=False, **kwargs):
"""Link user creation to token generation.
Source: https://www.django-rest-framework.org/api-guide/authentication/#generating-tokens
"""
if created:
# The anonymous user's token is hard-coded
# in server.conf.
if instance.username == "anon":
# Create anon's record with the hard-coded key.
Token.objects.create(user=instance, key=settings.ANON_KEY)
else:
# Create a normal user's record.
Token.objects.create(user=instance)
if 'loaddata' in sys.argv:
return
else:
if created:
# The anonymous user's token is hard-coded
# in server.conf.
if instance.username == "anon":
# Create anon's record with the hard-coded key.
Token.objects.create(user=instance, key=settings.ANON_KEY)
else:
# Create a normal user's record.
Token.objects.create(user=instance)


# Link object deletion to object permissions deletion.
Expand Down
5 changes: 4 additions & 1 deletion api/scripts/utilities/DbUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,10 @@ def messages(self, parameters, p_content=False):
"status_code": "409",
"message": "The provided object "
+ parameters["object_id"]
+ " has already been created on this server.",
+ " has already been created on this server."
+ " If you wish to publish a new version of this BCO try"
+ " to save the DRAFT with a different version number, and"
+ " then resubmit.",
},
"409_draft_object_id_conflict": {
"request_status": "FAILURE",
Expand Down
Loading