mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(web): Remove from Stack (#19703)
* - add component - update server's StackCreateDto for merge parameter - Update stackRepo to only merge stacks when merge=true (default) - update web action handlers to show stack changes * - make open-api * lint & format * - Add proper icon to 'remove from stack' - change web unstack icon to image-off-outline * - cleanup * - format & lint * - make open-api: StackCreateDto merge optional * initial addition of new endpoint * remove stack endpoint * - fix up remove stack endpoint - open-api * - Undo stackCreate merge parameter * - open-api typescript * open-api dart * Tests: - add tests - update assetStub.imageFrom2015 to have required stack attributes to include it with tests * update event name * Fix event name in test * remove asset_update check * - merge stack.removeAsset params into one object - refactor asset existence check (no need for asset fetch) - fix tests * Don't return updated stack * Create specialized stack id & primary asset fetch for asset removal checks * Correct new permission names * make sql * - fix open-api * - cleanup
This commit is contained in:
parent
1011cdb376
commit
1a70896113
19 changed files with 289 additions and 23 deletions
|
|
@ -4,6 +4,7 @@ import { AuthDto } from 'src/dtos/auth.dto';
|
|||
import { StackCreateDto, StackResponseDto, StackSearchDto, StackUpdateDto, mapStack } from 'src/dtos/stack.dto';
|
||||
import { Permission } from 'src/enum';
|
||||
import { BaseService } from 'src/services/base.service';
|
||||
import { UUIDAssetIDParamDto } from 'src/validation';
|
||||
|
||||
@Injectable()
|
||||
export class StackService extends BaseService {
|
||||
|
|
@ -58,6 +59,24 @@ export class StackService extends BaseService {
|
|||
await this.eventRepository.emit('StackDeleteAll', { stackIds: dto.ids, userId: auth.user.id });
|
||||
}
|
||||
|
||||
async removeAsset(auth: AuthDto, dto: UUIDAssetIDParamDto): Promise<void> {
|
||||
const { id: stackId, assetId } = dto;
|
||||
await this.requireAccess({ auth, permission: Permission.StackUpdate, ids: [stackId] });
|
||||
|
||||
const stack = await this.stackRepository.getForAssetRemoval(assetId);
|
||||
|
||||
if (!stack?.id || stack.id !== stackId) {
|
||||
throw new BadRequestException('Asset not in stack');
|
||||
}
|
||||
|
||||
if (stack.primaryAssetId === assetId) {
|
||||
throw new BadRequestException("Cannot remove stack's primary asset");
|
||||
}
|
||||
|
||||
await this.assetRepository.update({ id: assetId, stackId: null });
|
||||
await this.eventRepository.emit('StackUpdate', { stackId, userId: auth.user.id });
|
||||
}
|
||||
|
||||
private async findOrFail(id: string) {
|
||||
const stack = await this.stackRepository.getById(id);
|
||||
if (!stack) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue