From 3ceb53746c0c3bd79c2d4cf6908a312e5ad506d9 Mon Sep 17 00:00:00 2001 From: keiranjprice101 <44777678+keiranjprice101@users.noreply.github.com> Date: Mon, 1 Jul 2024 09:11:36 +0100 Subject: [PATCH] Restrict pages (#189) * Restrict pages * Temporarily build on every push * Add auth provider to settings.json * Derestrict single page * Derestrict single page * Derestrict single page * test * attach token * inline filename * Call correct method * update dockerfile * Revert build push * Update src/index.tsx Co-authored-by: Samuel Jones * Update .github/workflows/build-push-action.yml Co-authored-by: Samuel Jones * Update .github/workflows/build-push-action.yml Co-authored-by: Samuel Jones --------- Co-authored-by: Samuel Jones --- .github/workflows/build-push-action.yml | 4 ++-- container/frontend.dockerfile | 1 + container/scigateway.dockerfile | 4 ++++ container/settings.json | 6 +++--- src/ReductionHistory.tsx | 15 +++++++++------ src/ValueEditor.tsx | 7 +++++-- src/index.tsx | 6 +++--- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-push-action.yml b/.github/workflows/build-push-action.yml index 7d211e0..5fc67b1 100644 --- a/.github/workflows/build-push-action.yml +++ b/.github/workflows/build-push-action.yml @@ -34,7 +34,7 @@ jobs: with: file: ./container/frontend.dockerfile push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/frontend:${{ github.sha }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/frontend${{ github.sha }} - name: Build and push scigateway Docker image uses: docker/build-push-action@v6 @@ -43,7 +43,7 @@ jobs: context: ./container file: ./container/scigateway.dockerfile push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/scigateway:${{ github.sha }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/scigateway${{ github.sha }} - name: Checkout the Gitops repository uses: actions/checkout@v4 diff --git a/container/frontend.dockerfile b/container/frontend.dockerfile index 3c60e93..74b2dba 100644 --- a/container/frontend.dockerfile +++ b/container/frontend.dockerfile @@ -4,6 +4,7 @@ FROM node:lts-alpine3.19@sha256:ec0c413b1d84f3f7f67ec986ba885930c57b5318d2eb3abc WORKDIR /app ENV REACT_APP_FIA_REST_API_URL="/api" +ENV REACT_APP_FIA_DATA_VIEWER_URL="/data-viewer" COPY . . diff --git a/container/scigateway.dockerfile b/container/scigateway.dockerfile index 88b8fb4..d61e727 100644 --- a/container/scigateway.dockerfile +++ b/container/scigateway.dockerfile @@ -1,6 +1,10 @@ FROM harbor.stfc.ac.uk/datagateway/scigateway:develop +ENV AUTH_URL /auth +ENV AUTH_PROVIDER jwt + WORKDIR /usr/local/apache2/htdocs COPY --chown=www-data:www-data settings.json ./settings.json COPY --chown=www-data:www-data default.json ./res/default.json + diff --git a/container/settings.json b/container/settings.json index a59dc88..81a0b23 100644 --- a/container/settings.json +++ b/container/settings.json @@ -1,5 +1,5 @@ { - "title": "a cool title", + "title": "fia", "logo": "", "navigationDrawerLogo": { "light": "", @@ -54,8 +54,8 @@ "content": "Click here to open or close the navigation menu" } ], - "auth-provider": null, - "authUrl": "", + "auth-provider": "jwt", + "authUrl": "/auth", "ui-strings": "res/default.json", "autoLogin": true, "ga-tracking-id": "UA-XXXX-Y", diff --git a/src/ReductionHistory.tsx b/src/ReductionHistory.tsx index 5ef1ee7..8985f6e 100644 --- a/src/ReductionHistory.tsx +++ b/src/ReductionHistory.tsx @@ -1,6 +1,6 @@ // React components -import React, { useState, useEffect, useCallback } from 'react'; -import { useParams, useHistory } from 'react-router-dom'; +import React, { useCallback, useEffect, useState } from 'react'; +import { useHistory, useParams } from 'react-router-dom'; // Material UI components import { @@ -12,8 +12,8 @@ import { Icon, IconButton, InputLabel, - Paper, MenuItem, + Paper, Select, SelectChangeEvent, Table, @@ -104,9 +104,13 @@ const ReductionHistory: React.FC = () => { const fetchReductions = useCallback(async (): Promise => { try { + const token = localStorage.getItem('scigateway:token'); const offset = currentPage * rowsPerPage; const query = `limit=${rowsPerPage}&offset=${offset}&order_by=${orderBy}&order_direction=${orderDirection}&include_runs=true`; - const response = await fetch(`${fiaApiUrl}/instrument/${selectedInstrument}/reductions?${query}`); + const response = await fetch(`${fiaApiUrl}/instrument/${selectedInstrument}/reductions?${query}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }, + }); const data = await response.json(); setReductions(data); } catch (error) { @@ -284,8 +288,7 @@ function Row({ reduction, index }: { reduction: Reduction; index: number }): JSX if (typeof fileNameWithExtension === 'undefined') { return ''; } - const fileName = fileNameWithExtension.split('.')[0]; - return fileName; + return fileNameWithExtension.split('.')[0]; }; const parseReductionOutputs = (): JSX.Element | JSX.Element[] | undefined => { diff --git a/src/ValueEditor.tsx b/src/ValueEditor.tsx index 0f2437b..54357f8 100644 --- a/src/ValueEditor.tsx +++ b/src/ValueEditor.tsx @@ -41,11 +41,14 @@ const ValueEditor: React.FC = () => { const fiaApiUrl = process.env.REACT_APP_FIA_REST_API_URL; const fetchReduction = useCallback(async (): Promise => { + const token = localStorage.getItem('scigateway:token'); try { setLoading(true); - const response = await fetch(`${fiaApiUrl}/reduction/${reductionId}`); + const response = await fetch(`${fiaApiUrl}/reduction/${reductionId}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }, + }); const data = await response.json(); - console.log('Fetching reduction', data); if (data && data.script && data.script.value) { setScriptValue(data.script.value); } diff --git a/src/index.tsx b/src/index.tsx index 3e7fba4..04333a6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -62,10 +62,10 @@ createRoute( '/fia', // route the link should link to 1, // how high up in the section should your link be - ascending order 'Data help text', // help text renders a tooltip in the site tour for this link - true // whether the link should be visible to unauthenticated users + false // whether the link should be visible to unauthenticated users ); -createRoute('Reductions', 'Instruments', '/fia/instruments', 2, 'Data help text', true); -createRoute('Reductions', 'Reduction history', '/fia/reduction-history/MARI', 3, 'Data help text', true); +createRoute('Reductions', 'Instruments', '/fia/instruments', 2, 'Data help text', false); +createRoute('Reductions', 'Reduction history', '/fia/reduction-history/MARI', 3, 'Data help text', false); // Single-SPA bootstrap methods have no idea what type of inputs may be // pushed down from the parent app