From 50e52732439c53176be416e5f359560e01e328bd Mon Sep 17 00:00:00 2001 From: learner97 Date: Tue, 7 May 2024 14:53:28 -0600 Subject: [PATCH 1/4] changed setup test to include althome --- tests/first_time_setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/first_time_setup.py b/tests/first_time_setup.py index 8c1ef9b8..d3748b7c 100644 --- a/tests/first_time_setup.py +++ b/tests/first_time_setup.py @@ -29,6 +29,7 @@ def test_post(self): 'frontendURL': 'http://localhost:3333', 'instanceUrl': 'http://localhost:7777/', 'uriPrefix': 'https://synbiohub.org/', + 'altHome': 'http://testHomepage.org/', 'color': '#D25627', 'frontPageText': 'text', 'virtuosoINI': '/etc/virtuoso-opensource-7/virtuoso.ini', From ac9f40e6457e55a433ec14556e4bc0f2d0e761c3 Mon Sep 17 00:00:00 2001 From: learner97 Date: Thu, 9 May 2024 11:29:52 -0600 Subject: [PATCH 2/4] added althome setup to navbar --- frontend/components/Admin/Theme.js | 18 ++++++++++++++++-- frontend/components/Navbar/Navbar.js | 8 +++++++- frontend/public/commitHash.txt | 2 +- frontend/specialAccess/setup.js | 16 +++++++++++----- tests/first_time_setup.py | 2 -- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/frontend/components/Admin/Theme.js b/frontend/components/Admin/Theme.js index 73888393..001f140a 100644 --- a/frontend/components/Admin/Theme.js +++ b/frontend/components/Admin/Theme.js @@ -10,6 +10,7 @@ import { useState } from 'react'; import Loader from 'react-loader-spinner'; import { useEffect } from 'react'; import { useSelector } from 'react-redux'; +import { isValidURI } from '../Viewing/Shell'; const { publicRuntimeConfig } = getConfig(); export default function Theme() { @@ -17,6 +18,7 @@ export default function Theme() { const { theme, loading } = useTheme(dispatch); const [instanceName, setInstanceName] = useState(''); // default to empty const [frontPageText, setFrontPageText] = useState(''); // default to empty + const [altHome, setAltHome] = useState(''); const [baseColor, setBaseColor] = useState(''); const [logoFile, setLogoFile] = useState(null); const [showModuleInteractions, setShowModuleInteractions] = useState(true); @@ -27,6 +29,7 @@ export default function Theme() { if (theme) { setInstanceName(theme.instanceName); setFrontPageText(theme.frontPageText); + setAltHome(theme.altHome); } }, [theme]); @@ -57,16 +60,20 @@ export default function Theme() { 'X-authorization': token }; + if (altHome !== '' && !isValidURI(altHome)) { + alert('Alternate Home Page must be empty or contain a valid URL.'); + return; // Prevent form submission + } + const formData = new FormData(); formData.append('instanceName', instanceName); formData.append('frontPageText', frontPageText); + formData.append('altHome', altHome); formData.append('baseColor', baseColor); if (logoFile) { formData.append('logo', logoFile); } - console.log('this is a test'); - try { const response = await fetch(url, { method: 'POST', headers: headers, body: formData }); const data = await response.text(); @@ -116,6 +123,13 @@ export default function Theme() { rows={10} // Number of rows cols={100} // Number of columns /> +
Alternate Home Page
+ setAltHome(e.target.value)} + style={{ width: '600px' }} + />
Color Settings
diff --git a/frontend/components/Navbar/Navbar.js b/frontend/components/Navbar/Navbar.js index b4b530f6..3c4e6441 100644 --- a/frontend/components/Navbar/Navbar.js +++ b/frontend/components/Navbar/Navbar.js @@ -37,13 +37,19 @@ export default function Navbar() { ); }, [loggedIn]); + console.log(theme); + let linkHref = "/"; + if (theme && theme.altHome && theme.altHome.length > 0) { + linkHref = theme.altHome; + } + return (
{/* This is your new div container */} - + {/* */} diff --git a/frontend/public/commitHash.txt b/frontend/public/commitHash.txt index 1b08bb50..8aa66915 100644 --- a/frontend/public/commitHash.txt +++ b/frontend/public/commitHash.txt @@ -1 +1 @@ -f6f9da07901a90dad77c15690464facfc1fa8e67 \ No newline at end of file +50e52732439c53176be416e5f359560e01e328bd \ No newline at end of file diff --git a/frontend/specialAccess/setup.js b/frontend/specialAccess/setup.js index 8620c36d..f7e4c1b7 100644 --- a/frontend/specialAccess/setup.js +++ b/frontend/specialAccess/setup.js @@ -9,6 +9,7 @@ import SubmitLabel from '../components/Submit/ReusableComponents/SubmitLabel'; import getConfig from 'next/config'; import { useDispatch } from 'react-redux'; import { addError } from '../redux/actions'; +import { isValidURI } from '../components/Viewing/Shell'; import axios from 'axios'; const { publicRuntimeConfig } = getConfig(); @@ -139,13 +140,14 @@ export default function Setup({ setInSetupMode }) { /> setAltHome(event.target.value)} inputName="Alternate Home Page" containerStyling={styles.inputcontainer} /> +
} /> @@ -221,6 +223,10 @@ export default function Setup({ setInSetupMode }) { 'Content-Type': 'application/json', Accept: 'text/plain' }; + if (altHome !== '' && !isValidURI(altHome)) { + setErrors(['Alternate Home Page must either be empty or contain a valid URL.']); + return; // Prevent the submission + } try { await axios.post( `${publicRuntimeConfig.backend}/setup`, @@ -240,18 +246,18 @@ export default function Setup({ setInSetupMode }) { virtuosoINI: '/etc/virtuoso-opensource-7/virtuoso.ini', virtuosoDB: '/var/lib/virtuoso-opensource-7/db', allowPublicSignup, - altHome + altHome, // This can now be either a valid URL or an empty string }, { - headers + headers, } ); setErrors([]); setInSetupMode(false); } catch (error) { - if (error.response.status === 400) { + if (error.response?.status === 400) { const errorMessages = error.response.data.details.map( - error => error.message + (err) => err.message ); setErrors(errorMessages); return; diff --git a/tests/first_time_setup.py b/tests/first_time_setup.py index d3748b7c..7dafe891 100644 --- a/tests/first_time_setup.py +++ b/tests/first_time_setup.py @@ -26,10 +26,8 @@ def test_post(self): 'userPassword': 'test', 'userPasswordConfirm': 'test', 'instanceName': 'Test Synbiohub', - 'frontendURL': 'http://localhost:3333', 'instanceUrl': 'http://localhost:7777/', 'uriPrefix': 'https://synbiohub.org/', - 'altHome': 'http://testHomepage.org/', 'color': '#D25627', 'frontPageText': 'text', 'virtuosoINI': '/etc/virtuoso-opensource-7/virtuoso.ini', From d0b75e4ea8e7260cb4feb94089cbba74ee3971e5 Mon Sep 17 00:00:00 2001 From: learner97 Date: Thu, 9 May 2024 11:31:29 -0600 Subject: [PATCH 3/4] added althome to search navbar as well --- frontend/components/Search/NavbarSearch/NavbarSearch.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/components/Search/NavbarSearch/NavbarSearch.js b/frontend/components/Search/NavbarSearch/NavbarSearch.js index e31c7624..968f25ec 100644 --- a/frontend/components/Search/NavbarSearch/NavbarSearch.js +++ b/frontend/components/Search/NavbarSearch/NavbarSearch.js @@ -14,11 +14,16 @@ export default function NavbarSearch(properties) { const pageVisited = useSelector(state => state.tracking.pageVisited); const { theme, loading } = useTheme(); + let linkHref = "/"; + if (theme && theme.altHome && theme.altHome.length > 0) { + linkHref = theme.altHome; + } + return (
- + From 82bf46db168559d3860fd687e22e9d6eab072442 Mon Sep 17 00:00:00 2001 From: learner97 Date: Thu, 9 May 2024 11:53:44 -0600 Subject: [PATCH 4/4] added back frontend url to setup test for sbh2 --- tests/first_time_setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/first_time_setup.py b/tests/first_time_setup.py index 7dafe891..8c1ef9b8 100644 --- a/tests/first_time_setup.py +++ b/tests/first_time_setup.py @@ -26,6 +26,7 @@ def test_post(self): 'userPassword': 'test', 'userPasswordConfirm': 'test', 'instanceName': 'Test Synbiohub', + 'frontendURL': 'http://localhost:3333', 'instanceUrl': 'http://localhost:7777/', 'uriPrefix': 'https://synbiohub.org/', 'color': '#D25627',