Skip to content

Commit

Permalink
Restrict pages (#189)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update .github/workflows/build-push-action.yml

Co-authored-by: Samuel Jones <[email protected]>

* Update .github/workflows/build-push-action.yml

Co-authored-by: Samuel Jones <[email protected]>

---------

Co-authored-by: Samuel Jones <[email protected]>
  • Loading branch information
keiranjprice101 and Pasarus authored Jul 1, 2024
1 parent 4c790a0 commit 3ceb537
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-push-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions container/frontend.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .

Expand Down
4 changes: 4 additions & 0 deletions container/scigateway.dockerfile
Original file line number Diff line number Diff line change
@@ -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


6 changes: 3 additions & 3 deletions container/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "a cool title",
"title": "fia",
"logo": "",
"navigationDrawerLogo": {
"light": "",
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 9 additions & 6 deletions src/ReductionHistory.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,8 +12,8 @@ import {
Icon,
IconButton,
InputLabel,
Paper,
MenuItem,
Paper,
Select,
SelectChangeEvent,
Table,
Expand Down Expand Up @@ -104,9 +104,13 @@ const ReductionHistory: React.FC = () => {

const fetchReductions = useCallback(async (): Promise<void> => {
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) {
Expand Down Expand Up @@ -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 => {
Expand Down
7 changes: 5 additions & 2 deletions src/ValueEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ const ValueEditor: React.FC = () => {
const fiaApiUrl = process.env.REACT_APP_FIA_REST_API_URL;

const fetchReduction = useCallback(async (): Promise<void> => {
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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ceb537

Please sign in to comment.