fix(server): cannot share album to owner (#18802)

* fix(server): create shared album

* add test

* trigger ci

* resolve conversation
This commit is contained in:
Daimolean 2025-06-02 09:58:07 +08:00 committed by GitHub
parent daf1a48b54
commit c89ac5b5e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 0 deletions

View File

@ -428,6 +428,15 @@ describe('/albums', () => {
order: AssetOrder.Desc, 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', () => { describe('PUT /albums/:id/assets', () => {

View File

@ -210,6 +210,17 @@ describe(AlbumService.name, () => {
false, 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', () => { describe('update', () => {

View File

@ -93,6 +93,10 @@ export class AlbumService extends BaseService {
if (!exists) { if (!exists) {
throw new BadRequestException('User not found'); throw new BadRequestException('User not found');
} }
if (userId == auth.user.id) {
throw new BadRequestException('Cannot share album with owner');
}
} }
const allowedAssetIdsSet = await this.checkAccess({ const allowedAssetIdsSet = await this.checkAccess({