Skip to content

Commit

Permalink
Merge pull request #1537 from ral-facilities/feature/mint-custom-data…
Browse files Browse the repository at this point in the history
…publications-#1529-#1531

Mint custom datapublications #1529 #1531
  • Loading branch information
louise-davies authored Jan 18, 2024
2 parents 3ce86a8 + ae1fb81 commit 10bb7d1
Show file tree
Hide file tree
Showing 36 changed files with 4,113 additions and 715 deletions.
13 changes: 13 additions & 0 deletions .github/add_doi_datapublicationtype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from icat.client import Client

client = Client(
"https://localhost:8181",
checkCert=False,
)
client.login("simple", {"username": "root", "password": "pw"})

data_publication_type = client.new("dataPublicationType")
data_publication_type.name = "User-defined"
data_publication_type.description = "User-defined"
data_publication_type.facility = client.get("Facility", 1)
data_publication_type.create()
18 changes: 18 additions & 0 deletions .github/config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ICAT_URL=https://host.docker.internal:8181
FACILITY=LILS
ICAT_USERNAME=root
ICAT_PASSWORD=pw
PUBLISHER=test
MINTER_ROLE=PI
VERSION=0.01

ICAT_DOI_BASE_URL=https://example.stfc.ac.uk/
ICAT_SESSION_PATH=/icat/session/
ICAT_AUTHENTICATOR_NAME=simple
ICAT_CHECK_CERT=False
SSL_CERT_VERIFICATION=False

DATACITE_PREFIX=10.5286
DATACITE_URL=https://api.test.datacite.org/dois
DATACITE_USERNAME=BL.STFC

35 changes: 33 additions & 2 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,21 @@ jobs:
ansible-playbook icat-ansible/icat_test_hosts.yml -i icat-ansible/hosts --vault-password-file icat-ansible/vault_pass.txt -vv
# Fixes on ICAT components needed for e2e tests
- name: Add anon user to rootUserNames
- name: Removing authenticator prefix for simple auth
run: |
awk -F" =" '/rootUserNames/{$2="= simple/root anon/anon";print;next}1' /home/runner/install/icat.server/run.properties > /home/runner/install/icat.server/run.properties.tmp
sed -i 's/mechanism = simple/!mechanism = simple/' /home/runner/install/authn.simple/run.properties
- name: Adding Chris481 user
run: |
sed -i '/user\.list/ s/$/ Chris481/' /home/runner/install/authn.simple/run.properties
- name: Adding Chris481 user password
run: |
echo "user.Chris481.password = pw" >> /home/runner/install/authn.simple/run.properties
- name: Reinstall authn.simple
run: |
cd /home/runner/install/authn.simple/ && ./setup -vv install
- name: Add anon, root (simple without prefix) and Chris481 users to rootUserNames
run: |
awk -F" =" '/rootUserNames/{$2="= root Chris481 anon/anon";print;next}1' /home/runner/install/icat.server/run.properties > /home/runner/install/icat.server/run.properties.tmp
- name: Apply rootUserNames change
run: |
mv -f /home/runner/install/icat.server/run.properties.tmp /home/runner/install/icat.server/run.properties
Expand All @@ -260,6 +272,15 @@ jobs:
- name: Reinstall IDS Server
run: |
cd /home/runner/install/ids.server/ && python2 ./setup -vv install
- name: Add root (simple without prefix) to datagateway-download-api adminUserNames
run: |
awk -F" =" '/adminUserNames/{$2="= root";print;next}1' /home/runner/install/datagateway-download-api/run.properties > /home/runner/install/datagateway-download-api/run.properties.tmp
- name: Apply adminUserNames change
run: |
mv -f /home/runner/install/datagateway-download-api/run.properties.tmp /home/runner/install/datagateway-download-api/run.properties
- name: Reinstall datagateway-download-api
run: |
cd /home/runner/install/datagateway-download-api/ && python2 ./setup -vv install
# Disable Globus for Download e2e tests
- name: Login to ICAT
Expand Down Expand Up @@ -299,6 +320,16 @@ jobs:
- name: Start API
run: cd datagateway-api/; nohup poetry run python -m datagateway_api.src.main > api-output.txt &

# DOI minter setup
- name: Adding 'User-defined' DataPublicationType (needed for DOI minting api)
run: cd datagateway-api/; poetry run python ../.github/add_doi_datapublicationtype.py

- name: 'Add password to env file'
run: echo DATACITE_PASSWORD=${{ secrets.DATACITE_PASSWORD }} >> ./.github/config.env

- name: Run minting api
run: docker run --env-file ./.github/config.env -p 8000:8000 --add-host host.docker.internal:host-gateway -d harbor.stfc.ac.uk/icat/doi-mint-api

# E2E tests
- name: Setup Node.js
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3
Expand Down
14 changes: 9 additions & 5 deletions packages/datagateway-common/src/api/cart.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks';
import axios from 'axios';
import axios, { AxiosError } from 'axios';
import { useCart, useAddToCart, useRemoveFromCart } from '.';
import { DownloadCart } from '../app.types';
import handleICATError from '../handleICATError';
Expand Down Expand Up @@ -122,9 +122,11 @@ describe('Cart api functions', () => {
it('sends axios request to add item to cart once mutate function is called and calls handleICATError on failure, with a retry on code 431', async () => {
(axios.post as jest.MockedFunction<typeof axios.post>)
.mockRejectedValueOnce({
code: '431',
response: {
status: 431,
},
message: 'Test 431 error message',
})
} as AxiosError)
.mockRejectedValue({
message: 'Test error message',
});
Expand Down Expand Up @@ -184,9 +186,11 @@ describe('Cart api functions', () => {
it('sends axios request to remove item from cart once mutate function is called and calls handleICATError on failure, with a retry on code 431', async () => {
(axios.post as jest.MockedFunction<typeof axios.post>)
.mockRejectedValueOnce({
code: '431',
response: {
status: 431,
},
message: 'Test 431 error message',
})
} as AxiosError)
.mockRejectedValue({
message: 'Test error message',
});
Expand Down
4 changes: 2 additions & 2 deletions packages/datagateway-common/src/api/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const useAddToCart = (
},
retry: (failureCount, error) => {
// if we get 431 we know this is an intermittent error so retry
if (error.code === '431' && failureCount < 3) {
if (error.response?.status === 431 && failureCount < 3) {
return true;
} else {
return false;
Expand Down Expand Up @@ -141,7 +141,7 @@ export const useRemoveFromCart = (
},
retry: (failureCount, error) => {
// if we get 431 we know this is an intermittent error so retry
if (error.code === '431' && failureCount < 3) {
if (error.response?.status === 431 && failureCount < 3) {
return true;
} else {
return false;
Expand Down
2 changes: 2 additions & 0 deletions packages/datagateway-common/src/app.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export interface User {
id: number;
name: string;
fullName?: string;
email?: string;
affiliation?: string;
}

export interface Sample {
Expand Down
35 changes: 14 additions & 21 deletions packages/datagateway-common/src/table/table.component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import TableCell from '@mui/material/TableCell';
import { styled, SxProps, Theme, useTheme } from '@mui/material/styles';
import { styled, SxProps } from '@mui/material/styles';
import {
AutoSizer,
Column,
Expand Down Expand Up @@ -31,6 +31,9 @@ const dataColumnMinWidth = 84;

const StyledTable = styled(Table)(({ theme }) => ({
fontFamily: theme.typography.fontFamily,
'.hoverable-row:hover': {
backgroundColor: theme.palette.action.hover,
},
}));

const flexContainerStyle = {
Expand All @@ -48,12 +51,10 @@ const headerFlexContainerStyle = {

const tableRowStyle = {};

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const getTableRowHoverStyle = (theme: Theme) => ({
'&:hover': {
backgroundColor: theme.palette.action.hover,
},
});
const tableRowStyleCombined = {
...tableRowStyle,
...flexContainerStyle,
};

const tableCellStyle = {
flex: 1,
Expand Down Expand Up @@ -140,7 +141,6 @@ const VirtualizedTable = React.memo(
const [expandedIndex, setExpandedIndex] = React.useState(-1);
const [detailPanelHeight, setDetailPanelHeight] = React.useState(rowHeight);
const [lastChecked, setLastChecked] = React.useState(-1);
const theme = useTheme();

let tableRef: Table | null = null;
const detailPanelRef = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -256,18 +256,10 @@ const VirtualizedTable = React.memo(
[detailPanelHeight, expandedIndex]
);

const getRowStyle = React.useCallback(
({ index }: Index): React.CSSProperties => {
const tableRowHoverStyle =
index > -1 ? getTableRowHoverStyle(theme) : {};
return {
...tableRowStyle,
...flexContainerStyle,
...tableRowHoverStyle,
};
},
[theme]
);
const getRowClassName = React.useCallback(({ index }: Index) => {
return index > -1 ? 'hoverable-row' : '';
}, []);

const getRow = React.useCallback(
({ index }: Index): Entity => data[index],
[data]
Expand Down Expand Up @@ -353,7 +345,8 @@ const VirtualizedTable = React.memo(
onRowsRendered={onRowsRendered}
headerHeight={headerHeight}
rowHeight={getRowHeight}
rowStyle={getRowStyle}
rowStyle={tableRowStyleCombined}
rowClassName={getRowClassName}
rowGetter={getRow}
rowRenderer={renderRow}
// Disable tab focus on whole table for accessibility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ describe('DLS - Datasets Cards', () => {
// check that count is correct after filtering
cy.get('[data-testid="card"]').first().contains('15');

cy.get('input[id="Create Time filter from"]').type('2019-01-01');
cy.wait(['@getDatasetsCount'], { timeout: 10000 });
cy.get('[data-testid="card"]').first().contains('DATASET 61');

cy.get('input[aria-label="Create Time filter to"]')
cy.get('input[aria-label="Start Date filter to"]')
.parent()
.find('button')
.click();
Expand All @@ -136,10 +132,16 @@ describe('DLS - Datasets Cards', () => {
date.setDate(1);
date.setMonth(0);
date.setFullYear(2020);
cy.get('input[id="Create Time filter to"]').should(
cy.get('input[id="Start Date filter to"]').should(
'have.value',
date.toISOString().slice(0, 10)
);
cy.wait(['@getDatasetsCount'], { timeout: 10000 });
cy.get('[data-testid="card"]').first().contains('DATASET 61');

cy.get('input[id="Start Date filter from"]').type('2019-01-01');
cy.wait(['@getDatasetsCount'], { timeout: 10000 });

cy.get('[data-testid="card"]').should('not.exist');
});
});
Loading

0 comments on commit 10bb7d1

Please sign in to comment.