refactor(note-user-permission-entry-dto): do not embed User objects

This is part of an effort to consistently not embed User objects
in API responses. Usernames are returned instead.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-01-16 22:24:54 +01:00
parent b955faa983
commit 13284b26cb
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 10 additions and 10 deletions

View file

@ -17,11 +17,11 @@ import { UserInfoDto } from '../users/user-info.dto';
export class NoteUserPermissionEntryDto { export class NoteUserPermissionEntryDto {
/** /**
* User this permission applies to * Username of the User this permission applies to
*/ */
@ValidateNested() @IsString()
@ApiProperty({ type: UserInfoDto }) @ApiProperty()
user: UserInfoDto; username: string;
/** /**
* True if the user is allowed to edit the note * True if the user is allowed to edit the note

View file

@ -688,7 +688,7 @@ describe('NotesService', () => {
const permissions = await service.toNotePermissionsDto(note); const permissions = await service.toNotePermissionsDto(note);
expect(permissions.owner).toEqual(user.username); expect(permissions.owner).toEqual(user.username);
expect(permissions.sharedToUsers).toHaveLength(1); expect(permissions.sharedToUsers).toHaveLength(1);
expect(permissions.sharedToUsers[0].user.username).toEqual(user.username); expect(permissions.sharedToUsers[0].username).toEqual(user.username);
expect(permissions.sharedToUsers[0].canEdit).toEqual(true); expect(permissions.sharedToUsers[0].canEdit).toEqual(true);
expect(permissions.sharedToGroups).toHaveLength(1); expect(permissions.sharedToGroups).toHaveLength(1);
expect(permissions.sharedToGroups[0].group.displayName).toEqual( expect(permissions.sharedToGroups[0].group.displayName).toEqual(
@ -778,7 +778,7 @@ describe('NotesService', () => {
expect(metadataDto.editedBy[0]).toEqual(user.username); expect(metadataDto.editedBy[0]).toEqual(user.username);
expect(metadataDto.permissions.owner).toEqual(user.username); expect(metadataDto.permissions.owner).toEqual(user.username);
expect(metadataDto.permissions.sharedToUsers).toHaveLength(1); expect(metadataDto.permissions.sharedToUsers).toHaveLength(1);
expect(metadataDto.permissions.sharedToUsers[0].user.username).toEqual( expect(metadataDto.permissions.sharedToUsers[0].username).toEqual(
user.username, user.username,
); );
expect(metadataDto.permissions.sharedToUsers[0].canEdit).toEqual(true); expect(metadataDto.permissions.sharedToUsers[0].canEdit).toEqual(true);
@ -880,9 +880,9 @@ describe('NotesService', () => {
expect(noteDto.metadata.editedBy[0]).toEqual(user.username); expect(noteDto.metadata.editedBy[0]).toEqual(user.username);
expect(noteDto.metadata.permissions.owner).toEqual(user.username); expect(noteDto.metadata.permissions.owner).toEqual(user.username);
expect(noteDto.metadata.permissions.sharedToUsers).toHaveLength(1); expect(noteDto.metadata.permissions.sharedToUsers).toHaveLength(1);
expect( expect(noteDto.metadata.permissions.sharedToUsers[0].username).toEqual(
noteDto.metadata.permissions.sharedToUsers[0].user.username, user.username,
).toEqual(user.username); );
expect(noteDto.metadata.permissions.sharedToUsers[0].canEdit).toEqual( expect(noteDto.metadata.permissions.sharedToUsers[0].canEdit).toEqual(
true, true,
); );

View file

@ -375,7 +375,7 @@ export class NotesService {
return { return {
owner: owner ? owner.username : null, owner: owner ? owner.username : null,
sharedToUsers: userPermissions.map((noteUserPermission) => ({ sharedToUsers: userPermissions.map((noteUserPermission) => ({
user: this.usersService.toUserDto(noteUserPermission.user), username: noteUserPermission.user.username,
canEdit: noteUserPermission.canEdit, canEdit: noteUserPermission.canEdit,
})), })),
sharedToGroups: groupPermissions.map((noteGroupPermission) => ({ sharedToGroups: groupPermissions.map((noteGroupPermission) => ({