1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-06 11:56:46 +01:00
This commit is contained in:
Matthias Rupp 2022-11-21 20:17:44 +01:00
parent 11407b7e30
commit 7653eda8b3
4 changed files with 10 additions and 10 deletions

View file

@ -123,6 +123,7 @@ describe('Album service', () => {
updateAlbum: jest.fn(), updateAlbum: jest.fn(),
getListByAssetId: jest.fn(), getListByAssetId: jest.fn(),
getCountByUserId: jest.fn(), getCountByUserId: jest.fn(),
getSharedAlbumCount: jest.fn(),
}; };
assetRepositoryMock = { assetRepositoryMock = {
@ -142,6 +143,7 @@ describe('Album service', () => {
getAssetWithNoThumbnail: jest.fn(), getAssetWithNoThumbnail: jest.fn(),
getAssetWithNoSmartInfo: jest.fn(), getAssetWithNoSmartInfo: jest.fn(),
getExistingAssets: jest.fn(), getExistingAssets: jest.fn(),
countByIdAndUser: jest.fn(),
}; };
downloadServiceMock = { downloadServiceMock = {

View file

@ -14,8 +14,6 @@ import {
Header, Header,
Put, Put,
UploadedFiles, UploadedFiles,
HttpException,
HttpStatus
} from '@nestjs/common'; } from '@nestjs/common';
import { Authenticated } from '../../decorators/authenticated.decorator'; import { Authenticated } from '../../decorators/authenticated.decorator';
import { AssetService } from './asset.service'; import { AssetService } from './asset.service';

View file

@ -10,11 +10,11 @@ import { CommunicationModule } from '../communication/communication.module';
import { QueueNameEnum } from '@app/job/constants/queue-name.constant'; import { QueueNameEnum } from '@app/job/constants/queue-name.constant';
import { AssetRepository, ASSET_REPOSITORY } from './asset-repository'; import { AssetRepository, ASSET_REPOSITORY } from './asset-repository';
import { DownloadModule } from '../../modules/download/download.module'; import { DownloadModule } from '../../modules/download/download.module';
import {ALBUM_REPOSITORY, AlbumRepository} from "../album/album-repository"; import { ALBUM_REPOSITORY, AlbumRepository } from '../album/album-repository';
import {AlbumEntity} from "@app/database/entities/album.entity"; import { AlbumEntity } from '@app/database/entities/album.entity';
import {UserAlbumEntity} from "@app/database/entities/user-album.entity"; import { UserAlbumEntity } from '@app/database/entities/user-album.entity';
import {UserEntity} from "@app/database/entities/user.entity"; import { UserEntity } from '@app/database/entities/user.entity';
import {AssetAlbumEntity} from "@app/database/entities/asset-album.entity"; import { AssetAlbumEntity } from '@app/database/entities/asset-album.entity';
@Module({ @Module({
imports: [ imports: [

View file

@ -54,7 +54,7 @@ import { InjectQueue } from '@nestjs/bull';
import { Queue } from 'bull'; import { Queue } from 'bull';
import { DownloadService } from '../../modules/download/download.service'; import { DownloadService } from '../../modules/download/download.service';
import { DownloadDto } from './dto/download-library.dto'; import { DownloadDto } from './dto/download-library.dto';
import { ALBUM_REPOSITORY, IAlbumRepository } from "../album/album-repository"; import { ALBUM_REPOSITORY, IAlbumRepository } from '../album/album-repository';
const fileInfo = promisify(stat); const fileInfo = promisify(stat);
@ -634,14 +634,14 @@ export class AssetService {
async checkAssetsAccess(authUser: AuthUserDto, assetIds: string[], mustBeOwner = false) { async checkAssetsAccess(authUser: AuthUserDto, assetIds: string[], mustBeOwner = false) {
for (const assetId of assetIds) { for (const assetId of assetIds) {
// Step 1: Check if user owns asset // Step 1: Check if user owns asset
if (await this._assetRepository.countByIdAndUser(assetId, authUser.id) == 1) { if ((await this._assetRepository.countByIdAndUser(assetId, authUser.id)) == 1) {
continue; continue;
} }
// Avoid additional checks if ownership is required // Avoid additional checks if ownership is required
if (!mustBeOwner) { if (!mustBeOwner) {
// Step 2: Check if asset is part of an album shared with me // Step 2: Check if asset is part of an album shared with me
if (await this._albumRepository.getSharedAlbumCount(authUser.id, assetId) > 0) { if ((await this._albumRepository.getSharedAlbumCount(authUser.id, assetId)) > 0) {
continue; continue;
} }