Skip to content

Commit

Permalink
Merge branch 'master' into talk-rails-5.2-canary-test
Browse files Browse the repository at this point in the history
  • Loading branch information
yuenmichelle1 committed Dec 12, 2024
2 parents 9ef4c02 + a854eb3 commit b7d7222
Show file tree
Hide file tree
Showing 6 changed files with 565 additions and 507 deletions.
18 changes: 3 additions & 15 deletions app/lib/session.coffee
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
storage = window.sessionStorage ? window.localStorage
storage = window.sessionStorage
stored = JSON.parse storage?.getItem('session_id')

generateSessionID = () ->
hash = require('hash.js')
sha2 = hash.sha256()
id = sha2.update("#{Math.random() * 10000 }#{Date.now()}#{Math.random() * 1000}").digest('hex')
ttl = fiveMinutesFromNow()
stored = {id, ttl}
stored = {id}
try
storage.setItem('session_id', JSON.stringify(stored))
stored

getSessionID = () ->
{id, ttl} = JSON.parse(storage.getItem('session_id')) ? generateSessionID()
if ttl < Date.now()
{id} = generateSessionID()
else
ttl = fiveMinutesFromNow()
try
storage.setItem('session_id', JSON.stringify({id, ttl}))
{id} = JSON.parse(storage.getItem('session_id')) ? generateSessionID()
id

fiveMinutesFromNow = () ->
d = new Date()
d.setMinutes(d.getMinutes() + 5)
d

module.exports = {generateSessionID, getSessionID}
2 changes: 1 addition & 1 deletion app/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export default {
partnerPreferences: 'Zooniverse partner email preferences',
nasa: 'Get periodic email updates from NASA regarding broader NASA citizen science projects and efforts',
emailValid: 'Valid email',
emailInvalid: 'Verified email',
emailInvalid: 'Invalid email',
emailInvalidPrompt: 'Please re-enter your email above',
emailVerified: 'Verified email',
emailUnverified: 'Unverified email',
Expand Down
19 changes: 18 additions & 1 deletion app/pages/lab-pages-editor/DataManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import PropTypes from 'prop-types';
import apiClient from 'panoptes-client/lib/api-client';
import { WorkflowContext } from './context.js';
import checkIsPFEWorkflow from './helpers/checkIsPFEWorkflow.js';
import checkIsWorkflowPartOfProject from './helpers/checkIsWorkflowPartOfProject.js';

function DataManager({
// key: to ensure DataManager renders FRESH (with states reset) whenever workflowId changes, use <DataManager key={workflowId} ... />
Expand Down Expand Up @@ -118,8 +119,24 @@ function DataManager({
};
}, [apiData.project, apiData.workflow, apiData.status, updateCounter]);

// Safety check: did this component receive its minimum input?
if (!workflowId) return (<div>ERROR: no Workflow ID specified</div>);
// if (!workflow) return null

// Safety check: does this workflow belong to this project?
if (apiData.workflow && apiData.project) {
const isWorkflowPartOfProject = checkIsWorkflowPartOfProject(apiData.workflow, apiData.project);
if (!isWorkflowPartOfProject) {
return (
<div className="status-banner error">
ERROR: workflow {apiData.workflow.id} doesn't belong to project {apiData.project.id}
</div>
);
}
}

// NOTE: no need to check for !workflow.
// This is automatically handled by "Error: could not fetch data"
// // if (!workflow) return null

return (
<WorkflowContext.Provider
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Checks if a workflow belongs to a project.
*/

export default function checkIsWorkflowPartOfProject(workflow, project) {
if (!workflow || !project) return false;
return !!project.links?.workflows?.includes(workflow.id);
}
Loading

0 comments on commit b7d7222

Please sign in to comment.