-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Changelog: * Fix(backend): Fixed permissions in schema generations for nested views. See merge request vst/vst-utils!622
- Loading branch information
Showing
11 changed files
with
332 additions
and
86 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...est_proj/migrations/0043_manufacturer_store_product_option_manufacturer_store_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Generated by Django 4.2.8 on 2023-12-20 06:45 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('test_proj', '0042_testexternalcustommodel'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Manufacturer', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
], | ||
options={ | ||
'default_related_name': 'manufacturers', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Store', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
], | ||
options={ | ||
'default_related_name': 'stores', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Product', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
('price', models.DecimalField(decimal_places=2, max_digits=10)), | ||
('manufacturer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_proj.manufacturer')), | ||
('store', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_proj.store')), | ||
], | ||
options={ | ||
'default_related_name': 'products', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Option', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_proj.product')), | ||
], | ||
options={ | ||
'default_related_name': 'options', | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='manufacturer', | ||
name='store', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_proj.store'), | ||
), | ||
migrations.CreateModel( | ||
name='Attribute', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='test_proj.product')), | ||
], | ||
options={ | ||
'default_related_name': 'attributes', | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,5 +66,5 @@ class Meta: | |
'protected': { | ||
'allow_append': True, | ||
'model': ProtectedBySignal, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from django.db import models | ||
from django.dispatch import receiver | ||
from django.db.models.signals import pre_delete | ||
from django.core.validators import ValidationError | ||
from rest_framework.permissions import BasePermission | ||
from rest_framework.request import Request | ||
from rest_framework.views import APIView | ||
|
||
from vstutils.models import BaseModel | ||
|
||
|
||
class DisallowStaffPermission(BasePermission): | ||
def has_permission(self, request, view): | ||
if not request.user.is_superuser and request.user.is_staff: | ||
return False | ||
return super().has_permission(request, view) | ||
|
||
|
||
class Option(BaseModel): | ||
name = models.CharField(max_length=255) | ||
product = models.ForeignKey('Product', on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
default_related_name = 'options' | ||
|
||
|
||
class Attribute(BaseModel): | ||
name = models.CharField(max_length=255) | ||
product = models.ForeignKey('Product', on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
default_related_name = 'attributes' | ||
_permission_classes = [DisallowStaffPermission] | ||
|
||
|
||
class Product(BaseModel): | ||
name = models.CharField(max_length=255) | ||
price = models.DecimalField(max_digits=10, decimal_places=2) | ||
store = models.ForeignKey('Store', on_delete=models.CASCADE) | ||
manufacturer = models.ForeignKey('Manufacturer', on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
default_related_name = 'products' | ||
_nested = { | ||
'options': { | ||
'allow_append': True, | ||
'model': Option, | ||
}, | ||
'attributes': { | ||
'allow_append': True, | ||
'model': Attribute, | ||
} | ||
} | ||
|
||
|
||
class Manufacturer(BaseModel): | ||
name = models.CharField(max_length=255) | ||
store = models.ForeignKey('Store', on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
default_related_name = 'manufacturers' | ||
_nested = { | ||
'products': { | ||
'allow_append': False, | ||
'model': Product, | ||
} | ||
} | ||
|
||
|
||
class Store(BaseModel): | ||
name = models.CharField(max_length=255) | ||
|
||
class Meta: | ||
default_related_name = 'stores' | ||
_nested = { | ||
'products': { | ||
'allow_append': True, | ||
'model': Product, | ||
}, | ||
'manufacturers': { | ||
'allow_append': False, | ||
'model': Manufacturer, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# pylint: disable=django-not-available | ||
__version__: str = '5.8.18' | ||
__version__: str = '5.8.19' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.