Skip to content

Commit

Permalink
Clean up code, remove dotenv and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bolmsten committed Dec 3, 2024
1 parent c83c931 commit ae4c4d6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
4 changes: 3 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"graylogEnabled": false,
"graylogServer": "it-graylog.esss.lu.se",
"graylogPort": 12201,
"environment": "development"
"environment": "development",
"basePath": "",
"accessToken": ""
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
14 changes: 9 additions & 5 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions src/common/scicatAPI.ts
Original file line number Diff line number Diff line change
@@ -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,
});

Expand Down

0 comments on commit ae4c4d6

Please sign in to comment.