Skip to content

Commit

Permalink
Merge pull request #148 from TaskarCenterAtUW/feature-spatial-join
Browse files Browse the repository at this point in the history
Feature spatial join
  • Loading branch information
MashB committed Jul 25, 2024
2 parents b3af577 + 9b33535 commit a2ac2e3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/controller/general-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextFunction, Request } from "express";
import express from "express";
import { IController } from "./interface/IController";
import HttpException from "../exceptions/http/http-base-exception";
import { FileTypeException, InputException, UnAuthenticated } from "../exceptions/http/http-exceptions";
import { FileTypeException, InputException } from "../exceptions/http/http-exceptions";
import { authenticate } from "../middleware/authenticate-middleware";
import { JobsQueryParams, TDEIDataType, TDEIRole } from "../model/jobs-get-query-params";
import jobService from "../service/job-service";
Expand All @@ -11,7 +11,6 @@ import { authorize } from "../middleware/authorize-middleware";
import { DatasetQueryParams } from "../model/dataset-get-query-params";
import multer, { memoryStorage } from "multer";
import path from "path";
import { Utility } from "../utility/utility";
import { IDatasetCloneRequest } from "../model/request-interfaces";


Expand Down
4 changes: 2 additions & 2 deletions src/controller/osw-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import express from "express";
import { IController } from "./interface/IController";
import oswService from "../service/osw-service";
import HttpException from "../exceptions/http/http-base-exception";
import { InputException, FileTypeException, UnAuthenticated } from "../exceptions/http/http-exceptions";
import { InputException, FileTypeException, UnAuthenticated, ForbiddenAccess } from "../exceptions/http/http-exceptions";
import { Versions } from "../model/versions-dto";
import { environment } from "../environment/environment";
import multer, { memoryStorage } from "multer";
Expand Down Expand Up @@ -210,7 +210,7 @@ class OSWController implements IController {
let osw = await tdeiCoreService.getDatasetDetailsById(requestService.target_dataset_id);
var authorized = await Utility.authorizeRoles(request.body.user_id, osw.tdei_project_group_id, ["tdei_admin", "poc", "osw_data_generator"]);
if (!authorized) {
return next(new UnAuthenticated());
return next(new ForbiddenAccess());
}

let backendRequest: TagRoadServiceRequest = {
Expand Down
6 changes: 6 additions & 0 deletions src/exceptions/http/http-exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export class UnAuthenticated extends HttpException {
}
}

export class ForbiddenAccess extends HttpException {
constructor() {
super(403, `User not authorized to perform this action.`);
}
}

export class ForeignKeyException extends HttpException {
constructor(name: string) {
super(400, `No reference found for the constraint '${name}' in the system.`);
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/authorize-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { Request, Response, NextFunction } from 'express';
import { UnAuthenticated } from '../exceptions/http/http-exceptions';
import { ForbiddenAccess, UnAuthenticated } from '../exceptions/http/http-exceptions';
import HttpException from '../exceptions/http/http-base-exception';
import tdeiCoreService from '../service/tdei-core-service';
import { Utility } from '../utility/utility';
Expand Down Expand Up @@ -56,7 +56,7 @@ export const authorize = (approvedRoles: string[]) => {
next();
}
else {
next(new UnAuthenticated());
next(new ForbiddenAccess());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/service/osw-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class OswService implements IOswService {
tdei_dataset_id: tdei_dataset_id,
trigger_type: 'manual'
},
tdei_project_group_id: dataset.tdei_project_group_id,
tdei_project_group_id: '',
user_id: user_id,
});

Expand Down Expand Up @@ -1004,7 +1004,7 @@ class OswService implements IOswService {
algorithms: algorithms,
persist: persist
},
tdei_project_group_id: dataset.tdei_project_group_id,
tdei_project_group_id: '',
user_id: user_id
})
const job_id = await this.jobServiceInstance.createJob(job);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/middleware/authorize-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getMockReq, getMockRes } from "@jest-mock/express"
import { UnAuthenticated } from "../../../src/exceptions/http/http-exceptions"
import { ForbiddenAccess, UnAuthenticated } from "../../../src/exceptions/http/http-exceptions"
import { mockCoreAuth } from "../../common/mock-utils";
import { authorize } from "../../../src/middleware/authorize-middleware";
import tdeiCoreService from "../../../src/service/tdei-core-service";
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('Authorize Middleware', () => {
expect(next).toHaveBeenCalledWith();
});

it('should call next() with UnAuthenticated error if roles are not approved', async () => {
it('should call next() with forbidden error if roles are not approved', async () => {
const req = getMockReq()
const { res, next } = getMockRes();
req.body.user_id = 'someUserId';
Expand All @@ -61,6 +61,6 @@ describe('Authorize Middleware', () => {

await authorize(['approvedRole1', 'approvedRole2'])(req, res, next);

expect(next).toHaveBeenCalledWith(new UnAuthenticated());
expect(next).toHaveBeenCalledWith(new ForbiddenAccess());
});
});
6 changes: 3 additions & 3 deletions test/unit/osw.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import oswController from "../../src/controller/osw-controller";
import oswService from "../../src/service/osw-service";
import { getMockReq, getMockRes } from "@jest-mock/express";
import HttpException from "../../src/exceptions/http/http-base-exception";
import { InputException, UnAuthenticated } from "../../src/exceptions/http/http-exceptions";
import { ForbiddenAccess, InputException, UnAuthenticated } from "../../src/exceptions/http/http-exceptions";
import tdeiCoreService from "../../src/service/tdei-core-service";
import { Utility } from "../../src/utility/utility";

Expand Down Expand Up @@ -201,7 +201,7 @@ describe("OSW Controller Test", () => {
expect(next).toHaveBeenCalledWith(inputException);
});

test("When user is not authorized, Expect to return HTTP status 401", async () => {
test("When user is not authorized, Expect to return HTTP status 403", async () => {
// Arrange
const req = getMockReq({
query: {
Expand All @@ -215,7 +215,7 @@ describe("OSW Controller Test", () => {
const { res, next } = getMockRes();
jest.spyOn(tdeiCoreService, "getDatasetDetailsById").mockResolvedValueOnce({ tdei_project_group_id: "mock-project-group-id" } as any);
jest.spyOn(Utility, "authorizeRoles").mockResolvedValueOnce(false);
const unauthenticatedException = new UnAuthenticated();
const unauthenticatedException = new ForbiddenAccess();
jest.spyOn(oswService, "processDatasetTagRoadRequest").mockRejectedValueOnce(unauthenticatedException);

// Act
Expand Down

0 comments on commit a2ac2e3

Please sign in to comment.