diff --git a/config/config.json b/config/config.json index eb9ad3c..a685353 100644 --- a/config/config.json +++ b/config/config.json @@ -13,5 +13,7 @@ "graylogEnabled": false, "graylogServer": "it-graylog.esss.lu.se", "graylogPort": 12201, - "environment": "development" + "environment": "development", + "basePath": "", + "accessToken": "" } diff --git a/package.json b/package.json index 629821d..8db5f82 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "cookie-parser": "~1.4.6", "cors": "^2.8.5", "debug": "~2.6.9", - "dotenv": "^16.4.5", "ejs": "^3.1.8", "express": "~4.19.2", "express-fileupload": "^1.4.0", diff --git a/src/app.ts b/src/app.ts index 44dc9b1..cbd0930 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,7 +13,6 @@ import { router as indexRouter } from "./routes/index"; import { router as uploadRouter } from "./routes/upload"; import { logger } from "@user-office-software/duo-logger"; import { configureLogger } from "./common/configureLogger"; -import 'dotenv/config' const app = express(); app.set("views", path.join(__dirname, "views")); diff --git a/src/auth.ts b/src/auth.ts index baf76ca..5f3f6c4 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -94,15 +94,19 @@ export const hasFileAccess = async ( const valid = await dataSetAPI.datasetsControllerFindById({pid: authRequest.dataset}).then( (value) => { - if(value.isPublished || value.accessGroups.some(item => new Set(authRequest.jwt.groups).has(item)) || authRequest.jwt.groups.indexOf(value.ownerGroup) > -1){ - return true - }else{ - false + if(value.isPublished || // Check if proposal is public + value.accessGroups.some(item => new Set(authRequest.jwt.groups).has(item)) || // Check if user has one or more of the access groups of dataset + authRequest.jwt.groups.indexOf(value.ownerGroup) > -1) //Check if user has the owner group + { + return true; } + + return false; + } ).catch((e) => { - return false + return false; }); return { diff --git a/src/common/scicatAPI.ts b/src/common/scicatAPI.ts index fe64ab9..e1777d1 100644 --- a/src/common/scicatAPI.ts +++ b/src/common/scicatAPI.ts @@ -1,18 +1,19 @@ import { Configuration, DatasetsApi } from "@scicatproject/scicat-ts-fetch-test"; +import { config } from "./config"; let datasetsApiInstance: DatasetsApi | null = null; export function scicatDataSetAPI(): DatasetsApi { + const { basePath, accessToken } = config; + if (!datasetsApiInstance) { - const basePath = process.env.SCICAT_API_BASE_PATH; - const accessToken = process.env.SCICAT_API_ACCESS_TOKEN; if (!basePath || !accessToken) { throw new Error("SciCat API configuration is missing: Check SCICAT_API_BASE_PATH and SCICAT_API_ACCESS_TOKEN."); } const apiConfig = new Configuration({ - basePath, + basePath , accessToken, });