|
|
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
|
|
import { Collapse } from 'reactstrap';
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
|
|
-import { validateDeleteConfigs } from '~/utils/page-delete-config';
|
|
|
+import { validateDeleteConfigs, prepareDeleteConfigValuesForCalc } from '~/utils/page-delete-config';
|
|
|
import { withUnstatedContainers } from '../../UnstatedUtils';
|
|
|
import { toastSuccess, toastError } from '~/client/util/apiNotification';
|
|
|
import { PageDeleteConfigValue } from '~/interfaces/page-delete-config';
|
|
|
@@ -39,6 +39,20 @@ const getDeletionTypeForT = (deletionType) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const getDeleteConfigValueForT = (DeleteConfigValue) => {
|
|
|
+ switch (DeleteConfigValue) {
|
|
|
+ case PageDeleteConfigValue.Anyone:
|
|
|
+ case null:
|
|
|
+ return 'security_setting.anyone';
|
|
|
+ case PageDeleteConfigValue.Inherit:
|
|
|
+ return 'security_setting.inherit';
|
|
|
+ case PageDeleteConfigValue.AdminOnly:
|
|
|
+ return 'security_setting.admin_only';
|
|
|
+ case PageDeleteConfigValue.AdminAndAuthor:
|
|
|
+ return 'security_setting.admin_and_author';
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* Return true if "deletionType" is DeletionType.RecursiveDeletion or DeletionType.RecursiveCompleteDeletion.
|
|
|
* @param deletionType Deletion type
|
|
|
@@ -62,9 +76,16 @@ class SecuritySetting extends React.Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
|
|
|
+ // functions
|
|
|
this.putSecuritySetting = this.putSecuritySetting.bind(this);
|
|
|
this.getRecursiveDeletionConfigState = this.getRecursiveDeletionConfigState.bind(this);
|
|
|
+ this.previousPageRecursiveAuthorityState = this.previousPageRecursiveAuthorityState.bind(this);
|
|
|
+ this.setPagePreviousRecursiveAuthorityState = this.setPagePreviousRecursiveAuthorityState.bind(this);
|
|
|
+ this.expantDeleteOptionsState = this.expantDeleteOptionsState.bind(this);
|
|
|
+ this.setExpantOtherDeleteOptionsState = this.setExpantOtherDeleteOptionsState.bind(this);
|
|
|
this.setDeletionConfigState = this.setDeletionConfigState.bind(this);
|
|
|
+
|
|
|
+ // render
|
|
|
this.renderPageDeletePermission = this.renderPageDeletePermission.bind(this);
|
|
|
this.renderPageDeletePermissionDropdown = this.renderPageDeletePermissionDropdown.bind(this);
|
|
|
}
|
|
|
@@ -96,25 +117,67 @@ class SecuritySetting extends React.Component {
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ previousPageRecursiveAuthorityState(deletionType) {
|
|
|
+ const { adminGeneralSecurityContainer } = this.props;
|
|
|
+
|
|
|
+ return isTypeDeletion(deletionType)
|
|
|
+ ? adminGeneralSecurityContainer.state.previousPageRecursiveDeletionAuthority
|
|
|
+ : adminGeneralSecurityContainer.state.previousPageRecursiveCompleteDeletionAuthority;
|
|
|
+ }
|
|
|
+
|
|
|
+ setPagePreviousRecursiveAuthorityState(deletionType, previousState) {
|
|
|
+ const { adminGeneralSecurityContainer } = this.props;
|
|
|
+
|
|
|
+ if (isTypeDeletion(deletionType)) {
|
|
|
+ adminGeneralSecurityContainer.changePreviousPageRecursiveDeletionAuthority(previousState);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ adminGeneralSecurityContainer.changePreviousPageRecursiveCompleteDeletionAuthority(previousState);
|
|
|
+ }
|
|
|
+
|
|
|
+ expantDeleteOptionsState(deletionType) {
|
|
|
+ const { adminGeneralSecurityContainer } = this.props;
|
|
|
+
|
|
|
+ return isTypeDeletion(deletionType)
|
|
|
+ ? adminGeneralSecurityContainer.state.expandOtherOptionsForDeletion
|
|
|
+ : adminGeneralSecurityContainer.state.expandOtherOptionsForCompleteDeletion;
|
|
|
+ }
|
|
|
+
|
|
|
+ setExpantOtherDeleteOptionsState(deletionType, bool) {
|
|
|
+ const { adminGeneralSecurityContainer } = this.props;
|
|
|
+
|
|
|
+ if (isTypeDeletion(deletionType)) {
|
|
|
+ adminGeneralSecurityContainer.switchExpandOtherOptionsForDeletion(bool);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ adminGeneralSecurityContainer.switchExpandOtherOptionsForCompleteDeletion(bool);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 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);
|
|
|
+ setState(newState);
|
|
|
|
|
|
+ if (this.previousPageRecursiveAuthorityState(deletionType) !== null) {
|
|
|
+ this.setPagePreviousRecursiveAuthorityState(deletionType, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isRecursiveDeletion(deletionType)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const [recursiveState, setRecursiveState] = this.getRecursiveDeletionConfigState(deletionType);
|
|
|
- const shouldForceUpdate = !validateDeleteConfigs(newState, recursiveState);
|
|
|
+
|
|
|
+ const calculableValue = prepareDeleteConfigValuesForCalc(newState, recursiveState);
|
|
|
+ const shouldForceUpdate = !validateDeleteConfigs(calculableValue[0], calculableValue[1]);
|
|
|
if (shouldForceUpdate) {
|
|
|
- setState(newState);
|
|
|
setRecursiveState(newState);
|
|
|
- }
|
|
|
- else {
|
|
|
- setState(newState);
|
|
|
+ this.setPagePreviousRecursiveAuthorityState(deletionType, recursiveState);
|
|
|
+ this.setExpantOtherDeleteOptionsState(deletionType, true);
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
@@ -133,10 +196,7 @@ class SecuritySetting extends React.Component {
|
|
|
aria-expanded="true"
|
|
|
>
|
|
|
<span className="float-left">
|
|
|
- {currentState === PageDeleteConfigValue.Inherit && t('security_setting.inherit')}
|
|
|
- {(currentState === PageDeleteConfigValue.Anyone || currentState == null) && t('security_setting.anyone')}
|
|
|
- {currentState === PageDeleteConfigValue.AdminOnly && t('security_setting.admin_only')}
|
|
|
- {currentState === PageDeleteConfigValue.AdminAndAuthor && t('security_setting.admin_and_author')}
|
|
|
+ {t(getDeleteConfigValueForT(currentState))}
|
|
|
</span>
|
|
|
</button>
|
|
|
<div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
|
|
@@ -184,20 +244,9 @@ class SecuritySetting extends React.Component {
|
|
|
}
|
|
|
|
|
|
renderPageDeletePermission(currentState, setState, deletionType, isButtonDisabled) {
|
|
|
- const { t, adminGeneralSecurityContainer } = this.props;
|
|
|
-
|
|
|
- const expandOtherOptions = isTypeDeletion(deletionType)
|
|
|
- ? adminGeneralSecurityContainer.state.expandOtherOptionsForDeletion
|
|
|
- : adminGeneralSecurityContainer.state.expandOtherOptionsForCompleteDeletion;
|
|
|
+ const { t } = this.props;
|
|
|
|
|
|
- const setExpantOtherOptions = () => {
|
|
|
- if (isTypeDeletion(deletionType)) {
|
|
|
- adminGeneralSecurityContainer.switchExpandOtherOptionsForDeletion();
|
|
|
- return;
|
|
|
- }
|
|
|
- adminGeneralSecurityContainer.switchExpandOtherOptionsForCompleteDeletion();
|
|
|
- return;
|
|
|
- };
|
|
|
+ const expantDeleteOptionsState = this.expantDeleteOptionsState(deletionType);
|
|
|
|
|
|
return (
|
|
|
<div key={`page-delete-permission-dropdown-${deletionType}`} className="row">
|
|
|
@@ -223,13 +272,30 @@ class SecuritySetting extends React.Component {
|
|
|
type="button"
|
|
|
className="btn btn-link p-0 mb-4"
|
|
|
aria-expanded="false"
|
|
|
- onClick={() => setExpantOtherOptions()}
|
|
|
+ onClick={() => this.setExpantOtherDeleteOptionsState(deletionType, !expantDeleteOptionsState)}
|
|
|
>
|
|
|
- <i className={`fa fa-fw fa-arrow-right ${expandOtherOptions ? 'fa-rotate-90' : ''}`}></i>
|
|
|
+ <i className={`fa fa-fw fa-arrow-right ${expantDeleteOptionsState ? 'fa-rotate-90' : ''}`}></i>
|
|
|
{ t('security_setting.other_options') }
|
|
|
</button>
|
|
|
- <Collapse isOpen={expandOtherOptions}>
|
|
|
+ <Collapse isOpen={expantDeleteOptionsState}>
|
|
|
<div className="pb-4">
|
|
|
+ <p className="card well">
|
|
|
+ <span className="text-warning">
|
|
|
+ <i className="icon-info"></i>
|
|
|
+ {/* eslint-disable-next-line react/no-danger */}
|
|
|
+ <span dangerouslySetInnerHTML={{ __html: t('security_setting.page_delete_rights_caution') }} />
|
|
|
+ </span>
|
|
|
+ </p>
|
|
|
+ { this.previousPageRecursiveAuthorityState(deletionType) !== null && (
|
|
|
+ <div className="mb-3">
|
|
|
+ <strong>
|
|
|
+ {t('security_setting.forced_update_desc')}
|
|
|
+ </strong>
|
|
|
+ <code>
|
|
|
+ {t(getDeleteConfigValueForT(this.previousPageRecursiveAuthorityState(deletionType)))}
|
|
|
+ </code>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
{this.renderPageDeletePermissionDropdown(currentState, setState, deletionType, isButtonDisabled)}
|
|
|
</div>
|
|
|
</Collapse>
|
|
|
@@ -368,8 +434,7 @@ class SecuritySetting extends React.Component {
|
|
|
</div>
|
|
|
|
|
|
<h4>{t('security_setting.page_delete_rights')}</h4>
|
|
|
- <div className="row mb-4"></div>
|
|
|
- {/* Render PageDeletePermissionDropdown */}
|
|
|
+ {/* Render PageDeletePermission */}
|
|
|
{
|
|
|
[
|
|
|
[currentPageDeletionAuthority, adminGeneralSecurityContainer.changePageDeletionAuthority, DeletionType.Deletion, false],
|