Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api-key/api-key.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('APIKeyController (e2e)', () => {
await client.post('/api/v1/api-keys').send(apiKeyData).expect(403);
});

it('should return 403 when user tries to create API key with resource they do not have write access to', async () => {
it('should return 404 when user tries to create API key with resource they do not have write access to', async () => {
const apiKeyData = {
user_id: client.user.id,
namespace_id: client.namespace.id,
Expand All @@ -212,6 +212,6 @@ describe('APIKeyController (e2e)', () => {
},
};

await client.post('/api/v1/api-keys').send(apiKeyData).expect(403);
await client.post('/api/v1/api-keys').send(apiKeyData).expect(404);
});
});
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { TasksModule } from 'omniboxd/tasks/tasks.module';
import { WizardModule } from 'omniboxd/wizard/wizard.module';
import { APIKeyModule } from 'omniboxd/api-key/api-key.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ResourcesModule } from 'omniboxd/resources/resources.module';
import { NamespaceResourcesModule } from 'omniboxd/namespace-resources/namespace-resources.module';
import { SnakeCaseInterceptor } from 'omniboxd/interceptor/snake-case';
import { NamespacesModule } from 'omniboxd/namespaces/namespaces.module';
import { PermissionsModule } from 'omniboxd/permissions/permissions.module';
Expand Down Expand Up @@ -46,6 +46,7 @@ import { UpdateAttachmentUrls1755499552000 } from 'omniboxd/migrations/175549955
import { ScanResourceAttachments1755504936756 } from 'omniboxd/migrations/1755504936756-scan-resource-attachments';
import { OAuthModule } from 'omniboxd/oauth2/oauth.module';
import { SharesAllResources1754471311959 } from 'omniboxd/migrations/1754471311959-shares-all-resources';
import { ResourcesModule } from 'omniboxd/resources/resources.module';

@Module({})
export class AppModule implements NestModule {
Expand Down Expand Up @@ -75,6 +76,7 @@ export class AppModule implements NestModule {
UserModule,
APIKeyModule,
NamespacesModule,
NamespaceResourcesModule,
ResourcesModule,
TasksModule,
WizardModule,
Expand Down
4 changes: 2 additions & 2 deletions src/attachments/attachments.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestClient } from 'test/test-client';
import { HttpStatus } from '@nestjs/common';
import { uploadLanguageDatasets } from 'omniboxd/resources/file-resources.e2e-spec';
import { uploadLanguageDatasets } from 'omniboxd/namespace-resources/file-resources.e2e-spec';

describe('AttachmentsController (e2e)', () => {
let client: TestClient;
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('AttachmentsController (e2e)', () => {
`/api/v1/namespaces/${client.namespace.id}/resources/${nonExistentResourceId}/attachments`,
)
.attach('file[]', Buffer.from(testContent), 'test.txt')
.expect(403);
.expect(HttpStatus.NOT_FOUND);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IsOptional,
IsNotEmpty,
} from 'class-validator';
import { ResourceType } from 'omniboxd/resources/resources.entity';
import { ResourceType } from 'omniboxd/resources/entities/resource.entity';

export class CreateResourceDto {
@IsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ResourcePermission } from 'omniboxd/permissions/resource-permission.enum';
import { Resource, ResourceType } from '../resources.entity';
import {
Resource,
ResourceType,
} from 'omniboxd/resources/entities/resource.entity';
import { TagDto } from 'omniboxd/tag/dto/tag.dto';

export enum SpaceType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IsOptional,
IsNotEmpty,
} from 'class-validator';
import { ResourceType } from 'omniboxd/resources/resources.entity';
import { ResourceType } from 'omniboxd/resources/entities/resource.entity';

export class UpdateResourceDto {
@IsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from 'express';
import { FileInterceptor } from '@nestjs/platform-express';
import { ResourcesService } from 'omniboxd/resources/resources.service';
import { NamespaceResourcesService } from 'omniboxd/namespace-resources/namespace-resources.service';
import {
Body,
Controller,
Expand All @@ -18,7 +18,9 @@ import { UserId } from 'omniboxd/decorators/user-id.decorator';

@Controller('api/v1/namespaces/:namespaceId/resources/files')
export class FileResourcesController {
constructor(private readonly resourcesService: ResourcesService) {}
constructor(
private readonly namespaceResourcesService: NamespaceResourcesService,
) {}

@Post()
@UseInterceptors(FileInterceptor('file'))
Expand All @@ -28,14 +30,14 @@ export class FileResourcesController {
@Body('namespace_id') namespaceId: string,
@Body('parent_id') parentId: string,
) {
const newResource = await this.resourcesService.uploadFile(
const newResource = await this.namespaceResourcesService.uploadFile(
userId,
namespaceId,
file,
parentId,
undefined,
);
return await this.resourcesService.getPath({
return await this.namespaceResourcesService.getPath({
namespaceId,
userId,
resourceId: newResource.id,
Expand All @@ -50,7 +52,7 @@ export class FileResourcesController {
@Body('file_hash') fileHash: string,
@Body('namespace_id') namespaceId: string,
) {
return this.resourcesService.uploadFileChunk(
return this.namespaceResourcesService.uploadFileChunk(
namespaceId,
chunk,
chunkNumber,
Expand All @@ -64,7 +66,7 @@ export class FileResourcesController {
@Body('chunks_number') chunksNumber: string,
@Body('file_hash') fileHash: string,
) {
return this.resourcesService.cleanFileChunks(
return this.namespaceResourcesService.cleanFileChunks(
namespaceId,
chunksNumber,
fileHash,
Expand All @@ -81,7 +83,7 @@ export class FileResourcesController {
@Body('mimetype') mimetype: string,
@Body('parent_id') parentId: string,
) {
const newResource = await this.resourcesService.mergeFileChunks(
const newResource = await this.namespaceResourcesService.mergeFileChunks(
req.user!.id,
namespaceId,
totalChunks,
Expand All @@ -90,7 +92,7 @@ export class FileResourcesController {
mimetype,
parentId,
);
return await this.resourcesService.getPath({
return await this.namespaceResourcesService.getPath({
namespaceId,
userId: req.user!.id,
resourceId: newResource.id,
Expand All @@ -105,7 +107,7 @@ export class FileResourcesController {
@Body('namespace_id') namespaceId: string,
@Body('resource_id') resourceId: string,
) {
return this.resourcesService.uploadFile(
return this.namespaceResourcesService.uploadFile(
userId,
namespaceId,
file,
Expand All @@ -119,6 +121,6 @@ export class FileResourcesController {
@Param('resourceId') resourceId: string,
@Res() res: Response,
) {
return await this.resourcesService.fileResponse(resourceId, res);
return await this.namespaceResourcesService.fileResponse(resourceId, res);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Response } from 'express';
import { Controller, Get, Param, Res } from '@nestjs/common';
import { ResourcesService } from 'omniboxd/resources/resources.service';
import { NamespaceResourcesService } from 'omniboxd/namespace-resources/namespace-resources.service';
import { Public } from 'omniboxd/auth/decorators/public.auth.decorator';

@Controller('internal/api/v1/resources')
export class InternalResourcesController {
constructor(private readonly resourcesService: ResourcesService) {}
constructor(
private readonly namespaceResourcesService: NamespaceResourcesService,
) {}

@Public()
@Get('files/:id')
async downloadFile(@Param('id') resourceId: string, @Res() res: Response) {
return await this.resourcesService.fileResponse(resourceId, res);
return await this.namespaceResourcesService.fileResponse(resourceId, res);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ResourcesService } from 'omniboxd/resources/resources.service';
import { CreateResourceDto } from 'omniboxd/resources/dto/create-resource.dto';
import { UpdateResourceDto } from 'omniboxd/resources/dto/update-resource.dto';
import { NamespaceResourcesService } from 'omniboxd/namespace-resources/namespace-resources.service';
import { CreateResourceDto } from 'omniboxd/namespace-resources/dto/create-resource.dto';
import { UpdateResourceDto } from 'omniboxd/namespace-resources/dto/update-resource.dto';
import { PermissionsService } from 'omniboxd/permissions/permissions.service';
import { ResourcePermission } from 'omniboxd/permissions/resource-permission.enum';
import {
Expand All @@ -17,12 +17,12 @@ import {
} from '@nestjs/common';
import { UserId } from 'omniboxd/decorators/user-id.decorator';
import { Request } from 'express';
import { ResourceMetaDto } from 'omniboxd/resources/dto/resource.dto';
import { ResourceMetaDto } from 'omniboxd/namespace-resources/dto/resource.dto';

@Controller('api/v1/namespaces/:namespaceId/resources')
export class ResourcesController {
export class NamespaceResourcesController {
constructor(
private readonly resourcesService: ResourcesService,
private readonly namespaceResourcesService: NamespaceResourcesService,
private readonly permissionsService: PermissionsService,
) {}

Expand All @@ -38,13 +38,16 @@ export class ResourcesController {
if (ids.length <= 0) {
return [];
}
return await this.resourcesService.findByIds(namespaceId, ids);
return await this.namespaceResourcesService.findByIds(namespaceId, ids);
}

@Post()
async create(@UserId() userId: string, @Body() data: CreateResourceDto) {
const newResource = await this.resourcesService.create(userId, data);
return await this.resourcesService.getPath({
const newResource = await this.namespaceResourcesService.create(
userId,
data,
);
return await this.namespaceResourcesService.getPath({
namespaceId: data.namespaceId,
resourceId: newResource.id,
userId: userId,
Expand All @@ -57,11 +60,11 @@ export class ResourcesController {
@Param('namespaceId') namespaceId: string,
@Param('resourceId') resourceId: string,
) {
const newResource = await this.resourcesService.duplicate(
const newResource = await this.namespaceResourcesService.duplicate(
req.user!.id,
resourceId,
);
return await this.resourcesService.getPath({
return await this.namespaceResourcesService.getPath({
namespaceId,
userId: req.user!.id,
resourceId: newResource.id,
Expand All @@ -75,7 +78,7 @@ export class ResourcesController {
@Query('parentId') parentId: string,
@Query('tags') tags: string,
) {
return await this.resourcesService.query(
return await this.namespaceResourcesService.query(
namespaceId,
parentId,
req.user!.id,
Expand All @@ -89,7 +92,11 @@ export class ResourcesController {
@Param('namespaceId') namespaceId: string,
@Param('resourceId') resourceId: string,
): Promise<ResourceMetaDto[]> {
return this.resourcesService.listChildren(namespaceId, resourceId, userId);
return this.namespaceResourcesService.listChildren(
namespaceId,
resourceId,
userId,
);
}

@Post(':resourceId/move/:targetId')
Expand All @@ -99,7 +106,7 @@ export class ResourcesController {
@Param('resourceId') resourceId: string,
@Param('targetId') targetId: string,
) {
return await this.resourcesService.move({
return await this.namespaceResourcesService.move({
userId: req.user!.id,
namespaceId,
resourceId,
Expand All @@ -114,7 +121,7 @@ export class ResourcesController {
@Query('exclude_resource_id') excludeResourceId: string | undefined,
@Query('name') name: string | undefined,
): Promise<ResourceMetaDto[]> {
return await this.resourcesService.search({
return await this.namespaceResourcesService.search({
namespaceId,
excludeResourceId,
name,
Expand All @@ -128,7 +135,7 @@ export class ResourcesController {
@Param('namespaceId') namespaceId: string,
@Param('resourceId') resourceId: string,
) {
return await this.resourcesService.getPath({
return await this.namespaceResourcesService.getPath({
namespaceId,
resourceId,
userId: req.user!.id,
Expand All @@ -151,8 +158,8 @@ export class ResourcesController {
if (!hasPermission) {
throw new ForbiddenException('Not authorized');
}
await this.resourcesService.update(req.user!.id, resourceId, data);
return await this.resourcesService.getPath({
await this.namespaceResourcesService.update(req.user!.id, resourceId, data);
return await this.namespaceResourcesService.getPath({
namespaceId,
resourceId,
userId: req.user!.id,
Expand All @@ -174,7 +181,10 @@ export class ResourcesController {
if (!hasPermission) {
throw new ForbiddenException('Not authorized');
}
return await this.resourcesService.delete(req.user!.id, resourceId);
return await this.namespaceResourcesService.delete(
req.user!.id,
resourceId,
);
}

@Post(':resourceId/restore')
Expand All @@ -183,8 +193,8 @@ export class ResourcesController {
@Param('namespaceId') namespaceId: string,
@Param('resourceId') resourceId: string,
) {
await this.resourcesService.restore(req.user!.id, resourceId);
return await this.resourcesService.getPath({
await this.namespaceResourcesService.restore(req.user!.id, resourceId);
return await this.namespaceResourcesService.getPath({
namespaceId,
resourceId,
userId: req.user!.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestClient } from 'test/test-client';
import { HttpStatus } from '@nestjs/common';
import { ResourceType } from 'omniboxd/resources/resources.entity';
import { ResourceType } from 'omniboxd/resources/entities/resource.entity';

describe('ResourcesController (e2e)', () => {
let client: TestClient;
Expand Down Expand Up @@ -399,7 +399,7 @@ describe('ResourcesController (e2e)', () => {
`/api/v1/namespaces/${client.namespace.id}/resources/non-existent-id`,
)
.send(updateData)
.expect(HttpStatus.FORBIDDEN);
.expect(HttpStatus.NOT_FOUND);
});

it('should fail with missing namespaceId', async () => {
Expand Down Expand Up @@ -458,7 +458,7 @@ describe('ResourcesController (e2e)', () => {
.delete(
`/api/v1/namespaces/${client.namespace.id}/resources/non-existent-id`,
)
.expect(HttpStatus.FORBIDDEN);
.expect(HttpStatus.NOT_FOUND);
});
});

Expand Down Expand Up @@ -774,7 +774,7 @@ describe('ResourcesController (e2e)', () => {
.post(
`/api/v1/namespaces/${client.namespace.id}/resources/non-existent-source/move/${targetFolderId}`,
)
.expect(HttpStatus.FORBIDDEN);
.expect(HttpStatus.NOT_FOUND);
});

it('should fail with non-existent target resource', async () => {
Expand Down Expand Up @@ -946,7 +946,7 @@ describe('ResourcesController (e2e)', () => {
.post(
`/api/v1/namespaces/${client.namespace.id}/resources/non-existent-id/restore`,
)
.expect(HttpStatus.INTERNAL_SERVER_ERROR);
.expect(HttpStatus.NOT_FOUND);
});
});

Expand Down
Loading