From 1adb5e724d4e6d3312f570dd6fc967c878662fb2 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 9 Dec 2022 03:36:24 -0800 Subject: [PATCH] fix object creation, user serialization, user creation --- .../user-edit-dialog/user-edit-dialog.component.ts | 4 ++-- src-ui/src/app/data/object-with-permissions.ts | 2 +- src-ui/src/app/services/permissions.service.ts | 2 +- src/documents/serialisers.py | 13 +++++++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src-ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts index c3add99cd..0a87e33aa 100644 --- a/src-ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.ts @@ -52,8 +52,8 @@ export class UserEditDialogComponent last_name: new FormControl(''), is_active: new FormControl(true), is_superuser: new FormControl(false), - groups: new FormControl(null), - user_permissions: new FormControl(null), + groups: new FormControl([]), + user_permissions: new FormControl([]), }) } diff --git a/src-ui/src/app/data/object-with-permissions.ts b/src-ui/src/app/data/object-with-permissions.ts index dce0cc02a..86f5f7394 100644 --- a/src-ui/src/app/data/object-with-permissions.ts +++ b/src-ui/src/app/data/object-with-permissions.ts @@ -13,7 +13,7 @@ export interface PermissionsObject { } export interface ObjectWithPermissions extends ObjectWithId { - owner?: PaperlessUser + owner?: number permissions?: PermissionsObject } diff --git a/src-ui/src/app/services/permissions.service.ts b/src-ui/src/app/services/permissions.service.ts index b9bad0d96..e2c280b35 100644 --- a/src-ui/src/app/services/permissions.service.ts +++ b/src-ui/src/app/services/permissions.service.ts @@ -45,7 +45,7 @@ export class PermissionsService { } public currentUserOwnsObject(object: ObjectWithPermissions): boolean { - return !object || !object.owner || object.owner.id === this.currentUser.id + return !object || !object.owner || object.owner === this.currentUser.id } public currentUserHasObjectPermissions( diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 09cd4d9f6..2f0205031 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -172,9 +172,12 @@ class OwnedObjectSerializer(serializers.ModelSerializer, SetPermissionsMixin): "owner" not in validated_data or validated_data["owner"] is None ): validated_data["owner"] = self.user - instance = super().create(validated_data) + permissions = None if "set_permissions" in validated_data: - self._set_permissions(validated_data["set_permissions"], instance) + permissions = validated_data.pop("set_permissions") + instance = super().create(validated_data) + if permissions is not None: + self._set_permissions(permissions, instance) return instance def update(self, instance, validated_data): @@ -343,6 +346,12 @@ class DocumentSerializer(DynamicFieldsModelSerializer, OwnedObjectSerializer): archived_file_name = SerializerMethodField() created_date = serializers.DateField(required=False) + owner = serializers.PrimaryKeyRelatedField( + queryset=User.objects.all(), + required=False, + allow_null=True, + ) + def get_original_file_name(self, obj): return obj.get_public_filename()