mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
refactor(server): shared link asset access check (#2680)
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { IAccessRepository } from '@app/domain';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { PartnerEntity } from '../entities';
|
||||
import { PartnerEntity, SharedLinkEntity } from '../entities';
|
||||
|
||||
export class AccessRepository implements IAccessRepository {
|
||||
constructor(@InjectRepository(PartnerEntity) private partnerRepository: Repository<PartnerEntity>) {}
|
||||
constructor(
|
||||
@InjectRepository(PartnerEntity) private partnerRepository: Repository<PartnerEntity>,
|
||||
@InjectRepository(SharedLinkEntity) private sharedLinkRepository: Repository<SharedLinkEntity>,
|
||||
) {}
|
||||
|
||||
hasPartnerAccess(userId: string, partnerId: string): Promise<boolean> {
|
||||
return this.partnerRepository.exist({
|
||||
@@ -35,4 +38,29 @@ export class AccessRepository implements IAccessRepository {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async hasSharedLinkAssetAccess(sharedLinkId: string, assetId: string): Promise<boolean> {
|
||||
return (
|
||||
// album asset
|
||||
(await this.sharedLinkRepository.exist({
|
||||
where: {
|
||||
id: sharedLinkId,
|
||||
album: {
|
||||
assets: {
|
||||
id: assetId,
|
||||
},
|
||||
},
|
||||
},
|
||||
})) ||
|
||||
// individual asset
|
||||
(await this.sharedLinkRepository.exist({
|
||||
where: {
|
||||
id: sharedLinkId,
|
||||
assets: {
|
||||
id: assetId,
|
||||
},
|
||||
},
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,31 +86,6 @@ export class SharedLinkRepository implements ISharedLinkRepository {
|
||||
await this.repository.remove(entity);
|
||||
}
|
||||
|
||||
async hasAssetAccess(id: string, assetId: string): Promise<boolean> {
|
||||
return (
|
||||
// album asset
|
||||
(await this.repository.exist({
|
||||
where: {
|
||||
id,
|
||||
album: {
|
||||
assets: {
|
||||
id: assetId,
|
||||
},
|
||||
},
|
||||
},
|
||||
})) ||
|
||||
// individual asset
|
||||
(await this.repository.exist({
|
||||
where: {
|
||||
id,
|
||||
assets: {
|
||||
id: assetId,
|
||||
},
|
||||
},
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
private async save(entity: Partial<SharedLinkEntity>): Promise<SharedLinkEntity> {
|
||||
await this.repository.save(entity);
|
||||
return this.repository.findOneOrFail({ where: { id: entity.id } });
|
||||
|
||||
Reference in New Issue
Block a user