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
19 changes: 11 additions & 8 deletions src/modules/workspace/controllers/testflow.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class TestflowController {
* @description This will retrieve a specific Testflow using its ID,
* returning the Testflow object if found.
*/
@Get("testflow/:testflowId")
@Get(":workspaceId/testflow/:testflowId")
@ApiOperation({
summary: "Get Individual Testflow",
description: "This will get individual testflow of a workspace",
Expand All @@ -121,10 +121,13 @@ export class TestflowController {
})
@ApiResponse({ status: 400, description: "Fetch Testflow Request Failed" })
async getTestflow(
@Param("workspaceId") workspaceId: string,
@Param("testflowId") testflowId: string,
@Res() res: FastifyReply,
@Req() request: ExtendedFastifyRequest,
) {
const testflow = await this.testflowService.getTestflow(testflowId);
const user = request.user;
const testflow = await this.testflowService.getTestflow(workspaceId, testflowId, user._id);
const responseData = new ApiResponseService(
"Success",
HttpStatusCode.OK,
Expand Down Expand Up @@ -321,8 +324,8 @@ export class TestflowController {
const response = await this.testflowService.createTestflowSchedular(
createTestflowSchedularDto,
user,
);
const testflow = await this.testflowService.getTestflow(createTestflowSchedularDto.testflowId);
);
const testflow = await this.testflowService.getTestflow(createTestflowSchedularDto.workspaceId, createTestflowSchedularDto.testflowId, user._id);
const result = {
testflow,
schedule:response
Expand Down Expand Up @@ -359,7 +362,7 @@ export class TestflowController {
workspaceId,
user,
);
const testflow = await this.testflowService.getTestflow(testflowId);
const testflow = await this.testflowService.getTestflow(workspaceId, testflowId, user._id);
const responseData = new ApiResponseService(
"Success",
HttpStatusCode.OK,
Expand Down Expand Up @@ -390,7 +393,7 @@ export class TestflowController {
workspaceId,
user,
);
const testflow = await this.testflowService.getTestflow(testflowId);
const testflow = await this.testflowService.getTestflow(workspaceId, testflowId, user._id);
const responseData = new ApiResponseService(
"Success",
HttpStatusCode.OK,
Expand Down Expand Up @@ -421,7 +424,7 @@ export class TestflowController {
workspaceId,
user,
);
const testflow = await this.testflowService.getTestflow(testflowId);
const testflow = await this.testflowService.getTestflow(workspaceId, testflowId, user._id);
const responseData = new ApiResponseService(
"Success",
HttpStatusCode.OK,
Expand All @@ -448,7 +451,7 @@ export class TestflowController {
) {
const user = request.user;
await this.testflowService.deleteScheduleRunHistory(workspaceId, testflowId, scheduleId, runHistoryId, user);
const testflow = await this.testflowService.getTestflow(testflowId);
const testflow = await this.testflowService.getTestflow(workspaceId, testflowId, user._id);
const responseData = new ApiResponseService(
"Success",
HttpStatusCode.OK,
Expand Down
29 changes: 7 additions & 22 deletions src/modules/workspace/services/testflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ export class TestflowService implements OnModuleInit {
* Fetches single testflow.
* @param id - Testflow id you want to fetch.
*/
async getTestflow(id: string): Promise<WithId<Testflow>> {
return await this.testflowRepository.get(id);
async getTestflow(workspaceId: string, testflowId: string, userId: ObjectId): Promise<WithId<Testflow>> {
await this.checkPermission(workspaceId, userId);
return await this.testflowRepository.get(testflowId);
}

/**
Expand All @@ -341,6 +342,9 @@ export class TestflowService implements OnModuleInit {
*/
async checkPermission(workspaceId: string, userid: ObjectId): Promise<void> {
const workspace = await this.workspaceService.get(workspaceId);
if(workspace.workspaceType === WorkspaceType.PUBLIC){
return;
}
const hasPermission = workspace.users.some((user) => {
return user.id.toString() === userid.toString();
});
Expand Down Expand Up @@ -502,26 +506,7 @@ export class TestflowService implements OnModuleInit {
user: DecodedUserObject,
) {
try {
const workspaceUsers = await this.workspaceReposistory.get(
schedularData?.workspaceId,
);
if (!workspaceUsers) {
throw new NotFoundException("Workspace not found.");
}
const userDetails = workspaceUsers.users.find(
(item) => item.id === user._id.toString(),
);
if (!userDetails) {
throw new NotFoundException("User not found in workspace.");
}
if (
userDetails.role !== WorkspaceRole.ADMIN &&
userDetails.role !== WorkspaceRole.EDITOR
) {
throw new ForbiddenException(
"User does not have permission to perform this action.",
);
}
await this.isWorkspaceAdminorEditor(schedularData?.workspaceId, user._id);
// Build cron config
const runCycleConfig = this.buildRunCycleConfig(
schedularData.runConfiguration,
Expand Down
Loading