2020-12-23 19:59:50 +01:00
|
|
|
import React, { memo, useMemo } from 'react';
|
2020-12-24 08:30:53 +01:00
|
|
|
import {
|
|
|
|
BaselineAlignment,
|
|
|
|
CheckPagePermissions,
|
2020-12-24 10:46:25 +01:00
|
|
|
NotAllowedInput,
|
2020-12-24 08:30:53 +01:00
|
|
|
SizedInput,
|
|
|
|
useUserPermissions,
|
|
|
|
} from 'strapi-helper-plugin';
|
2020-12-23 19:59:50 +01:00
|
|
|
import { useIntl } from 'react-intl';
|
|
|
|
import { getRequestUrl } from '../../../../../admin/src/utils';
|
2020-12-23 19:56:06 +01:00
|
|
|
import PageTitle from '../../../../../admin/src/components/SettingsPageTitle';
|
|
|
|
import ContainerFluid from '../../../../../admin/src/components/ContainerFluid';
|
|
|
|
import FormBloc from '../../../../../admin/src/components/FormBloc';
|
|
|
|
import { Header } from '../../../../../admin/src/components/Settings';
|
2020-12-24 08:33:25 +01:00
|
|
|
import { useRolesList, useSettingsForm } from '../../../../../admin/src/hooks';
|
2020-12-24 09:14:23 +01:00
|
|
|
import adminPermissions from '../../../../../admin/src/permissions';
|
2020-12-23 19:56:06 +01:00
|
|
|
import { form, schema } from './utils';
|
|
|
|
|
2020-12-24 10:02:27 +01:00
|
|
|
const ssoPermissions = {
|
|
|
|
...adminPermissions.settings.sso,
|
|
|
|
readRoles: adminPermissions.settings.roles.read,
|
|
|
|
};
|
|
|
|
|
2020-12-23 19:56:06 +01:00
|
|
|
const SingleSignOn = () => {
|
2020-12-23 19:59:50 +01:00
|
|
|
const { formatMessage } = useIntl();
|
2020-12-24 08:30:53 +01:00
|
|
|
const {
|
2020-12-24 10:02:27 +01:00
|
|
|
isLoading: isLoadingForPermissions,
|
|
|
|
allowedActions: { canUpdate, canReadRoles },
|
|
|
|
} = useUserPermissions(ssoPermissions);
|
2020-12-24 08:30:53 +01:00
|
|
|
|
2020-12-23 19:56:06 +01:00
|
|
|
const [
|
|
|
|
{ formErrors, initialData, isLoading, modifiedData, showHeaderButtonLoader },
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
dispatch,
|
|
|
|
{ handleCancel, handleChange, handleSubmit },
|
2020-12-24 08:33:25 +01:00
|
|
|
] = useSettingsForm(getRequestUrl('providers/options'), schema, () => {}, [
|
2020-12-23 19:56:06 +01:00
|
|
|
'autoRegister',
|
|
|
|
'defaultRole',
|
|
|
|
]);
|
2020-12-24 10:02:27 +01:00
|
|
|
const { roles } = useRolesList(canReadRoles);
|
2020-12-23 19:56:06 +01:00
|
|
|
|
2020-12-24 10:02:27 +01:00
|
|
|
const showLoader = useMemo(() => isLoadingForPermissions || isLoading, [
|
|
|
|
isLoading,
|
|
|
|
isLoadingForPermissions,
|
|
|
|
]);
|
2020-12-23 19:56:06 +01:00
|
|
|
|
|
|
|
const options = useMemo(() => {
|
|
|
|
return [
|
|
|
|
<option key="placeholder" disabled value="">
|
|
|
|
{formatMessage({ id: 'components.InputSelect.option.placeholder' })}
|
|
|
|
</option>,
|
|
|
|
...roles.map(({ id, name }) => (
|
|
|
|
<option key={id} value={id}>
|
|
|
|
{name}
|
|
|
|
</option>
|
|
|
|
)),
|
|
|
|
];
|
|
|
|
}, [roles, formatMessage]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<PageTitle name="SSO" />
|
|
|
|
<form onSubmit={handleSubmit}>
|
|
|
|
<ContainerFluid padding="0">
|
|
|
|
<Header
|
|
|
|
isLoading={showLoader}
|
|
|
|
initialData={initialData}
|
|
|
|
label={formatMessage({ id: 'Settings.sso.title' })}
|
|
|
|
modifiedData={modifiedData}
|
|
|
|
onCancel={handleCancel}
|
|
|
|
content={formatMessage({ id: 'Settings.sso.description' })}
|
|
|
|
showHeaderButtonLoader={showHeaderButtonLoader}
|
|
|
|
/>
|
|
|
|
<BaselineAlignment top size="3px" />
|
|
|
|
<FormBloc isLoading={showLoader}>
|
|
|
|
{Object.keys(form).map(key => {
|
2020-12-24 10:46:25 +01:00
|
|
|
let type = key === 'defaultRole' && !canReadRoles ? 'notAllowed' : form[key].type;
|
|
|
|
let description =
|
|
|
|
key === 'defaultRole' && !canReadRoles
|
|
|
|
? form[key].notAllowedDescription
|
|
|
|
: form[key].description;
|
|
|
|
|
2020-12-23 19:56:06 +01:00
|
|
|
return (
|
|
|
|
<SizedInput
|
|
|
|
{...form[key]}
|
2020-12-24 10:46:25 +01:00
|
|
|
customInputs={{ notAllowed: NotAllowedInput }}
|
|
|
|
description={description}
|
2020-12-23 19:56:06 +01:00
|
|
|
key={key}
|
2020-12-24 08:30:53 +01:00
|
|
|
disabled={!canUpdate}
|
2020-12-23 19:56:06 +01:00
|
|
|
error={formErrors[key]}
|
|
|
|
name={key}
|
|
|
|
onChange={handleChange}
|
|
|
|
options={options}
|
|
|
|
value={modifiedData[key]}
|
2020-12-24 10:46:25 +01:00
|
|
|
type={type}
|
2020-12-23 19:56:06 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</FormBloc>
|
|
|
|
</ContainerFluid>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-12-24 08:30:53 +01:00
|
|
|
const ProtectedSSO = () => (
|
2020-12-24 10:02:27 +01:00
|
|
|
<CheckPagePermissions permissions={ssoPermissions.main}>
|
2020-12-24 08:30:53 +01:00
|
|
|
<SingleSignOn />
|
|
|
|
</CheckPagePermissions>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default memo(ProtectedSSO);
|