Add secure TrizRis access control for OHIF toolbar
Build and Deploy Docs / build-and-deploy-docs (push) Waiting to run
Build and Deploy Docs / build-and-deploy-docs (push) Waiting to run
This commit is contained in:
1 parent
f00379a672
commit
1546a4c81a
4 files changed
+168
-8
No files matched your search
@@ -9,6 +9,7 @@ import HeaderPatientInfo from './HeaderPatientInfo';
|
||||
import { PatientInfoVisibility } from './HeaderPatientInfo/HeaderPatientInfo';
|
||||
import { preserveQueryParameters } from '@ohif/app';
|
||||
import { Types } from '@ohif/core';
|
||||
import { checkTrizRisAccess } from '../services/TrizRisAccessApi';
|
||||
|
||||
function ViewerHeader({ appConfig }: withAppTypes<{ appConfig: AppTypes.Config }>) {
|
||||
const { servicesManager, extensionManager, commandsManager } = useSystem();
|
||||
@@ -17,6 +18,22 @@ function ViewerHeader({ appConfig }: withAppTypes<{ appConfig: AppTypes.Config }
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
const [toolbarDisabled, setToolbarDisabled] = React.useState(true);
|
||||
|
||||
React.useEffect(() => {
|
||||
const chargerAcces = async () => {
|
||||
const access = await checkTrizRisAccess();
|
||||
|
||||
console.log('### ACCESS TOOLBAR ###', access);
|
||||
console.log('### canUseToolbar ###', access?.canUseToolbar);
|
||||
console.log('### canConsulter ###', access?.canConsulter);
|
||||
console.log('### isMedecin ###', access?.isMedecin);
|
||||
|
||||
setToolbarDisabled(access?.canUseToolbar !== true);
|
||||
};
|
||||
|
||||
chargerAcces();
|
||||
}, []);
|
||||
const onClickReturnButton = () => {
|
||||
const { pathname } = location;
|
||||
const dataSourceIdx = pathname.indexOf('/', 1);
|
||||
@@ -104,7 +121,21 @@ function ViewerHeader({ appConfig }: withAppTypes<{ appConfig: AppTypes.Config }
|
||||
isReturnEnabled={!!appConfig.showStudyList}
|
||||
onClickReturnButton={onClickReturnButton}
|
||||
WhiteLabeling={appConfig.whiteLabeling}
|
||||
Secondary={<Toolbar buttonSection="secondary" />}
|
||||
Secondary={
|
||||
<div
|
||||
style={
|
||||
toolbarDisabled
|
||||
? {
|
||||
pointerEvents: 'none',
|
||||
opacity: 0.45,
|
||||
cursor: 'not-allowed',
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<Toolbar buttonSection="secondary" />
|
||||
</div>
|
||||
}
|
||||
PatientInfo={
|
||||
appConfig.showPatientInfo !== PatientInfoVisibility.DISABLED && (
|
||||
<HeaderPatientInfo
|
||||
@@ -138,7 +169,14 @@ function ViewerHeader({ appConfig }: withAppTypes<{ appConfig: AppTypes.Config }
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="relative flex justify-center gap-[4px]">
|
||||
<div
|
||||
className="relative flex justify-center gap-[4px]"
|
||||
style={{
|
||||
pointerEvents: toolbarDisabled ? 'none' : 'auto',
|
||||
opacity: toolbarDisabled ? 0.45 : 1,
|
||||
cursor: toolbarDisabled ? 'not-allowed' : 'default',
|
||||
}}
|
||||
>
|
||||
<Toolbar buttonSection="primary" />
|
||||
</div>
|
||||
</Header>
|
||||
|
||||
@@ -2,7 +2,15 @@ import { TrizRisConfig } from '@ohif/core/src/config/TrizRisConfig';
|
||||
|
||||
const ACCESS_URL = `${TrizRisConfig.apiBaseUrl}/ohif/access`;
|
||||
|
||||
export async function checkTrizRisAccess(): Promise<boolean> {
|
||||
export interface TrizRisAccess {
|
||||
authorized: boolean;
|
||||
isMedecin: boolean;
|
||||
canVisualiser: boolean;
|
||||
canConsulter: boolean;
|
||||
canUseToolbar: boolean;
|
||||
}
|
||||
|
||||
export async function checkTrizRisAccess(): Promise<TrizRisAccess | null> {
|
||||
try {
|
||||
const response = await fetch(ACCESS_URL, {
|
||||
method: 'GET',
|
||||
@@ -15,15 +23,22 @@ export async function checkTrizRisAccess(): Promise<boolean> {
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
console.log('### REPONSE ACCESS TRIZRIS ###', result);
|
||||
|
||||
return result.authorized === true;
|
||||
return {
|
||||
authorized: result.authorized === true,
|
||||
isMedecin: result.isMedecin === true,
|
||||
canVisualiser: result.canVisualiser === true,
|
||||
canConsulter: result.canConsulter === true,
|
||||
canUseToolbar: result.canUseToolbar === true,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('### ERREUR VERIFICATION ACCES TRIZRIS ###', error);
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user