mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
Make object permissions show
This commit is contained in:
parent
f4298d5add
commit
451e02b7ca
@ -1,4 +1,7 @@
|
|||||||
from drf_spectacular.extensions import OpenApiAuthenticationExtension
|
from drf_spectacular.extensions import OpenApiAuthenticationExtension
|
||||||
|
from drf_spectacular.types import OpenApiTypes
|
||||||
|
from drf_spectacular.utils import OpenApiParameter
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
|
||||||
|
|
||||||
class AngularApiAuthenticationOverrideScheme(OpenApiAuthenticationExtension):
|
class AngularApiAuthenticationOverrideScheme(OpenApiAuthenticationExtension):
|
||||||
@ -10,3 +13,28 @@ class AngularApiAuthenticationOverrideScheme(OpenApiAuthenticationExtension):
|
|||||||
"name": "Angular Authorization",
|
"name": "Angular Authorization",
|
||||||
"description": "Automatic Angular authentication for the dev server",
|
"description": "Automatic Angular authentication for the dev server",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def generate_object_with_permissions_schema(serializer_class):
|
||||||
|
return {
|
||||||
|
"list": extend_schema(
|
||||||
|
parameters=[
|
||||||
|
OpenApiParameter(
|
||||||
|
name="full_perms",
|
||||||
|
type=OpenApiTypes.BOOL,
|
||||||
|
location=OpenApiParameter.QUERY,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
responses={200: serializer_class(many=True, all_fields=True)},
|
||||||
|
),
|
||||||
|
"retrieve": extend_schema(
|
||||||
|
parameters=[
|
||||||
|
OpenApiParameter(
|
||||||
|
name="full_perms",
|
||||||
|
type=OpenApiTypes.BOOL,
|
||||||
|
location=OpenApiParameter.QUERY,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
responses={200: serializer_class(many=True, all_fields=True)},
|
||||||
|
),
|
||||||
|
}
|
||||||
|
@ -181,6 +181,7 @@ class SerializerWithPerms(serializers.Serializer):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.user = kwargs.pop("user", None)
|
self.user = kwargs.pop("user", None)
|
||||||
self.full_perms = kwargs.pop("full_perms", False)
|
self.full_perms = kwargs.pop("full_perms", False)
|
||||||
|
self.all_fields = kwargs.pop("all_fields", False)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@ -229,6 +230,7 @@ class OwnedObjectSerializer(
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
if not self.all_fields:
|
||||||
try:
|
try:
|
||||||
if self.full_perms:
|
if self.full_perms:
|
||||||
self.fields.pop("user_can_change")
|
self.fields.pop("user_can_change")
|
||||||
|
@ -133,6 +133,7 @@ from documents.permissions import PaperlessObjectPermissions
|
|||||||
from documents.permissions import get_objects_for_user_owner_aware
|
from documents.permissions import get_objects_for_user_owner_aware
|
||||||
from documents.permissions import has_perms_owner_aware
|
from documents.permissions import has_perms_owner_aware
|
||||||
from documents.permissions import set_permissions_for_object
|
from documents.permissions import set_permissions_for_object
|
||||||
|
from documents.schema import generate_object_with_permissions_schema
|
||||||
from documents.serialisers import AcknowledgeTasksViewSerializer
|
from documents.serialisers import AcknowledgeTasksViewSerializer
|
||||||
from documents.serialisers import BulkDownloadSerializer
|
from documents.serialisers import BulkDownloadSerializer
|
||||||
from documents.serialisers import BulkEditObjectsSerializer
|
from documents.serialisers import BulkEditObjectsSerializer
|
||||||
@ -262,29 +263,7 @@ class PermissionsAwareDocumentCountMixin(PassUserMixin):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
full_perms_schema = {
|
@extend_schema_view(**generate_object_with_permissions_schema(CorrespondentSerializer))
|
||||||
"list": extend_schema(
|
|
||||||
parameters=[
|
|
||||||
OpenApiParameter(
|
|
||||||
name="full_perms",
|
|
||||||
type=OpenApiTypes.BOOL,
|
|
||||||
location=OpenApiParameter.QUERY,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
"retrieve": extend_schema(
|
|
||||||
parameters=[
|
|
||||||
OpenApiParameter(
|
|
||||||
name="full_perms",
|
|
||||||
type=OpenApiTypes.BOOL,
|
|
||||||
location=OpenApiParameter.QUERY,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@extend_schema_view(**full_perms_schema)
|
|
||||||
class CorrespondentViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
class CorrespondentViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||||
model = Correspondent
|
model = Correspondent
|
||||||
|
|
||||||
@ -321,7 +300,7 @@ class CorrespondentViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
|||||||
return super().retrieve(request, *args, **kwargs)
|
return super().retrieve(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@extend_schema_view(**full_perms_schema)
|
@extend_schema_view(**generate_object_with_permissions_schema(TagSerializer))
|
||||||
class TagViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
class TagViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||||
model = Tag
|
model = Tag
|
||||||
|
|
||||||
@ -346,7 +325,7 @@ class TagViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
|||||||
ordering_fields = ("color", "name", "matching_algorithm", "match", "document_count")
|
ordering_fields = ("color", "name", "matching_algorithm", "match", "document_count")
|
||||||
|
|
||||||
|
|
||||||
@extend_schema_view(**full_perms_schema)
|
@extend_schema_view(**generate_object_with_permissions_schema(DocumentTypeSerializer))
|
||||||
class DocumentTypeViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
class DocumentTypeViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||||
model = DocumentType
|
model = DocumentType
|
||||||
|
|
||||||
@ -2023,7 +2002,7 @@ class BulkDownloadView(GenericAPIView):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@extend_schema_view(**full_perms_schema)
|
@extend_schema_view(**generate_object_with_permissions_schema(StoragePathSerializer))
|
||||||
class StoragePathViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
class StoragePathViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||||
model = StoragePath
|
model = StoragePath
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user