Skip to content

Commit

Permalink
Prefix registry (#318)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Apr 27, 2024
1 parent 3cea13e commit 4b8a372
Show file tree
Hide file tree
Showing 19 changed files with 2,628 additions and 4,551 deletions.
3 changes: 2 additions & 1 deletion .secrets.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ ANON_KEY=

[SERVER]
PRODUCTION=
DEBUG=True
ALLOWED_HOSTS=
SERVER_VERSION=
HOSTNAME=
HUMAN_READABLE_HOSTNAME=
PUBLIC_HOSTNAME=
SERVER_URL=
#DATABASE=
DATABASE=
EMAIL_BACKEND=
2 changes: 1 addition & 1 deletion admin_only/bco_api.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ server {
return 204;
}

root /var/www/bcoeditor/portal/build/;
root root /var/www/bcoeditor/portal_userdb/client/build;
try_files $uri /index.html;
#try_files $uri $uri/ =404;
}
Expand Down
6 changes: 3 additions & 3 deletions admin_only/bco_api.service
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[Unit]
Description=BCO Test API gunicorn daemon
Description=BCODB API gunicorn daemon
Requires=bco_api.socket
After=network.target

[Service]
User=bco_api_user
Group=nginx
WorkingDirectory=/var/www/bcoeditor/bco_api/bco_api/
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
WorkingDirectory=/var/www/bcoeditor/bco_api/
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
26 changes: 12 additions & 14 deletions authentication/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import jwt
from django.conf import settings
from django.contrib.auth.models import User, Permission
from django.contrib.auth.models import User
from django.db.models import Q
from authentication.models import Authentication, NewUser
from rest_framework.authtoken.models import Token
from prefix.selectors import get_user_prefixes
from prefix.models import Prefix
from biocompute.selectors import get_authorized_bcos

def get_anon()-> User:
Expand Down Expand Up @@ -70,22 +72,18 @@ def get_user_info(user: User) -> dict:
A dict with the user information.
"""

token = Token.objects.get(user=user.pk)
other_info = {
"permissions": {},
"account_creation": "",
}
user_perms = {"prefixes": get_user_prefixes(user), "BCOs": get_authorized_bcos(user)}

other_info["permissions"] = user_perms

other_info["account_creation"] = user.date_joined

return {
"hostname": settings.HOSTNAME,
"human_readable_hostname": settings.HUMAN_READABLE_HOSTNAME,
"public_hostname": settings.PUBLIC_HOSTNAME,
"token": token.key,
"token": Token.objects.get(user=user.pk).key,
"username": user.username,
"other_info": other_info,
"permissions": {
"owned_prefixes": Prefix.objects.filter(
Q(owner=user)
).values_list('prefix', flat=True).distinct(),
"permissions": get_user_prefixes(user),
"BCOs": get_authorized_bcos(user)
},
"account_creation": user.date_joined
}
9 changes: 6 additions & 3 deletions biocompute/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ def post(self, request) -> Response:
data = request.data
rejected_requests = False
accepted_requests = False
if 'POST_api_objects_draft_create' in request.data:
if 'POST_api_objects_drafts_create' in request.data:
data = legacy_api_converter(request.data)

for index, object in enumerate(data):
response_id = object.get("object_id", index)
response_id = object["contents"].get("object_id", index)
# response_id = object.get("object_id", index)
bco_prefix = object.get("prefix", index)
prefix_permitted = user_can_draft_prefix(owner, bco_prefix)

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

for index, object in enumerate(data):
response_id = object["contents"].get("object_id", index)
response_id = object.get("object_id", index)
modify_permitted = user_can_modify_bco(response_id, requester)

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

for index, object in enumerate(data):
import pdb; pdb.set_trace()
# response_id = object["contents"].get("object_id", index)
response_id = object.get("object_id", index)
bco_instance = user_can_publish_bco(object, requester)

Expand Down
22 changes: 17 additions & 5 deletions config/fixtures/local_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -846,39 +846,39 @@
},
{
"model": "authtoken.token",
"pk": "1ef53d4042d14299918a4e1f21d2be128a2a7427",
"pk": "0bd55c955fcbfc269f6dc8f61ea107674cafdecb",
"fields": {
"user": 5,
"created": "2024-03-14T15:21:04.318Z"
}
},
{
"model": "authtoken.token",
"pk": "49020e6fb85eb19a15bbdfb5cf6a1a28aaa8c1ce",
"pk": "bd97d8cbec1fc7234e11e80957496aefc20c6395",
"fields": {
"user": 7,
"created": "2024-04-03T10:53:08.951Z"
}
},
{
"model": "authtoken.token",
"pk": "705531f3b2fbf80bb5a5b9d0cf4ee663676b4579",
"pk": "c400a6076a2dfe7e9906ab86c6ad4574d1d60e03",
"fields": {
"user": 4,
"created": "2024-03-14T15:21:14.996Z"
}
},
{
"model": "authtoken.token",
"pk": "b8e588c4bdfb366420007827054042e8e594ec51",
"pk": "627626823549f787c3ec763ff687169206626149",
"fields": {
"user": 1,
"created": "2024-03-14T13:53:45.793Z"
}
},
{
"model": "authtoken.token",
"pk": "ba1a932a6af59930293e087c1633fa60927b6690",
"pk": "3f5504d88a5085d0452b19350fb6f82ae7097dd0",
"fields": {
"user": 6,
"created": "2024-03-14T15:21:09.348Z"
Expand Down Expand Up @@ -4393,5 +4393,17 @@
"counter": 7,
"public": true
}
},
{
"model": "prefix.prefix",
"pk": "HIVE",
"fields": {
"certifying_key": "lazc=!pr35pau5b2x-x70y3_t++d5^s4cgk=mjo5o3^9zvrzki",
"created": "2024-03-14T13:53:59Z",
"description": "Test HIVE prefix",
"owner": "hivelab",
"counter": 0,
"public": true
}
}
]
Loading

0 comments on commit 4b8a372

Please sign in to comment.