Skip to content

Commit 4b8a372

Browse files
HadleyKingtianywan819acoleman2000
authored
Prefix registry (#318)
* Created test_objects_drafts_modify, hasn't passed test yet * Created test_objects_drafts_modify, hasn't passed test yet * Created test_objects_drafts_modify, hasn't passed test yet * new tests * Update modify_prefix permissions Changes to be committed: modified: authentication/selectors.py modified: config/fixtures/local_data.json modified: prefix/services.py * Created and tested test_objects_drafts_modify API * Fixes for Prefix creation Changes to be committed: modified: config/services.py modified: prefix/apis.py modified: tests/test_apis/test_api_prefix/test_prefixes_create.py * Add UserSearch endpoint Changes to be committed: modified: prefix/apis.py modified: prefix/selectors.py modified: search/apis.py modified: search/urls.py * Fixes for deployment Changes to be committed: modified: .secrets.example modified: admin_only/bco_api.service modified: biocompute/apis.py modified: config/fixtures/test_portal.json modified: config/settings.py modified: tests/fixtures/test_data.json modified: tests/test_apis/test_biocompute/test_objects_drafts_create.py * test_objects_drafts_publish failed. Kicking back to Hadley for more investigation * Update bco_api.conf Changes to be committed: modified: admin_only/bco_api.conf --------- Co-authored-by: tianywan819 <[email protected]> Co-authored-by: acoleman29 <[email protected]>
1 parent 3cea13e commit 4b8a372

File tree

19 files changed

+2628
-4551
lines changed

19 files changed

+2628
-4551
lines changed

.secrets.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ ANON_KEY=
44

55
[SERVER]
66
PRODUCTION=
7+
DEBUG=True
8+
ALLOWED_HOSTS=
79
SERVER_VERSION=
810
HOSTNAME=
911
HUMAN_READABLE_HOSTNAME=
1012
PUBLIC_HOSTNAME=
1113
SERVER_URL=
12-
#DATABASE=
1314
DATABASE=
1415
EMAIL_BACKEND=

admin_only/bco_api.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ server {
5151
return 204;
5252
}
5353

54-
root /var/www/bcoeditor/portal/build/;
54+
root root /var/www/bcoeditor/portal_userdb/client/build;
5555
try_files $uri /index.html;
5656
#try_files $uri $uri/ =404;
5757
}

admin_only/bco_api.service

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[Unit]
2-
Description=BCO Test API gunicorn daemon
2+
Description=BCODB API gunicorn daemon
33
Requires=bco_api.socket
44
After=network.target
55

66
[Service]
77
User=bco_api_user
88
Group=nginx
9-
WorkingDirectory=/var/www/bcoeditor/bco_api/bco_api/
10-
ExecStart=/var/www/bcoeditor/bco_api/env/bin/gunicorn --access-logfile /var/log/gunicorn/api_stdout.log --log-level=debug --log-file /var/log/gunicorn/api_stderr.log --workers 3 --bind unix:/var/run/bco_api.sock bco_api.wsgi:application
9+
WorkingDirectory=/var/www/bcoeditor/bco_api/
10+
ExecStart=/var/www/bcoeditor/bco_api/env/bin/gunicorn --access-logfile /var/log/gunicorn/api_stdout.log --log-level=debug --log-file /var/log/gunicorn/api_stderr.log --workers 3 --bind unix:/var/run/bco_api.sock config.wsgi:application

authentication/selectors.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import jwt
44
from django.conf import settings
5-
from django.contrib.auth.models import User, Permission
5+
from django.contrib.auth.models import User
6+
from django.db.models import Q
67
from authentication.models import Authentication, NewUser
78
from rest_framework.authtoken.models import Token
89
from prefix.selectors import get_user_prefixes
10+
from prefix.models import Prefix
911
from biocompute.selectors import get_authorized_bcos
1012

1113
def get_anon()-> User:
@@ -70,22 +72,18 @@ def get_user_info(user: User) -> dict:
7072
A dict with the user information.
7173
"""
7274

73-
token = Token.objects.get(user=user.pk)
74-
other_info = {
75-
"permissions": {},
76-
"account_creation": "",
77-
}
78-
user_perms = {"prefixes": get_user_prefixes(user), "BCOs": get_authorized_bcos(user)}
79-
80-
other_info["permissions"] = user_perms
81-
82-
other_info["account_creation"] = user.date_joined
83-
8475
return {
8576
"hostname": settings.HOSTNAME,
8677
"human_readable_hostname": settings.HUMAN_READABLE_HOSTNAME,
8778
"public_hostname": settings.PUBLIC_HOSTNAME,
88-
"token": token.key,
79+
"token": Token.objects.get(user=user.pk).key,
8980
"username": user.username,
90-
"other_info": other_info,
81+
"permissions": {
82+
"owned_prefixes": Prefix.objects.filter(
83+
Q(owner=user)
84+
).values_list('prefix', flat=True).distinct(),
85+
"permissions": get_user_prefixes(user),
86+
"BCOs": get_authorized_bcos(user)
87+
},
88+
"account_creation": user.date_joined
9189
}

biocompute/apis.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ def post(self, request) -> Response:
101101
data = request.data
102102
rejected_requests = False
103103
accepted_requests = False
104-
if 'POST_api_objects_draft_create' in request.data:
104+
if 'POST_api_objects_drafts_create' in request.data:
105105
data = legacy_api_converter(request.data)
106106

107107
for index, object in enumerate(data):
108-
response_id = object.get("object_id", index)
108+
response_id = object["contents"].get("object_id", index)
109+
# response_id = object.get("object_id", index)
109110
bco_prefix = object.get("prefix", index)
110111
prefix_permitted = user_can_draft_prefix(owner, bco_prefix)
111112

@@ -346,7 +347,7 @@ def post(self, request) -> Response:
346347
data = legacy_api_converter(request.data)
347348

348349
for index, object in enumerate(data):
349-
response_id = object["contents"].get("object_id", index)
350+
response_id = object.get("object_id", index)
350351
modify_permitted = user_can_modify_bco(response_id, requester)
351352

352353
if modify_permitted is None:
@@ -556,6 +557,8 @@ def post(self, request) -> Response:
556557
data = legacy_api_converter(request.data)
557558

558559
for index, object in enumerate(data):
560+
import pdb; pdb.set_trace()
561+
# response_id = object["contents"].get("object_id", index)
559562
response_id = object.get("object_id", index)
560563
bco_instance = user_can_publish_bco(object, requester)
561564

config/fixtures/local_data.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,39 +846,39 @@
846846
},
847847
{
848848
"model": "authtoken.token",
849-
"pk": "1ef53d4042d14299918a4e1f21d2be128a2a7427",
849+
"pk": "0bd55c955fcbfc269f6dc8f61ea107674cafdecb",
850850
"fields": {
851851
"user": 5,
852852
"created": "2024-03-14T15:21:04.318Z"
853853
}
854854
},
855855
{
856856
"model": "authtoken.token",
857-
"pk": "49020e6fb85eb19a15bbdfb5cf6a1a28aaa8c1ce",
857+
"pk": "bd97d8cbec1fc7234e11e80957496aefc20c6395",
858858
"fields": {
859859
"user": 7,
860860
"created": "2024-04-03T10:53:08.951Z"
861861
}
862862
},
863863
{
864864
"model": "authtoken.token",
865-
"pk": "705531f3b2fbf80bb5a5b9d0cf4ee663676b4579",
865+
"pk": "c400a6076a2dfe7e9906ab86c6ad4574d1d60e03",
866866
"fields": {
867867
"user": 4,
868868
"created": "2024-03-14T15:21:14.996Z"
869869
}
870870
},
871871
{
872872
"model": "authtoken.token",
873-
"pk": "b8e588c4bdfb366420007827054042e8e594ec51",
873+
"pk": "627626823549f787c3ec763ff687169206626149",
874874
"fields": {
875875
"user": 1,
876876
"created": "2024-03-14T13:53:45.793Z"
877877
}
878878
},
879879
{
880880
"model": "authtoken.token",
881-
"pk": "ba1a932a6af59930293e087c1633fa60927b6690",
881+
"pk": "3f5504d88a5085d0452b19350fb6f82ae7097dd0",
882882
"fields": {
883883
"user": 6,
884884
"created": "2024-03-14T15:21:09.348Z"
@@ -4393,5 +4393,17 @@
43934393
"counter": 7,
43944394
"public": true
43954395
}
4396+
},
4397+
{
4398+
"model": "prefix.prefix",
4399+
"pk": "HIVE",
4400+
"fields": {
4401+
"certifying_key": "lazc=!pr35pau5b2x-x70y3_t++d5^s4cgk=mjo5o3^9zvrzki",
4402+
"created": "2024-03-14T13:53:59Z",
4403+
"description": "Test HIVE prefix",
4404+
"owner": "hivelab",
4405+
"counter": 0,
4406+
"public": true
4407+
}
43964408
}
43974409
]

0 commit comments

Comments
 (0)