Skip to content

Commit

Permalink
Fixes for unauthorized studies feature
Browse files Browse the repository at this point in the history
- Fixed the issue where the html inside the global message would not
be interpreted by the browser, when there was no placeholders.
- Fixed issue 9255 where SELECT ALL selects unauth studies as well
- Allow {$.studyId} placeholder in the unauth studies message
  • Loading branch information
Diana Baiceanu committed Feb 5, 2022
1 parent 372c545 commit c69238a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
13 changes: 8 additions & 5 deletions src/shared/components/query/QueryContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { StudySelectorStats } from 'shared/components/query/StudySelectorStats';
import $ from 'jquery';
import { serializeEvent } from 'shared/lib/tracking';
import { ModifyQueryParams } from 'pages/resultsView/ResultsViewPageStore';
import { getServerConfig } from 'config/config';

interface QueryContainerProps {
store: QueryStore;
Expand Down Expand Up @@ -202,11 +203,13 @@ export default class QueryContainer extends React.Component<
</div>
)}

{this.store.unknownStudyIds.isComplete && (
<UnknownStudiesWarning
ids={this.store.unknownStudyIds.result}
/>
)}
{this.store.unknownStudyIds.isComplete &&
!!getServerConfig()
.skin_home_page_show_unauthorized_studies === false && (
<UnknownStudiesWarning
ids={this.store.unknownStudyIds.result}
/>
)}

{this.store.forDownloadTab && (
<div className={'alert alert-danger'} role="alert">
Expand Down
5 changes: 4 additions & 1 deletion src/shared/components/query/QueryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
import { isMixedReferenceGenome } from 'shared/lib/referenceGenomeUtils';
import { getSuffixOfMolecularProfile } from 'shared/lib/molecularProfileUtils';
import { VirtualStudy } from 'shared/api/session-service/sessionServiceModels';
import { isQueriedStudyAuthorized } from 'pages/studyView/StudyViewUtils';

// interface for communicating
export type CancerStudyQueryUrlParams = {
Expand Down Expand Up @@ -832,7 +833,9 @@ export class QueryStore {
let result: { [studyId: string]: string[] } = {};

_.each(this.physicalStudiesSet.result, (study, studyId) => {
result[studyId] = [studyId];
if (isQueriedStudyAuthorized(study)) {
result[studyId] = [studyId];
}
});

_.each(
Expand Down
28 changes: 15 additions & 13 deletions src/shared/components/studyTagsTooltip/StudyTagsTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export type StudyInfoOverlayTooltipProps = {
iconType: IconType;
};

function addHTMLDescription(description: string) {
return { __html: description };
}

@observer
class StudyInfoOverlay extends React.Component<
StudyInfoOverlayTooltipProps,
Expand All @@ -77,16 +81,12 @@ class StudyInfoOverlay extends React.Component<
makeObservable(this);
}

addHTMLDescription(description: string) {
return { __html: description };
}

render() {
let overlay: any = '';
if (this.props.isVirtualStudy) {
overlay = (
<div
dangerouslySetInnerHTML={this.addHTMLDescription(
dangerouslySetInnerHTML={addHTMLDescription(
this.props.studyDescription
)}
/>
Expand All @@ -99,7 +99,7 @@ class StudyInfoOverlay extends React.Component<
.length;
const description = (
<div
dangerouslySetInnerHTML={this.addHTMLDescription(
dangerouslySetInnerHTML={addHTMLDescription(
this.props.studyDescription
)}
/>
Expand All @@ -122,7 +122,8 @@ class StudyInfoOverlay extends React.Component<
const message = replaceJsonPathPlaceholders(
getServerConfig()
.skin_home_page_unauthorized_studies_global_message,
this.studyMetadata.result
this.studyMetadata.result,
this.props.studyId
);

// if the placeholders couldn't be replaced, then show default global message
Expand All @@ -131,7 +132,7 @@ class StudyInfoOverlay extends React.Component<
) : (
<div
style={{ maxWidth: 300 }}
dangerouslySetInnerHTML={this.addHTMLDescription(
dangerouslySetInnerHTML={addHTMLDescription(
message.toString()
)}
/>
Expand All @@ -153,7 +154,7 @@ export default class StudyTagsTooltip extends React.Component<
> {
renderTooltip() {
return (
<DefaultTooltip
<DefaultTooltip
mouseEnterDelay={this.props.mouseEnterDelay}
placement={this.props.placement}
overlay={
Expand All @@ -162,12 +163,13 @@ export default class StudyTagsTooltip extends React.Component<
getServerConfig()
.skin_home_page_unauthorized_studies_global_message
) === false ? (
<div className={styles.tooltip}>
{
<div
className={styles.tooltip}
dangerouslySetInnerHTML={addHTMLDescription(
getServerConfig()
.skin_home_page_unauthorized_studies_global_message
}
</div>
)}
/>
) : (
<StudyInfoOverlay
studyDescription={this.props.studyDescription}
Expand Down
28 changes: 18 additions & 10 deletions src/shared/lib/JsonPathUtils.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
export function hasJsonPathPlaceholders(message: String) {
const jp = require('jsonpath');

export function hasJsonPathPlaceholders(message: string) {
if (message.match(/[{][$][^}]*[}]/g) === null) return false;
return true;
}

export function replaceJsonPathPlaceholders(
message: String,
studyMetadata: any
message: string,
studyMetadata: any,
studyId: string
) {
let placeholders = message.match(/[{][$][^}]*[}]/g);
let placeholdersReplaced: boolean = true;
if (placeholders !== null) {
let jp = require('jsonpath');
placeholders.forEach(placeholder => {
let placeholderReplaceValue = jp.query(
studyMetadata,
placeholder.replace(/["'{}]/g, '')
);
if (placeholderReplaceValue.length === 0)
let placeholderReplaceValue = '';
if (placeholder === '{$.studyId}') {
placeholderReplaceValue = studyId;
} else {
placeholderReplaceValue = jp.query(
studyMetadata,
placeholder.replace(/["'{}]/g, '')
);
}
if (placeholderReplaceValue.length === 0) {
placeholdersReplaced = false;
else
} else {
message = message.replace(placeholder, placeholderReplaceValue);
}
});
}
return message;
Expand Down

0 comments on commit c69238a

Please sign in to comment.