Skip to content

Commit

Permalink
Merge branch 'hm-duos-2608-read-only-dar-form' into hm-duos-2676-read…
Browse files Browse the repository at this point in the history
…-only-dar-researcher-console
  • Loading branch information
hams7504 committed Sep 29, 2023
2 parents 8877f36 + f544df2 commit 6c5f271
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 67 deletions.
64 changes: 36 additions & 28 deletions src/components/eRACommons.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export const eRACommons = hh(class eRACommons extends React.Component {
expirationCount: 0,
eraCommonsId: '',
nihError: false,
isHovered: false,
isCurrentUser: true
isHovered: false
};

componentDidMount = async () => {
Expand Down Expand Up @@ -49,31 +48,40 @@ export const eRACommons = hh(class eRACommons extends React.Component {
};

getUserInfo = async () => {
let response = await User.getMe();
if (this.props.researcher !== undefined) {
const givenUser = this.props.researcher;
if (givenUser.userId != response.userId) {
this.setState(prev => {
prev.isCurrentUser = false;
return prev;
});
}
response = givenUser;
if (this.props.researcherProfile === undefined) {
const response = await User.getMe();
const props = response.researcherProperties;
const authProp = find({'propertyKey':'eraAuthorized'})(props);
const expProp = find({'propertyKey':'eraExpiration'})(props);
const isAuthorized = isNil(authProp) ? false : getOr(false,'propertyValue')(authProp);
const expirationCount = isNil(expProp) ? 0 : AuthenticateNIH.expirationCount(getOr(0,'propertyValue')(expProp));
const nihValid = isAuthorized && expirationCount > 0;
const eraCommonsId = response.eraCommonsId;
this.props.onNihStatusUpdate(nihValid);
this.setState(prev => {
prev.isAuthorized = isAuthorized;
prev.expirationCount = expirationCount;
prev.eraCommonsId = isNil(eraCommonsId) ? '' : eraCommonsId;
return prev;
});
}
else {
const response = this.props.researcherProfile;
const props = response.researcherProperties;
const authProp = find({'propertyKey':'eraAuthorized'})(props);
const expProp = find({'propertyKey':'eraExpiration'})(props);
const isAuthorized = isNil(authProp) ? false : getOr(false,'propertyValue')(authProp);
const expirationCount = isNil(expProp) ? 0 : AuthenticateNIH.expirationCount(getOr(0,'propertyValue')(expProp));
const nihValid = isAuthorized && expirationCount > 0;
const eraCommonsId = response.eraCommonsId;
this.props.onNihStatusUpdate(nihValid);
this.setState(prev => {
prev.isAuthorized = isAuthorized;
prev.expirationCount = expirationCount;
prev.eraCommonsId = isNil(eraCommonsId) ? '' : eraCommonsId;
return prev;
});
}
const props = response.researcherProperties;
const authProp = find({'propertyKey':'eraAuthorized'})(props);
const expProp = find({'propertyKey':'eraExpiration'})(props);
const isAuthorized = isNil(authProp) ? false : getOr(false,'propertyValue')(authProp);
const expirationCount = isNil(expProp) ? 0 : AuthenticateNIH.expirationCount(getOr(0,'propertyValue')(expProp));
const nihValid = isAuthorized && expirationCount > 0;
const eraCommonsId = response.eraCommonsId;
this.props.onNihStatusUpdate(nihValid);
this.setState(prev => {
prev.isAuthorized = isAuthorized;
prev.expirationCount = expirationCount;
prev.eraCommonsId = isNil(eraCommonsId) ? '' : eraCommonsId;
return prev;
});
};

verifyToken = async (parsedToken) => {
Expand Down Expand Up @@ -202,10 +210,10 @@ export const eRACommons = hh(class eRACommons extends React.Component {
className: 'col-lg-12 col-md-12 col-sm-6 col-xs-12 no-padding'
}, [
div({ isRendered: this.state.expirationCount >= 0, className: 'fadein' }, ['Your NIH authentication will expire in ' + this.state.expirationCount + ' days']),
div({ isRendered: this.state.expirationCount < 0, className: 'fadein' }, [this.state.isCurrentUser ? 'Your NIH authentication has expired' : `This user's NIH authentication has expired`])
div({ isRendered: this.state.expirationCount < 0, className: 'fadein' }, [(this.props.researcherProfile === undefined) ? 'Your NIH authentication has expired' : `This user's NIH authentication has expired`])
])
])
])
);
}
});
});
6 changes: 0 additions & 6 deletions src/libs/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,6 @@ export const User = {
return res.json();
},

// getSOsForGivenUser: async (userId) => {
// const url = `${await getApiUrl()}/api/user/signing-officials/${userId}`;
// const res = await fetchOk(url, fp.mergeAll([Config.authOpts(), { method: 'GET' }]));
// return res.json();
// },

getUnassignedUsers: async () => {
const url = `${await getApiUrl()}/api/user/institution/unassigned`;
const res = await axios.get(url, Config.authOpts());
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dar_application/DataAccessRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,4 @@ export default function DataAccessRequest(props) {
]),
])
);
}
}
46 changes: 21 additions & 25 deletions src/pages/dar_application/DataAccessRequestApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import UsgOmbText from '../../components/UsgOmbText';
const ApplicationTabs = [
{ name: 'Researcher Information' },
{ name: 'Data Access Request' },
{ name: 'Research Purpose Statement' },
{ name: 'Data Use Agreement' }
{ name: 'Research Purpose Statement' }
];

const fetchAllDatasets = async (dsIds) => {
Expand Down Expand Up @@ -125,6 +124,9 @@ const DataAccessRequestApplication = (props) => {
const [isLoading, setIsLoading] = useState(true);
const [isAttested, setIsAttested] = useState(false);

if (!props.readOnlyMode) {
ApplicationTabs.push({ name: 'Data Use Agreement' });
}
const [applicationTabs, setApplicationTabs] = useState(ApplicationTabs);

//helper function to coordinate local state changes as well as updates to form data on the parent
Expand Down Expand Up @@ -227,19 +229,11 @@ const DataAccessRequestApplication = (props) => {
const init = useCallback(async () => {
const { dataRequestId, collectionId } = props.match.params;
let formData = {};
if (props.researcher === undefined) {
const researcher = await User.getMe();
const signingOfficials = await User.getSOsForCurrentUser();
setResearcher(researcher);
setAllSigningOfficials(signingOfficials);
}
else {
const researcher = props.researcher;
// const signingOfficials = await User.getSOsForGivenUser(props.researcher.userId);
setResearcher(researcher);
setAllSigningOfficials(['Hello']);
}
const researcher = await User.getMe();
const signingOfficials = await User.getSOsForCurrentUser();

setResearcher(researcher);
setAllSigningOfficials(signingOfficials);
setIsLoading(false);

if (!isNil(collectionId)) {
Expand Down Expand Up @@ -267,7 +261,7 @@ const DataAccessRequestApplication = (props) => {

batchFormFieldChange(formData);
window.addEventListener('scroll', onScroll); // eslint-disable-line -- codacy says event listeners are dangerous
}, [onScroll, props.match.params, props.researcher, researcher]);
}, [onScroll, props.match.params]);

useEffect(() => {
init();
Expand Down Expand Up @@ -538,6 +532,7 @@ const DataAccessRequestApplication = (props) => {
<ResearcherInfo
completed={!isNil(get('institutionId', researcher))}
readOnlyMode={props.readOnlyMode || isAttested}
researcherProfile={props.researcherProfile}
includeInstructions={!props.readOnlyMode}
darCode={formData.darCode}
formData={formData}
Expand All @@ -549,7 +544,7 @@ const DataAccessRequestApplication = (props) => {
nihValid={nihValid}
onNihStatusUpdate={setNihValid}
showNihValidationError={showNihValidationError}
researcher={(props.researcher === undefined) ? researcher : props.researcher}
researcher={researcher}
allSigningOfficials={allSigningOfficials}
setLabCollaboratorsCompleted={setLabCollaboratorsCompleted}
setInternalCollaboratorsCompleted={setInternalCollaboratorsCompleted}
Expand Down Expand Up @@ -587,15 +582,16 @@ const DataAccessRequestApplication = (props) => {
/>
</div>

<div className='step-container'>
{!props.readOnlyMode ? <DataUseAgreements
darCode={formData.darCode}
cancelAttest={() => setIsAttested(false)}
isAttested={isAttested}
attest={attemptSubmit}
save={() => setShowDialogSave(true)}
/> : <div />}
</div>
{!props.readOnlyMode ?
<div className='step-container'>
<DataUseAgreements
darCode={formData.darCode}
cancelAttest={() => setIsAttested(false)}
isAttested={isAttested}
attest={attemptSubmit}
save={() => setShowDialogSave(true)}
/>
</div> : <div />}

{isAttested &&
<div className='step-container'>
Expand Down
9 changes: 5 additions & 4 deletions src/pages/dar_application/ResearcherInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function ResearcherInfo(props) {
const {
allSigningOfficials,
readOnlyMode,
researcherProfile,
includeInstructions,
completed,
darCode,
Expand Down Expand Up @@ -78,7 +79,7 @@ export default function ResearcherInfo(props) {
title: '1.1 Researcher',
validators: [FormValidators.REQUIRED],
ariaLevel: ariaLevel + 1,
defaultValue: researcher.displayName,
defaultValue: (researcherProfile === undefined) ? researcher.displayName : researcherProfile.displayName,
disabled: true
}),
]),
Expand All @@ -97,7 +98,7 @@ export default function ResearcherInfo(props) {
location: location,
validationError: showNihValidationError,
readOnly: readOnlyMode,
researcher: props.researcher,
researcherProfile: researcherProfile,
header: true,
required: formData.checkCollaborator !== true,
})
Expand Down Expand Up @@ -200,7 +201,7 @@ export default function ResearcherInfo(props) {
}),
]),

div({className: 'dar-application-row'}, [
!props.readOnlyMode && div({className: 'dar-application-row'}, [
h(FormField, {
id: 'signingOfficial',
type: FormFieldTypes.SELECT,
Expand Down Expand Up @@ -392,4 +393,4 @@ export default function ResearcherInfo(props) {
]),
])
);
}
}
2 changes: 1 addition & 1 deletion src/pages/dar_application/collaborator/CollaboratorList.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ export default function CollaboratorList(props) {
ListItems
])
);
}
}
4 changes: 2 additions & 2 deletions src/pages/dar_collection_review/DarCollectionReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ export default function DarCollectionReview(props) {
}),
h(DataAccessRequestApplication, {
isRendered: selectedTab === tabs.fullDAR,
researcher: researcherProfile,
readOnlyMode: true,
researcherProfile: researcherProfile,
...props
}),
h(MultiDatasetVotingTab, {
Expand All @@ -232,4 +232,4 @@ export default function DarCollectionReview(props) {
]
),
]);
}
}

0 comments on commit 6c5f271

Please sign in to comment.