Skip to content

Commit e28711b

Browse files
authored
Bco perms (#293)
* Add `DraftRetrieveApi` To do this functions related to Prefixes and the associated permissions were created Changes to be committed: modified: biocompute/apis.py modified: biocompute/models.py modified: biocompute/selectors.py modified: biocompute/services.py modified: biocompute/urls.py modified: config/asgi.py modified: config/fixtures/local_data.json modified: config/services.py modified: config/urls.py modified: prefix/selectors.py modified: prefix/services.py deleted: test.json modified: tests/fixtures/example_bco.py modified: tests/fixtures/test_data.json deleted: token.json * Update testing functions Created subdirectory and moved test functions Changes to be committed: renamed: tests/test_views/__init__.py -> tests/test_apis/__init__.py new file: tests/test_apis/test_api_authentication/__init__.py renamed: tests/test_views/test_account_activate.py -> tests/test_apis/test_api_authentication/test_account_activate.py renamed: tests/test_views/test_account_describe.py -> tests/test_apis/test_api_authentication/test_account_describe.py renamed: tests/test_views/test_account_new.py -> tests/test_apis/test_api_authentication/test_account_new.py renamed: tests/test_views/test_api_auth_add.py -> tests/test_apis/test_api_authentication/test_api_auth_add.py renamed: tests/test_views/test_api_auth_remove.py -> tests/test_apis/test_api_authentication/test_api_auth_remove.py renamed: tests/test_views/test_api_auth_reset_token.py -> tests/test_apis/test_api_authentication/test_api_auth_reset_token.py renamed: tests/test_views/test_api_objects_drafts_create.py -> tests/test_apis/test_api_objects_drafts_create.py renamed: tests/test_views/test_auth_add.py -> tests/test_apis/test_auth_add.py renamed: tests/test_views/test_auth_remove.py -> tests/test_apis/test_auth_remove.py renamed: tests/test_views/test_auth_reset_token.py -> tests/test_apis/test_auth_reset_token.py renamed: tests/test_views/test_objects_drafts_create.py -> tests/test_apis/test_objects_drafts_create.py renamed: tests/test_views/test_prefixes_create.py -> tests/test_apis/test_prefixes_create.py new file: tests/test_apis/test_prefixes_modify.py deleted: tests/test_views/test_api_account_activate.py deleted: tests/test_views/test_api_account_describe.py deleted: tests/test_views/test_api_account_new.py deleted: tests/test_views/test_prefixes_modify.py * Update to Test functions Changes to be committed: modified: biocompute/migrations/0001_initial.py modified: docs/refactor.md modified: prefix/apis.py modified: prefix/migrations/0001_initial.py modified: prefix/services.py new file: tests/fixtures/bco_dump.json modified: tests/fixtures/test_data.json deleted: tests/test_apis/test_api_authentication/test_api_auth_add.py deleted: tests/test_apis/test_api_authentication/test_api_auth_reset_token.py renamed: tests/test_apis/test_auth_add.py -> tests/test_apis/test_api_authentication/test_auth_add.py renamed: tests/test_apis/test_auth_reset_token.py -> tests/test_apis/test_api_authentication/test_auth_reset_token.py renamed: tests/test_apis/test_api_authentication/test_api_auth_remove.py -> tests/test_apis/test_api_authentication/testi_auth_remove.py deleted: tests/test_apis/test_api_objects_drafts_create.py new file: tests/test_apis/test_api_prefix/__init__.py renamed: tests/test_apis/test_prefixes_create.py -> tests/test_apis/test_api_prefix/test_prefixes_create.py renamed: tests/test_apis/test_prefixes_modify.py -> tests/test_apis/test_api_prefix/test_prefixes_modify.py deleted: tests/test_apis/test_auth_remove.py new file: tests/test_apis/test_biocompute/__init__.py renamed: tests/test_apis/test_objects_drafts_create.py -> tests/test_apis/test_biocompute/test_objects_drafts_create.py
1 parent 5a4a5c9 commit e28711b

File tree

15 files changed

+5829
-124
lines changed

15 files changed

+5829
-124
lines changed

biocompute/migrations/0001_initial.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 3.2.13 on 2024-03-20 18:48
1+
# Generated by Django 3.2.13 on 2024-04-02 20:08
22

33
from django.conf import settings
44
from django.db import migrations, models
@@ -10,9 +10,8 @@ class Migration(migrations.Migration):
1010
initial = True
1111

1212
dependencies = [
13-
('prefix', '0001_initial'),
14-
('auth', '0012_alter_user_first_name_max_length'),
1513
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
14+
('prefix', '0001_initial'),
1615
]
1716

1817
operations = [
@@ -24,9 +23,8 @@ class Migration(migrations.Migration):
2423
('state', models.CharField(choices=[('REFERENCED', 'referenced'), ('PUBLISHED', 'published'), ('DRAFT', 'draft'), ('DELETE', 'delete')], default='DRAFT', max_length=20)),
2524
('last_update', models.DateTimeField()),
2625
('access_count', models.IntegerField(default=0)),
27-
('authorized_groups', models.ManyToManyField(blank=True, to='auth.Group')),
2826
('authorized_users', models.ManyToManyField(blank=True, related_name='authorized_bcos', to=settings.AUTH_USER_MODEL)),
29-
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owned_bcos', to=settings.AUTH_USER_MODEL)),
27+
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owned_bcos', to=settings.AUTH_USER_MODEL, to_field='username')),
3028
('prefix', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='prefix.prefix')),
3129
],
3230
),

docs/refactor.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,13 @@ Prefix Perms:
5252
delete -> Delete Draft
5353
publish -> Publish Draft
5454
view -> View/download
55-
ONLY if private
55+
ONLY if private
56+
57+
If prefix is public anyone can view, but only auth users can modify.
58+
59+
Things to look for when reviewing code:
60+
- variable names are consistant and make sense
61+
- all functions have documentation. This shoudl include:
62+
- descriptions
63+
- explicit parameters/inputs and outputs/returns
64+
- hoverover should display function documentation

prefix/apis.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def post(self, request) -> Response:
124124
data = request.data
125125
rejected_requests = False
126126
accepted_requests = False
127+
if 'POST_api_prefixes_create' in request.data:
128+
data = legacy_api_converter(request.data)
127129

128130
if data[0]['prefix']=='test' and data[0]['public'] is True:
129131
return Response(
@@ -132,9 +134,6 @@ def post(self, request) -> Response:
132134
'TEST',"SUCCESS",201,"Prefix TEST created"
133135
)
134136
)
135-
136-
if 'POST_api_prefixes_create' in request.data:
137-
data = legacy_api_converter(request.data)
138137

139138
for index, object in enumerate(data):
140139
response_id = object.get("prefix", index).upper()

prefix/migrations/0001_initial.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 3.2.13 on 2024-03-20 18:48
1+
# Generated by Django 3.2.13 on 2024-04-02 20:08
22

33
from django.conf import settings
44
from django.db import migrations, models
@@ -12,7 +12,6 @@ class Migration(migrations.Migration):
1212

1313
dependencies = [
1414
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
15-
('auth', '0012_alter_user_first_name_max_length'),
1615
]
1716

1817
operations = [
@@ -24,7 +23,7 @@ class Migration(migrations.Migration):
2423
('created', models.DateTimeField(blank=True, default=django.utils.timezone.now, null=True)),
2524
('description', models.TextField(blank=True, null=True)),
2625
('counter', models.IntegerField(default=0, help_text='Counter for object_id asignment')),
27-
('authorized_groups', models.ManyToManyField(blank=True, related_name='authorized_prefix', to='auth.Group')),
26+
('public', models.BooleanField(default=True, help_text='Boolean field to indicate if there are restrictions on the use of this prefix')),
2827
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, to_field='username')),
2928
],
3029
),

prefix/services.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ def create(self, validated_data):
105105
"""
106106

107107
validated_data.pop('user_permissions')
108-
public = validated_data['public']
108+
109+
try:
110+
public = validated_data['public']
111+
except KeyError:
112+
public, validated_data['public'] = True, True
113+
109114
prefix_instance = Prefix.objects.create(**validated_data, created=timezone.now())
110115

111116
if public is False:

0 commit comments

Comments
 (0)