mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
fix object creation, user serialization, user creation
This commit is contained in:
parent
8fad13b500
commit
1adb5e724d
@ -52,8 +52,8 @@ export class UserEditDialogComponent
|
|||||||
last_name: new FormControl(''),
|
last_name: new FormControl(''),
|
||||||
is_active: new FormControl(true),
|
is_active: new FormControl(true),
|
||||||
is_superuser: new FormControl(false),
|
is_superuser: new FormControl(false),
|
||||||
groups: new FormControl(null),
|
groups: new FormControl([]),
|
||||||
user_permissions: new FormControl(null),
|
user_permissions: new FormControl([]),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ export interface PermissionsObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ObjectWithPermissions extends ObjectWithId {
|
export interface ObjectWithPermissions extends ObjectWithId {
|
||||||
owner?: PaperlessUser
|
owner?: number
|
||||||
|
|
||||||
permissions?: PermissionsObject
|
permissions?: PermissionsObject
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ export class PermissionsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public currentUserOwnsObject(object: ObjectWithPermissions): boolean {
|
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(
|
public currentUserHasObjectPermissions(
|
||||||
|
@ -172,9 +172,12 @@ class OwnedObjectSerializer(serializers.ModelSerializer, SetPermissionsMixin):
|
|||||||
"owner" not in validated_data or validated_data["owner"] is None
|
"owner" not in validated_data or validated_data["owner"] is None
|
||||||
):
|
):
|
||||||
validated_data["owner"] = self.user
|
validated_data["owner"] = self.user
|
||||||
instance = super().create(validated_data)
|
permissions = None
|
||||||
if "set_permissions" in validated_data:
|
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
|
return instance
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
@ -343,6 +346,12 @@ class DocumentSerializer(DynamicFieldsModelSerializer, OwnedObjectSerializer):
|
|||||||
archived_file_name = SerializerMethodField()
|
archived_file_name = SerializerMethodField()
|
||||||
created_date = serializers.DateField(required=False)
|
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):
|
def get_original_file_name(self, obj):
|
||||||
return obj.get_public_filename()
|
return obj.get_public_filename()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user