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

Bco perms #293

Merged
merged 4 commits into from
Apr 3, 2024
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
8 changes: 3 additions & 5 deletions biocompute/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2024-03-20 18:48
# Generated by Django 3.2.13 on 2024-04-02 20:08

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

dependencies = [
('prefix', '0001_initial'),
('auth', '0012_alter_user_first_name_max_length'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('prefix', '0001_initial'),
]

operations = [
Expand All @@ -24,9 +23,8 @@ class Migration(migrations.Migration):
('state', models.CharField(choices=[('REFERENCED', 'referenced'), ('PUBLISHED', 'published'), ('DRAFT', 'draft'), ('DELETE', 'delete')], default='DRAFT', max_length=20)),
('last_update', models.DateTimeField()),
('access_count', models.IntegerField(default=0)),
('authorized_groups', models.ManyToManyField(blank=True, to='auth.Group')),
('authorized_users', models.ManyToManyField(blank=True, related_name='authorized_bcos', to=settings.AUTH_USER_MODEL)),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owned_bcos', to=settings.AUTH_USER_MODEL)),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owned_bcos', to=settings.AUTH_USER_MODEL, to_field='username')),
('prefix', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='prefix.prefix')),
],
),
Expand Down
11 changes: 10 additions & 1 deletion docs/refactor.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ Prefix Perms:
delete -> Delete Draft
publish -> Publish Draft
view -> View/download
ONLY if private
ONLY if private

If prefix is public anyone can view, but only auth users can modify.

Things to look for when reviewing code:
- variable names are consistant and make sense
- all functions have documentation. This shoudl include:
- descriptions
- explicit parameters/inputs and outputs/returns
- hoverover should display function documentation
5 changes: 2 additions & 3 deletions prefix/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def post(self, request) -> Response:
data = request.data
rejected_requests = False
accepted_requests = False
if 'POST_api_prefixes_create' in request.data:
data = legacy_api_converter(request.data)

if data[0]['prefix']=='test' and data[0]['public'] is True:
return Response(
Expand All @@ -132,9 +134,6 @@ def post(self, request) -> Response:
'TEST',"SUCCESS",201,"Prefix TEST created"
)
)

if 'POST_api_prefixes_create' in request.data:
data = legacy_api_converter(request.data)

for index, object in enumerate(data):
response_id = object.get("prefix", index).upper()
Expand Down
5 changes: 2 additions & 3 deletions prefix/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2024-03-20 18:48
# Generated by Django 3.2.13 on 2024-04-02 20:08

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

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
Expand All @@ -24,7 +23,7 @@ class Migration(migrations.Migration):
('created', models.DateTimeField(blank=True, default=django.utils.timezone.now, null=True)),
('description', models.TextField(blank=True, null=True)),
('counter', models.IntegerField(default=0, help_text='Counter for object_id asignment')),
('authorized_groups', models.ManyToManyField(blank=True, related_name='authorized_prefix', to='auth.Group')),
('public', models.BooleanField(default=True, help_text='Boolean field to indicate if there are restrictions on the use of this prefix')),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, to_field='username')),
],
),
Expand Down
7 changes: 6 additions & 1 deletion prefix/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ def create(self, validated_data):
"""

validated_data.pop('user_permissions')
public = validated_data['public']

try:
public = validated_data['public']
except KeyError:
public, validated_data['public'] = True, True

prefix_instance = Prefix.objects.create(**validated_data, created=timezone.now())

if public is False:
Expand Down
Loading
Loading