/* eslint-disable react/no-danger */ import React from 'react'; import PropTypes from 'prop-types'; import { Collapse } from 'reactstrap'; import { withTranslation } from 'react-i18next'; import { validateDeleteConfigs } from '~/utils/page-delete-config'; import { withUnstatedContainers } from '../../UnstatedUtils'; import { toastSuccess, toastError } from '~/client/util/apiNotification'; import { PageDeleteConfigValue } from '~/interfaces/page-delete-config'; import AppContainer from '~/client/services/AppContainer'; import AdminGeneralSecurityContainer from '~/client/services/AdminGeneralSecurityContainer'; // used as the prefix of translation const DeletionTypeForT = Object.freeze({ Deletion: 'deletion', CompleteDeletion: 'complete_deletion', RecursiveDeletion: 'recursive_deletion', RecursiveCompleteDeletion: 'recursive_complete_deletion', }); const DeletionType = Object.freeze({ Deletion: 'deletion', CompleteDeletion: 'completeDeletion', RecursiveDeletion: 'recursiveDeletion', RecursiveCompleteDeletion: 'recursiveCompleteDeletion', }); const getDeletionTypeForT = (deletionType) => { switch (deletionType) { case DeletionType.Deletion: return DeletionTypeForT.Deletion; case DeletionType.RecursiveDeletion: return DeletionTypeForT.RecursiveDeletion; case DeletionType.CompleteDeletion: return DeletionTypeForT.CompleteDeletion; case DeletionType.RecursiveCompleteDeletion: return DeletionTypeForT.RecursiveCompleteDeletion; } }; /** * Return true if "deletionType" is DeletionType.RecursiveDeletion or DeletionType.RecursiveCompleteDeletion. * @param deletionType Deletion type * @returns boolean */ const isRecursiveDeletion = (deletionType) => { return deletionType === DeletionType.RecursiveDeletion || deletionType === DeletionType.RecursiveCompleteDeletion; }; /** * Return true if "deletionType" is DeletionType.Deletion or DeletionType.RecursiveDeletion. * @param deletionType Deletion type * @returns boolean */ const isTypeDeletion = (deletionType) => { return deletionType === DeletionType.Deletion || deletionType === DeletionType.RecursiveDeletion; }; class SecuritySetting extends React.Component { constructor(props) { super(props); this.putSecuritySetting = this.putSecuritySetting.bind(this); this.getRecursiveDeletionConfigState = this.getRecursiveDeletionConfigState.bind(this); this.setDeletionConfigState = this.setDeletionConfigState.bind(this); this.renderPageDeletePermission = this.renderPageDeletePermission.bind(this); this.renderPageDeletePermissionDropdown = this.renderPageDeletePermissionDropdown.bind(this); } async putSecuritySetting() { const { t, adminGeneralSecurityContainer } = this.props; try { await adminGeneralSecurityContainer.updateGeneralSecuritySetting(); toastSuccess(t('security_setting.updated_general_security_setting')); } catch (err) { toastError(err); } } getRecursiveDeletionConfigState(deletionType) { const { adminGeneralSecurityContainer } = this.props; if (isTypeDeletion(deletionType)) { return [ adminGeneralSecurityContainer.state.currentPageRecursiveDeletionAuthority, adminGeneralSecurityContainer.changePageRecursiveDeletionAuthority, ]; } return [ adminGeneralSecurityContainer.state.currentPageRecursiveCompleteDeletionAuthority, adminGeneralSecurityContainer.changePageRecursiveCompleteDeletionAuthority, ]; } /** * Force update deletion config for recursive operation when the deletion config for general operation is updated. * @param deletionType Deletion type */ setDeletionConfigState(newState, setState, deletionType) { if (isRecursiveDeletion(deletionType)) { setState(newState); return; } const [recursiveState, setRecursiveState] = this.getRecursiveDeletionConfigState(deletionType); const shouldForceUpdate = !validateDeleteConfigs(newState, recursiveState); if (shouldForceUpdate) { setState(newState); setRecursiveState(newState); } else { setState(newState); } return; } renderPageDeletePermissionDropdown(currentState, setState, deletionType, isButtonDisabled) { const { t } = this.props; return (
{t(`security_setting.${getDeletionTypeForT(deletionType)}_explain`)}
{t('Error occurred')} : {adminGeneralSecurityContainer.retrieveError}
| { t('scope_of_page_disclosure') } | { t('set_point') } |
|---|---|
| { t('Public') } | { t('always_displayed') } |
| { t('Anyone with the link') } | { t('always_hidden') } |
| { t('Only me') } |
{ adminGeneralSecurityContainer.switchIsShowRestrictedByOwner() }}
/>
|
| { t('Only inside the group') } |
{ adminGeneralSecurityContainer.switchIsShowRestrictedByGroup() }}
/>
|
FIXED
{t('security_setting.max_age_caution')}