extensions/xnat/src/utils/checkAndSetPermissions.js
/**
 * checkAndSetPermissions - Queries the XNAT-ROI XAPI for the permissions the
 * user has for the roiCollection schema element, and stores the result in
 * Session variables.
 *
 * @param  {type} projectId       The XNAT projectId.
 * @param  {type} parentProjectId The ID of the parent project. If the session
 *                                is not shared into another project, it will
 *                                be the same as the projectId.
 * @returns {null}
 */
Queries the XNAT-ROI XAPI for the permissions the
user has for the roiCollection schema element, and stores the result in
Session variables.

@param  {type} projectId       The XNAT projectId.
@param  {type} parentProjectId The ID of the parent project. If the session
is not shared into another project, it will
be the same as the projectId.
@returns {null}
Queries the XNAT - ROI XAPI for the permissions the user has for the roiCollection schema element and stores the result in Session variables . @param { type } projectId The XNAT projectId . @param { type } parentProjectId The ID of the parent project . If the session is not shared into another project it will be the same as the projectId . @returns { null }
function checkAndSetPermissions({
  projectId,
  parentProjectId,
  subjectId,
}) {
  const { xnatRootUrl, permissions } = sessionMap;
  const url = `${xnatRootUrl}xapi/roi/projects/${parentProjectId}/permissions/RoiCollection`;
  sessionMap.setProject(projectId);
  sessionMap.setParentProject(parentProjectId);
  sessionMap.setSubject(subjectId);
  getPermissionsJson(url)
    .then(result => {
      const { status, response } = result;
      if (status === 200) {
        console.log(
          `permissions: create: ${response.create},
          read: ${response.read},
          edit: ${response.edit}`
        );
        permissions.writePermissions = response.create;
        permissions.readPermissions = response.read;
        permissions.editPermissions = response.edit;
      } else if (parentProjectId !== projectId) {
        console.log('Can only read from parent project');
        permissions.writePermissions = false;
        permissions.readPermissions = true;
        permissions.editPermissions = false;
      }
    })
    .catch(err => {
      console.log(err);
      permissions.writePermissions = false;
      permissions.readPermissions = false;
      permissions.editPermissions = false;
    });
}
function checkAndSetPermissions ( { projectId , parentProjectId , subjectId , } ) { const { xnatRootUrl , permissions } = sessionMap ; const url = ` ${ xnatRootUrl } ${ parentProjectId } ` ; sessionMap . setProject ( projectId ) ; sessionMap . setParentProject ( parentProjectId ) ; sessionMap . setSubject ( subjectId ) ; getPermissionsJson ( url ) . then ( result => { const { status , response } = result ; if ( status === 200 ) { console . log ( ` ${ response . create } ${ response . read } ${ response . edit } ` ) ; permissions . writePermissions = response . create ; permissions . readPermissions = response . read ; permissions . editPermissions = response . edit ; } else if ( parentProjectId !== projectId ) { console . log ( 'Can only read from parent project' ) ; permissions . writePermissions = false ; permissions . readPermissions = true ; permissions . editPermissions = false ; } } ) . catch ( err => { console . log ( err ) ; permissions . writePermissions = false ; permissions . readPermissions = false ; permissions . editPermissions = false ; } ) ; }
checkAndSetPermissions - Queries the XNAT-ROI XAPI for the permissions the
 user has for the roiCollection schema element, and stores the result in
 Session variables.
checkAndSetPermissions - Queries the XNAT - ROI XAPI for the permissions the user has for the roiCollection schema element and stores the result in Session variables .
// icrXnatRoiSession.set('writePermissions', response.create); // icrXnatRoiSession.set('readPermissions', response.read); // icrXnatRoiSession.set('editPermissions', response.edit); // Assume read only of parent  project. // icrXnatRoiSession.set('writePermissions', false); // icrXnatRoiSession.set('readPermissions', true); // icrXnatRoiSession.set('editPermissions', false);