Skip to content

Commit 02d452f

Browse files
committed
Create NewUser model and remove new_user model
changed model behind `/api/accounts/new/` Changes to be committed: modified: api/admin.py new file: api/migrations/0006_delete_new_users.py modified: api/models.py deleted: api/scripts/method_specific/POST_api_accounts_new.py modified: api/urls.py modified: api/views.py modified: authentication/admin.py modified: authentication/apis.py new file: authentication/migrations/0002_newuser.py modified: authentication/models.py modified: authentication/selectors.py modified: authentication/services.py modified: tests/fixtures/test_data.json modified: tests/test_views/test_api_account_activate.py modified: tests/test_views/test_api_account_new.py
1 parent 47d9ed8 commit 02d452f

File tree

15 files changed

+5810
-7297
lines changed

15 files changed

+5810
-7297
lines changed

api/admin.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
"""
66

77
from django.contrib import admin
8-
from guardian.admin import GuardedModelAdmin
9-
from api.models import BCO, new_users
8+
from api.models import BCO
109
from api.model.prefix import Prefix, prefix_table
1110
from api.model.groups import GroupInfo
1211

1312
class BcoModelAdmin(admin.ModelAdmin):
1413
search_fields = ["contents", "object_id"]
1514
admin.site.register(BCO, BcoModelAdmin)
16-
# admin.site.register(
1715
admin.site.register(prefix_table)
18-
admin.site.register(new_users)
1916
admin.site.register(GroupInfo)
2017
admin.site.register(Prefix)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Generated by Django 3.2.13 on 2024-03-07 21:53
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0005_rename_prefixes_prefix'),
10+
]
11+
12+
operations = [
13+
migrations.DeleteModel(
14+
name='new_users',
15+
),
16+
]

api/models.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
23
"""Models
34
45
Explanation of optional fields:
@@ -71,43 +72,6 @@ def __str__(self):
7172
"""String for representing the BCO model (in Admin site etc.)."""
7273
return str(self.object_id)
7374

74-
75-
# For registering new users.
76-
class new_users(models.Model):
77-
"""Instead of using the User model, just use
78-
a crude table to store the temporary information
79-
when someone asks for a new account."""
80-
81-
email = models.EmailField()
82-
temp_identifier = models.TextField(max_length=100)
83-
# In case we are writing back to UserDB.
84-
token = models.TextField(blank=True, null=True)
85-
86-
# Which host to send the activation back to (i.e. UserDB).
87-
hostname = models.TextField(blank=True, null=True)
88-
# Issue with time zone, so implement the fix.
89-
# Source: https://stackoverflow.com/a/32411560
90-
created = models.DateTimeField(default=timezone.now)
91-
92-
def __email__(self):
93-
return str(self.email)
94-
95-
def __token__(self):
96-
return str(self.token)
97-
98-
def __hostname__(self):
99-
return str(self.hostname)
100-
101-
def __temp_identifier__(self):
102-
return str(self.temp_identifier)
103-
104-
105-
# def get_first_name(self):
106-
# return self.first_name
107-
108-
# User.add_to_class("__str__", get_first_name)
109-
110-
11175
# --- Receivers --- #
11276

11377

api/scripts/method_specific/POST_api_accounts_new.py

Lines changed: 0 additions & 155 deletions
This file was deleted.

api/urls.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from api.views import (
2121
ApiAccountsActivateUsernameTempIdentifier,
2222
ApiAccountsDescribe,
23-
ApiAccountsNew,
2423
ApiGroupsCreate,
2524
ApiGroupsInfo,
2625
ApiGroupsDelete,
@@ -133,7 +132,6 @@
133132
ApiAccountsActivateUsernameTempIdentifier.as_view(),
134133
),
135134
path("api/accounts/describe/", ApiAccountsDescribe.as_view()),
136-
path("api/accounts/new/", ApiAccountsNew.as_view()),
137135
path("api/groups/group_info/", ApiGroupsInfo.as_view()),
138136
path("api/groups/create/", ApiGroupsCreate.as_view()),
139137
path("api/groups/delete/", ApiGroupsDelete.as_view()),

api/views.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
from api.scripts.method_specific.POST_api_accounts_describe import (
4646
POST_api_accounts_describe,
4747
)
48-
from api.scripts.method_specific.POST_api_accounts_new import POST_api_accounts_new
4948
from api.scripts.method_specific.POST_api_objects_drafts_create import (
5049
post_api_objects_drafts_create,
5150
)
@@ -516,67 +515,6 @@ class ApiGroupsModify(APIView):
516515
def post(self, request):
517516
return check_post_and_process(request, post_api_groups_modify)
518517

519-
520-
class ApiAccountsNew(APIView):
521-
"""
522-
Account creation request
523-
524-
--------------------
525-
526-
Ask for a new account. Sends an e-mail to the provided e-mail, which must
527-
then be clicked to activate the account.
528-
529-
The account create depends on creation of an account in the associated
530-
user database. The authentication as well as the user database host
531-
information is used to make this request.
532-
533-
```JSON
534-
{
535-
"hostname": "http://localhost:8000",
536-
"email": "[email protected]",
537-
"token": "eyJ1c2VyX2lkIjoyNCwidXNlcm5hbWUiOiJoYWRsZXlraW5nIiwiZXhwIjoxNjQwNzE5NTUwLCJlbWFpbCI6ImhhZGxleV9raW5nQGd3dS5lZHUiLCJvcmlnX2lhdCI6MTY0MDExNDc1MH0.7G3VPmxUBOWFfu-fMt1_UsWAcH_Gd1DfpQa83EwFwYY"
538-
}
539-
```
540-
"""
541-
542-
# Anyone can ask for a new account
543-
authentication_classes = []
544-
permission_classes = []
545-
546-
request_body = openapi.Schema(
547-
type=openapi.TYPE_OBJECT,
548-
title="Account Creation Schema",
549-
description="Account creation schema description.",
550-
required=["hostname", "email", "token"],
551-
properties={
552-
"hostname": openapi.Schema(
553-
type=openapi.TYPE_STRING, description="Hostname of the User Database."
554-
),
555-
"email": openapi.Schema(
556-
type=openapi.TYPE_STRING, description="Email address of user."
557-
),
558-
"token": openapi.Schema(
559-
type=openapi.TYPE_STRING,
560-
description="Token returned with new user being "
561-
"generated in the User Database.",
562-
),
563-
},
564-
)
565-
566-
@swagger_auto_schema(
567-
request_body=request_body,
568-
responses={
569-
201: "Account creation request is successful.",
570-
400: "Bad request format.",
571-
409: "Account has already been authenticated or requested.",
572-
},
573-
tags=["Account Management"],
574-
)
575-
def post(self, request) -> Response:
576-
print("Request: {}".format(request))
577-
return check_post_and_process(request, POST_api_accounts_new)
578-
579-
580518
class ApiObjectsDraftsCreate(APIView):
581519
"""
582520
Create BCO Draft

authentication/admin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
"""
33

44
from django.contrib import admin
5-
from authentication.models import Authentication
5+
from authentication.models import Authentication, NewUser
66

7-
admin.site.register(Authentication)
7+
class AuthenticationAdmin(admin.ModelAdmin):
8+
list_display = ["username", "auth_service"]
9+
10+
class NewUserAdmin(admin.ModelAdmin):
11+
list_display = ["email", "temp_identifier","token", "hostname", "created"]
12+
13+
admin.site.register(Authentication, AuthenticationAdmin)
14+
admin.site.register(NewUser, NewUserAdmin)

0 commit comments

Comments
 (0)