mirror of
https://github.com/immich-app/immich.git
synced 2026-02-12 11:58:15 +03:00
add role to addUsersToAlbum endpoint
This commit is contained in:
@@ -13,10 +13,23 @@ export class AlbumInfoDto {
|
||||
withoutAssets?: boolean;
|
||||
}
|
||||
|
||||
export class AddUserDto {
|
||||
@ValidateUUID()
|
||||
userId!: string;
|
||||
|
||||
@IsEnum(AlbumUserRole)
|
||||
@ApiProperty({ enum: AlbumUserRole, enumName: 'AlbumUserRole', default: AlbumUserRole.EDITOR })
|
||||
role?: AlbumUserRole;
|
||||
}
|
||||
|
||||
export class AddUsersDto {
|
||||
@ValidateUUID({ each: true })
|
||||
@ValidateUUID({ each: true, optional: true })
|
||||
@ArrayNotEmpty()
|
||||
sharedUserIds!: string[];
|
||||
@ApiProperty({ deprecated: true, description: 'Deprecated in favor of albumUsers' })
|
||||
sharedUserIds?: string[];
|
||||
|
||||
@ArrayNotEmpty()
|
||||
albumUsers!: AddUserDto[];
|
||||
}
|
||||
|
||||
export class CreateAlbumDto {
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from 'src/dtos/album.dto';
|
||||
import { BulkIdResponseDto, BulkIdsDto } from 'src/dtos/asset-ids.response.dto';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { AlbumUserEntity } from 'src/entities/album-user.entity';
|
||||
import { AlbumUserEntity, AlbumUserRole } from 'src/entities/album-user.entity';
|
||||
import { AlbumEntity } from 'src/entities/album.entity';
|
||||
import { AssetEntity } from 'src/entities/asset.entity';
|
||||
import { IAccessRepository } from 'src/interfaces/access.interface';
|
||||
@@ -211,12 +211,20 @@ export class AlbumService {
|
||||
return results;
|
||||
}
|
||||
|
||||
async addUsers(auth: AuthDto, id: string, dto: AddUsersDto): Promise<AlbumResponseDto> {
|
||||
async addUsers(auth: AuthDto, id: string, { albumUsers, sharedUserIds }: AddUsersDto): Promise<AlbumResponseDto> {
|
||||
// Remove once deprecated sharedUserIds is removed
|
||||
if (!albumUsers) {
|
||||
if (!sharedUserIds) {
|
||||
throw new BadRequestException('No users provided');
|
||||
}
|
||||
albumUsers = sharedUserIds.map((userId) => ({ userId, role: AlbumUserRole.EDITOR }));
|
||||
}
|
||||
|
||||
await this.access.requirePermission(auth, Permission.ALBUM_SHARE, id);
|
||||
|
||||
const album = await this.findOrFail(id, { withAssets: false });
|
||||
|
||||
for (const userId of dto.sharedUserIds) {
|
||||
for (const { userId, role } of albumUsers) {
|
||||
if (album.ownerId === userId) {
|
||||
throw new BadRequestException('Cannot be shared with owner');
|
||||
}
|
||||
@@ -231,7 +239,7 @@ export class AlbumService {
|
||||
throw new BadRequestException('User not found');
|
||||
}
|
||||
|
||||
await this.albumUserRepository.create({ userId: userId, albumId: id });
|
||||
await this.albumUserRepository.create({ userId: userId, albumId: id, role });
|
||||
}
|
||||
|
||||
return this.findOrFail(id, { withAssets: true }).then(mapAlbumWithoutAssets);
|
||||
|
||||
Reference in New Issue
Block a user