fix e2e tests and some bugs
This commit is contained in:
@@ -79,11 +79,28 @@ describe('/album', () => {
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await utils.updateAlbumUser(user2.accessToken, {
|
// Make editor
|
||||||
id: albums[3].id,
|
await Promise.all([
|
||||||
userId: user1.userId,
|
utils.updateAlbumUser(user1.accessToken, {
|
||||||
updateAlbumUserDto: { role: AlbumUserRole.Editor },
|
id: albums[0].id,
|
||||||
});
|
userId: user2.userId,
|
||||||
|
updateAlbumUserDto: { role: AlbumUserRole.Editor },
|
||||||
|
}),
|
||||||
|
utils.updateAlbumUser(user2.accessToken, {
|
||||||
|
id: albums[3].id,
|
||||||
|
userId: user1.userId,
|
||||||
|
updateAlbumUserDto: { role: AlbumUserRole.Editor },
|
||||||
|
}),
|
||||||
|
utils.updateAlbumUser(user3.accessToken, {
|
||||||
|
id: albums[6].id,
|
||||||
|
userId: user1.userId,
|
||||||
|
updateAlbumUserDto: { role: AlbumUserRole.Editor },
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
albums[0].albumUsers[0].role = AlbumUserRole.Editor;
|
||||||
|
albums[3].albumUsers[0].role = AlbumUserRole.Editor;
|
||||||
|
albums[6].albumUsers[0].role = AlbumUserRole.Editor;
|
||||||
|
|
||||||
await addAssetsToAlbum(
|
await addAssetsToAlbum(
|
||||||
{ id: albums[3].id, bulkIdsDto: { ids: [user1Asset1.id] } },
|
{ id: albums[3].id, bulkIdsDto: { ids: [user1Asset1.id] } },
|
||||||
@@ -364,6 +381,7 @@ describe('/album', () => {
|
|||||||
albumThumbnailAssetId: null,
|
albumThumbnailAssetId: null,
|
||||||
shared: false,
|
shared: false,
|
||||||
sharedUsers: [],
|
sharedUsers: [],
|
||||||
|
albumUsers: [],
|
||||||
hasSharedLink: false,
|
hasSharedLink: false,
|
||||||
assets: [],
|
assets: [],
|
||||||
assetCount: 0,
|
assetCount: 0,
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export class AlbumEntity {
|
|||||||
@Column({ comment: 'Asset ID to be used as thumbnail', nullable: true })
|
@Column({ comment: 'Asset ID to be used as thumbnail', nullable: true })
|
||||||
albumThumbnailAssetId!: string | null;
|
albumThumbnailAssetId!: string | null;
|
||||||
|
|
||||||
@OneToMany(() => AlbumUserEntity, ({ album }) => album)
|
@OneToMany(() => AlbumUserEntity, ({ album }) => album, { cascade: true, onDelete: 'CASCADE' })
|
||||||
albumUsers!: AlbumUserEntity[];
|
albumUsers!: AlbumUserEntity[];
|
||||||
|
|
||||||
@ManyToMany(() => AssetEntity, (asset) => asset.albums)
|
@ManyToMany(() => AssetEntity, (asset) => asset.albums)
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ export class AlbumService {
|
|||||||
async addUsers(auth: AuthDto, id: string, dto: AddUsersDto): Promise<AlbumResponseDto> {
|
async addUsers(auth: AuthDto, id: string, dto: AddUsersDto): Promise<AlbumResponseDto> {
|
||||||
await this.access.requirePermission(auth, Permission.ALBUM_SHARE, id);
|
await this.access.requirePermission(auth, Permission.ALBUM_SHARE, id);
|
||||||
|
|
||||||
const album = await this.findOrFail(id, { withAssets: true });
|
const album = await this.findOrFail(id, { withAssets: false });
|
||||||
|
|
||||||
for (const userId of dto.sharedUserIds) {
|
for (const userId of dto.sharedUserIds) {
|
||||||
if (album.ownerId === userId) {
|
if (album.ownerId === userId) {
|
||||||
@@ -234,7 +234,7 @@ export class AlbumService {
|
|||||||
album.albumUsers.push(await this.albumUserRepository.create({ userId: userId, albumId: id }));
|
album.albumUsers.push(await this.albumUserRepository.create({ userId: userId, albumId: id }));
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapAlbumWithoutAssets(album);
|
return this.findOrFail(id, { withAssets: true }).then(mapAlbumWithoutAssets);
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeUser(auth: AuthDto, id: string, userId: string | 'me'): Promise<void> {
|
async removeUser(auth: AuthDto, id: string, userId: string | 'me'): Promise<void> {
|
||||||
@@ -264,13 +264,6 @@ export class AlbumService {
|
|||||||
async updateUser(auth: AuthDto, id: string, userId: string, dto: Partial<AlbumUserEntity>): Promise<void> {
|
async updateUser(auth: AuthDto, id: string, userId: string, dto: Partial<AlbumUserEntity>): Promise<void> {
|
||||||
await this.access.requirePermission(auth, Permission.ALBUM_SHARE, id);
|
await this.access.requirePermission(auth, Permission.ALBUM_SHARE, id);
|
||||||
|
|
||||||
const album = await this.findOrFail(id, { withAssets: false });
|
|
||||||
|
|
||||||
const permission = album.albumUsers.find(({ user: { id } }) => id === userId);
|
|
||||||
if (!permission) {
|
|
||||||
throw new BadRequestException('Album not shared with user');
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.albumUserRepository.update({ albumId: id, userId }, { role: dto.role });
|
await this.albumUserRepository.update({ albumId: id, userId }, { role: dto.role });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user