High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(server): cannot share album to owner (#18802)
Daimoleanc89ac5b5e500
diff --git a/e2e/src/api/specs/album.e2e-spec.ts b/e2e/src/api/specs/album.e2e-spec.tsindex 65a94122fa..eedf70dc58 100644--- a/e2e/src/api/specs/album.e2e-spec.ts+++ b/e2e/src/api/specs/album.e2e-spec.ts@@ -428,6 +428,15 @@ describe('/albums', () => {order: AssetOrder.Desc,});});++ it('should not be able to share album with owner', async () => {+ const { status, body } = await request(app)+ .post('/albums')+ .send({ albumName: 'New album', albumUsers: [{ role: AlbumUserRole.Editor, userId: user1.userId }] })+ .set('Authorization', `Bearer ${user1.accessToken}`);+ expect(status).toBe(400);+ expect(body).toEqual(errorDto.badRequest('Cannot share album with owner'));+ });});describe('PUT /albums/:id/assets', () => {diff --git a/server/src/services/album.service.spec.ts b/server/src/services/album.service.spec.tsindex c2b792d091..f3bb7d1d5c 100644--- a/server/src/services/album.service.spec.ts+++ b/server/src/services/album.service.spec.ts@@ -210,6 +210,17 @@ describe(AlbumService.name, () => {false,);});++ it('should throw an error if the userId is the ownerId', async () => {+ mocks.user.get.mockResolvedValue(userStub.admin);+ await expect(+ sut.create(authStub.admin, {+ albumName: 'Empty album',+ albumUsers: [{ userId: userStub.admin.id, role: AlbumUserRole.EDITOR }],+ }),+ ).rejects.toBeInstanceOf(BadRequestException);+ expect(mocks.album.create).not.toHaveBeenCalled();+ });});describe('update', () => {diff --git a/server/src/services/album.service.ts b/server/src/services/album.service.tsindex d4e6ab7ffd..83d9535505 100644--- a/server/src/services/album.service.ts+++ b/server/src/services/album.service.ts@@ -93,6 +93,10 @@ export class AlbumService extends BaseService {if (!exists) {throw new BadRequestException('User not found');}++ if (userId == auth.user.id) {+ throw new BadRequestException('Cannot share album with owner');+ }}const allowedAssetIdsSet = await this.checkAccess({