SecuritySetting.jsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /* eslint-disable react/no-danger */
  2. import React from 'react';
  3. import { useTranslation } from 'next-i18next';
  4. import PropTypes from 'prop-types';
  5. import { Collapse } from 'reactstrap';
  6. import AdminGeneralSecurityContainer from '~/client/services/AdminGeneralSecurityContainer';
  7. import { toastSuccess, toastError } from '~/client/util/toastr';
  8. import { PageDeleteConfigValue } from '~/interfaces/page-delete-config';
  9. import { validateDeleteConfigs, prepareDeleteConfigValuesForCalc } from '~/utils/page-delete-config';
  10. import { withUnstatedContainers } from '../../UnstatedUtils';
  11. // used as the prefix of translation
  12. const DeletionTypeForT = Object.freeze({
  13. Deletion: 'deletion',
  14. CompleteDeletion: 'complete_deletion',
  15. RecursiveDeletion: 'recursive_deletion',
  16. RecursiveCompleteDeletion: 'recursive_complete_deletion',
  17. });
  18. const DeletionType = Object.freeze({
  19. Deletion: 'deletion',
  20. CompleteDeletion: 'completeDeletion',
  21. RecursiveDeletion: 'recursiveDeletion',
  22. RecursiveCompleteDeletion: 'recursiveCompleteDeletion',
  23. });
  24. const getDeletionTypeForT = (deletionType) => {
  25. switch (deletionType) {
  26. case DeletionType.Deletion:
  27. return DeletionTypeForT.Deletion;
  28. case DeletionType.RecursiveDeletion:
  29. return DeletionTypeForT.RecursiveDeletion;
  30. case DeletionType.CompleteDeletion:
  31. return DeletionTypeForT.CompleteDeletion;
  32. case DeletionType.RecursiveCompleteDeletion:
  33. return DeletionTypeForT.RecursiveCompleteDeletion;
  34. }
  35. };
  36. const getDeleteConfigValueForT = (DeleteConfigValue) => {
  37. switch (DeleteConfigValue) {
  38. case PageDeleteConfigValue.Anyone:
  39. case null:
  40. return 'security_settings.anyone';
  41. case PageDeleteConfigValue.Inherit:
  42. return 'security_settings.inherit';
  43. case PageDeleteConfigValue.AdminOnly:
  44. return 'security_settings.admin_only';
  45. case PageDeleteConfigValue.AdminAndAuthor:
  46. return 'security_settings.admin_and_author';
  47. }
  48. };
  49. /**
  50. * Return true if "deletionType" is DeletionType.RecursiveDeletion or DeletionType.RecursiveCompleteDeletion.
  51. * @param deletionType Deletion type
  52. * @returns boolean
  53. */
  54. const isRecursiveDeletion = (deletionType) => {
  55. return deletionType === DeletionType.RecursiveDeletion || deletionType === DeletionType.RecursiveCompleteDeletion;
  56. };
  57. /**
  58. * Return true if "deletionType" is DeletionType.Deletion or DeletionType.RecursiveDeletion.
  59. * @param deletionType Deletion type
  60. * @returns boolean
  61. */
  62. const isTypeDeletion = (deletionType) => {
  63. return deletionType === DeletionType.Deletion || deletionType === DeletionType.RecursiveDeletion;
  64. };
  65. class SecuritySetting extends React.Component {
  66. constructor(props) {
  67. super(props);
  68. // functions
  69. this.putSecuritySetting = this.putSecuritySetting.bind(this);
  70. this.getRecursiveDeletionConfigState = this.getRecursiveDeletionConfigState.bind(this);
  71. this.previousPageRecursiveAuthorityState = this.previousPageRecursiveAuthorityState.bind(this);
  72. this.setPagePreviousRecursiveAuthorityState = this.setPagePreviousRecursiveAuthorityState.bind(this);
  73. this.expantDeleteOptionsState = this.expantDeleteOptionsState.bind(this);
  74. this.setExpantOtherDeleteOptionsState = this.setExpantOtherDeleteOptionsState.bind(this);
  75. this.setDeletionConfigState = this.setDeletionConfigState.bind(this);
  76. // render
  77. this.renderPageDeletePermission = this.renderPageDeletePermission.bind(this);
  78. this.renderPageDeletePermissionDropdown = this.renderPageDeletePermissionDropdown.bind(this);
  79. }
  80. async putSecuritySetting() {
  81. const { t, adminGeneralSecurityContainer } = this.props;
  82. try {
  83. await adminGeneralSecurityContainer.updateGeneralSecuritySetting();
  84. toastSuccess(t('security_settings.updated_general_security_setting'));
  85. }
  86. catch (err) {
  87. toastError(err);
  88. }
  89. }
  90. getRecursiveDeletionConfigState(deletionType) {
  91. const { adminGeneralSecurityContainer } = this.props;
  92. if (isTypeDeletion(deletionType)) {
  93. return [
  94. adminGeneralSecurityContainer.state.currentPageRecursiveDeletionAuthority,
  95. adminGeneralSecurityContainer.changePageRecursiveDeletionAuthority,
  96. ];
  97. }
  98. return [
  99. adminGeneralSecurityContainer.state.currentPageRecursiveCompleteDeletionAuthority,
  100. adminGeneralSecurityContainer.changePageRecursiveCompleteDeletionAuthority,
  101. ];
  102. }
  103. previousPageRecursiveAuthorityState(deletionType) {
  104. const { adminGeneralSecurityContainer } = this.props;
  105. return isTypeDeletion(deletionType)
  106. ? adminGeneralSecurityContainer.state.previousPageRecursiveDeletionAuthority
  107. : adminGeneralSecurityContainer.state.previousPageRecursiveCompleteDeletionAuthority;
  108. }
  109. setPagePreviousRecursiveAuthorityState(deletionType, previousState) {
  110. const { adminGeneralSecurityContainer } = this.props;
  111. if (isTypeDeletion(deletionType)) {
  112. adminGeneralSecurityContainer.changePreviousPageRecursiveDeletionAuthority(previousState);
  113. return;
  114. }
  115. adminGeneralSecurityContainer.changePreviousPageRecursiveCompleteDeletionAuthority(previousState);
  116. }
  117. expantDeleteOptionsState(deletionType) {
  118. const { adminGeneralSecurityContainer } = this.props;
  119. return isTypeDeletion(deletionType)
  120. ? adminGeneralSecurityContainer.state.expandOtherOptionsForDeletion
  121. : adminGeneralSecurityContainer.state.expandOtherOptionsForCompleteDeletion;
  122. }
  123. setExpantOtherDeleteOptionsState(deletionType, bool) {
  124. const { adminGeneralSecurityContainer } = this.props;
  125. if (isTypeDeletion(deletionType)) {
  126. adminGeneralSecurityContainer.switchExpandOtherOptionsForDeletion(bool);
  127. return;
  128. }
  129. adminGeneralSecurityContainer.switchExpandOtherOptionsForCompleteDeletion(bool);
  130. return;
  131. }
  132. /**
  133. * Force update deletion config for recursive operation when the deletion config for general operation is updated.
  134. * @param deletionType Deletion type
  135. */
  136. setDeletionConfigState(newState, setState, deletionType) {
  137. setState(newState);
  138. if (this.previousPageRecursiveAuthorityState(deletionType) !== null) {
  139. this.setPagePreviousRecursiveAuthorityState(deletionType, null);
  140. }
  141. if (isRecursiveDeletion(deletionType)) {
  142. return;
  143. }
  144. const [recursiveState, setRecursiveState] = this.getRecursiveDeletionConfigState(deletionType);
  145. const calculableValue = prepareDeleteConfigValuesForCalc(newState, recursiveState);
  146. const shouldForceUpdate = !validateDeleteConfigs(calculableValue[0], calculableValue[1]);
  147. if (shouldForceUpdate) {
  148. setRecursiveState(newState);
  149. this.setPagePreviousRecursiveAuthorityState(deletionType, recursiveState);
  150. this.setExpantOtherDeleteOptionsState(deletionType, true);
  151. }
  152. return;
  153. }
  154. renderPageDeletePermissionDropdown(currentState, setState, deletionType, isButtonDisabled) {
  155. const { t } = this.props;
  156. return (
  157. <div className="dropdown">
  158. <button
  159. className="btn btn-outline-secondary dropdown-toggle text-end"
  160. type="button"
  161. id="dropdownMenuButton"
  162. data-bs-toggle="dropdown"
  163. aria-haspopup="true"
  164. aria-expanded="true"
  165. >
  166. <span className="float-start">
  167. {t(getDeleteConfigValueForT(currentState))}
  168. </span>
  169. </button>
  170. <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
  171. {
  172. isRecursiveDeletion(deletionType)
  173. ? (
  174. <button
  175. className="dropdown-item"
  176. type="button"
  177. onClick={() => { this.setDeletionConfigState(PageDeleteConfigValue.Inherit, setState, deletionType) }}
  178. >
  179. {t('security_settings.inherit')}
  180. </button>
  181. )
  182. : (
  183. <button
  184. className="dropdown-item"
  185. type="button"
  186. onClick={() => { this.setDeletionConfigState(PageDeleteConfigValue.Anyone, setState, deletionType) }}
  187. >
  188. {t('security_settings.anyone')}
  189. </button>
  190. )
  191. }
  192. <button
  193. className={`dropdown-item ${isButtonDisabled ? 'disabled' : ''}`}
  194. type="button"
  195. onClick={() => { this.setDeletionConfigState(PageDeleteConfigValue.AdminAndAuthor, setState, deletionType) }}
  196. >
  197. {t('security_settings.admin_and_author')}
  198. </button>
  199. <button
  200. className="dropdown-item"
  201. type="button"
  202. onClick={() => { this.setDeletionConfigState(PageDeleteConfigValue.AdminOnly, setState, deletionType) }}
  203. >
  204. {t('security_settings.admin_only')}
  205. </button>
  206. </div>
  207. <p className="form-text text-muted small">
  208. {t(`security_settings.${getDeletionTypeForT(deletionType)}_explanation`)}
  209. </p>
  210. </div>
  211. );
  212. }
  213. renderPageDeletePermission(currentState, setState, deletionType, isButtonDisabled) {
  214. const { t, adminGeneralSecurityContainer } = this.props;
  215. const expantDeleteOptionsState = this.expantDeleteOptionsState(deletionType);
  216. return (
  217. <div key={`page-delete-permission-dropdown-${deletionType}`} className="row">
  218. <div className="col-md-4 text-md-end">
  219. {!isRecursiveDeletion(deletionType) && isTypeDeletion(deletionType) && (
  220. <strong>{t('security_settings.page_delete')}</strong>
  221. )}
  222. {!isRecursiveDeletion(deletionType) && !isTypeDeletion(deletionType) && (
  223. <strong>{t('security_settings.page_delete_completely')}</strong>
  224. )}
  225. </div>
  226. <div className="col-md-8">
  227. {
  228. !isRecursiveDeletion(deletionType)
  229. ? (
  230. <>
  231. {this.renderPageDeletePermissionDropdown(currentState, setState, deletionType, isButtonDisabled)}
  232. {currentState === PageDeleteConfigValue.Anyone && deletionType === DeletionType.CompleteDeletion && (
  233. <>
  234. <input
  235. id="isAllGroupMembershipRequiredForPageCompleteDeletionCheckbox"
  236. className="form-check-input"
  237. type="checkbox"
  238. checked={adminGeneralSecurityContainer.state.isAllGroupMembershipRequiredForPageCompleteDeletion}
  239. onChange={() => { adminGeneralSecurityContainer.switchIsAllGroupMembershipRequiredForPageCompleteDeletion() }}
  240. />
  241. <label className="form-check-label" htmlFor="isAllGroupMembershipRequiredForPageCompleteDeletionCheckbox">
  242. {t('security_settings.is_all_group_membership_required_for_page_complete_deletion')}
  243. </label>
  244. <p
  245. className="form-text text-muted small mt-2"
  246. >
  247. {t('security_settings.is_all_group_membership_required_for_page_complete_deletion_explanation')}
  248. </p>
  249. </>
  250. )}
  251. </>
  252. )
  253. : (
  254. <>
  255. <button
  256. type="button"
  257. className="btn btn-link p-0 mb-4"
  258. aria-expanded="false"
  259. onClick={() => this.setExpantOtherDeleteOptionsState(deletionType, !expantDeleteOptionsState)}
  260. >
  261. <span className={`material-symbols-outlined me-1 ${expantDeleteOptionsState ? 'rotate-90' : ''}`}>navigate_next</span>
  262. {t('security_settings.other_options')}
  263. </button>
  264. <Collapse isOpen={expantDeleteOptionsState}>
  265. <div className="pb-4">
  266. <p className="card custom-card bg-warning-sublte">
  267. <span className="text-warning">
  268. <span className="material-symbols-outlined">info</span>
  269. {/* eslint-disable-next-line react/no-danger */}
  270. <span dangerouslySetInnerHTML={{ __html: t('security_settings.page_delete_rights_caution') }} />
  271. </span>
  272. </p>
  273. {this.previousPageRecursiveAuthorityState(deletionType) !== null && (
  274. <div className="mb-3">
  275. <strong>
  276. {t('security_settings.forced_update_desc')}
  277. </strong>
  278. <code>
  279. {t(getDeleteConfigValueForT(this.previousPageRecursiveAuthorityState(deletionType)))}
  280. </code>
  281. </div>
  282. )}
  283. {this.renderPageDeletePermissionDropdown(currentState, setState, deletionType, isButtonDisabled)}
  284. </div>
  285. </Collapse>
  286. </>
  287. )
  288. }
  289. </div>
  290. </div>
  291. );
  292. }
  293. render() {
  294. const { t, adminGeneralSecurityContainer } = this.props;
  295. const {
  296. currentRestrictGuestMode, currentPageDeletionAuthority, currentPageCompleteDeletionAuthority,
  297. currentPageRecursiveDeletionAuthority, currentPageRecursiveCompleteDeletionAuthority, isRomUserAllowedToComment,
  298. } = adminGeneralSecurityContainer.state;
  299. const isButtonDisabledForDeletion = !validateDeleteConfigs(
  300. adminGeneralSecurityContainer.state.currentPageDeletionAuthority, PageDeleteConfigValue.AdminAndAuthor,
  301. );
  302. const isButtonDisabledForCompleteDeletion = !validateDeleteConfigs(
  303. adminGeneralSecurityContainer.state.currentPageCompleteDeletionAuthority, PageDeleteConfigValue.AdminAndAuthor,
  304. );
  305. return (
  306. <React.Fragment>
  307. <h2 className="alert-anchor border-bottom">
  308. {t('security_settings.security_settings')}
  309. </h2>
  310. {adminGeneralSecurityContainer.retrieveError != null && (
  311. <div className="alert alert-danger">
  312. <p>{t('Error occurred')} : {adminGeneralSecurityContainer.retrieveError}</p>
  313. </div>
  314. )}
  315. <h4 className="alert-anchor border-bottom mt-4">{t('security_settings.page_list_and_search_results')}</h4>
  316. <div className="row mb-4">
  317. <div className="col-md-10">
  318. <div className="row">
  319. {/* Left Column: Labels */}
  320. <div className="col-5 d-flex flex-column align-items-end p-4">
  321. <div className="fw-bold mb-4">{t('public')}</div>
  322. <div className="fw-bold mb-4">{t('anyone_with_the_link')}</div>
  323. <div className="fw-bold mb-4">{t('only_me')}</div>
  324. <div className="fw-bold">{t('only_inside_the_group')}</div>
  325. </div>
  326. {/* Right Column: Content */}
  327. <div className="col-7 d-flex flex-column align-items-start pt-4 pb-4">
  328. <div className="mb-4 d-flex align-items-center">
  329. <span className="material-symbols-outlined text-success me-1"></span>
  330. {t('security_settings.always_displayed')}
  331. </div>
  332. <div className="mb-3 d-flex align-items-center">
  333. <span className="material-symbols-outlined text-danger me-1"></span>
  334. {t('security_settings.always_hidden')}
  335. </div>
  336. {/* Owner Restriction Dropdown */}
  337. <div className="mb-3">
  338. <div className="dropdown">
  339. <button
  340. className="btn btn-outline-secondary dropdown-toggle text-end col-12 col-md-auto"
  341. type="button"
  342. id="isShowRestrictedByOwner"
  343. data-bs-toggle="dropdown"
  344. aria-haspopup="true"
  345. aria-expanded="true"
  346. >
  347. <span className="float-start">
  348. {adminGeneralSecurityContainer.state.currentOwnerRestrictionDisplayMode === 'Displayed' && t('security_settings.always_displayed')}
  349. {adminGeneralSecurityContainer.state.currentOwnerRestrictionDisplayMode === 'Hidden' && t('security_settings.always_hidden')}
  350. </span>
  351. </button>
  352. <div className="dropdown-menu" aria-labelledby="isShowRestrictedByOwner">
  353. <button
  354. className="dropdown-item"
  355. type="button"
  356. onClick={() => { adminGeneralSecurityContainer.changeOwnerRestrictionDisplayMode('Displayed') }}
  357. >
  358. {t('security_settings.always_displayed')}
  359. </button>
  360. <button
  361. className="dropdown-item"
  362. type="button"
  363. onClick={() => { adminGeneralSecurityContainer.changeOwnerRestrictionDisplayMode('Hidden') }}
  364. >
  365. {t('security_settings.always_hidden')}
  366. </button>
  367. </div>
  368. </div>
  369. </div>
  370. {/* Group Restriction Dropdown */}
  371. <div className="">
  372. <div className="dropdown">
  373. <button
  374. className="btn btn-outline-secondary dropdown-toggle text-end col-12 col-md-auto"
  375. type="button"
  376. id="isShowRestrictedByGroup"
  377. data-bs-toggle="dropdown"
  378. aria-haspopup="true"
  379. aria-expanded="true"
  380. >
  381. <span className="float-start">
  382. {adminGeneralSecurityContainer.state.currentGroupRestrictionDisplayMode === 'Displayed' && t('security_settings.always_displayed')}
  383. {adminGeneralSecurityContainer.state.currentGroupRestrictionDisplayMode === 'Hidden' && t('security_settings.always_hidden')}
  384. </span>
  385. </button>
  386. <div className="dropdown-menu" aria-labelledby="isShowRestrictedByGroup">
  387. <button
  388. className="dropdown-item"
  389. type="button"
  390. onClick={() => { adminGeneralSecurityContainer.changeGroupRestrictionDisplayMode('Displayed') }}
  391. >
  392. {t('security_settings.always_displayed')}
  393. </button>
  394. <button
  395. className="dropdown-item"
  396. type="button"
  397. onClick={() => { adminGeneralSecurityContainer.changeGroupRestrictionDisplayMode('Hidden') }}
  398. >
  399. {t('security_settings.always_hidden')}
  400. </button>
  401. </div>
  402. </div>
  403. </div>
  404. </div>
  405. </div>
  406. </div>
  407. </div>
  408. <h4 className="mb-3">{t('security_settings.page_access_rights')}</h4>
  409. <div className="row mb-4">
  410. <div className="col-md-4 text-md-end py-2">
  411. <strong>{t('security_settings.Guest Users Access')}</strong>
  412. </div>
  413. <div className="col-md-8">
  414. <div className="dropdown">
  415. <button
  416. className={`btn btn-outline-secondary dropdown-toggle text-end col-12
  417. col-md-auto ${adminGeneralSecurityContainer.isWikiModeForced && 'disabled'}`}
  418. type="button"
  419. id="dropdownMenuButton"
  420. data-bs-toggle="dropdown"
  421. aria-haspopup="true"
  422. aria-expanded="true"
  423. >
  424. <span className="float-start">
  425. {currentRestrictGuestMode === 'Deny' && t('security_settings.guest_mode.deny')}
  426. {currentRestrictGuestMode === 'Readonly' && t('security_settings.guest_mode.readonly')}
  427. </span>
  428. </button>
  429. <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
  430. <button className="dropdown-item" type="button" onClick={() => { adminGeneralSecurityContainer.changeRestrictGuestMode('Deny') }}>
  431. {t('security_settings.guest_mode.deny')}
  432. </button>
  433. <button className="dropdown-item" type="button" onClick={() => { adminGeneralSecurityContainer.changeRestrictGuestMode('Readonly') }}>
  434. {t('security_settings.guest_mode.readonly')}
  435. </button>
  436. </div>
  437. </div>
  438. {adminGeneralSecurityContainer.isWikiModeForced && (
  439. <p className="alert alert-warning mt-2 col-6">
  440. <span className="material-symbols-outlined me-1">error</span>
  441. <b>FIXED</b><br />
  442. <b
  443. dangerouslySetInnerHTML={{
  444. __html: t('security_settings.Fixed by env var',
  445. { key: 'FORCE_WIKI_MODE', value: adminGeneralSecurityContainer.state.wikiMode }),
  446. }}
  447. />
  448. </p>
  449. )}
  450. </div>
  451. </div>
  452. <h4 className="mb-3">{t('security_settings.page_delete_rights')}</h4>
  453. {/* Render PageDeletePermission */}
  454. {
  455. [
  456. [currentPageDeletionAuthority, adminGeneralSecurityContainer.changePageDeletionAuthority, DeletionType.Deletion, false],
  457. // eslint-disable-next-line max-len
  458. [currentPageRecursiveDeletionAuthority, adminGeneralSecurityContainer.changePageRecursiveDeletionAuthority, DeletionType.RecursiveDeletion, isButtonDisabledForDeletion],
  459. ].map(arr => this.renderPageDeletePermission(arr[0], arr[1], arr[2], arr[3]))
  460. }
  461. {
  462. [
  463. [currentPageCompleteDeletionAuthority, adminGeneralSecurityContainer.changePageCompleteDeletionAuthority, DeletionType.CompleteDeletion, false],
  464. // eslint-disable-next-line max-len
  465. [currentPageRecursiveCompleteDeletionAuthority, adminGeneralSecurityContainer.changePageRecursiveCompleteDeletionAuthority, DeletionType.RecursiveCompleteDeletion, isButtonDisabledForCompleteDeletion],
  466. ].map(arr => this.renderPageDeletePermission(arr[0], arr[1], arr[2], arr[3]))
  467. }
  468. <h4 className="mb-3">{t('security_settings.user_homepage_deletion.user_homepage_deletion')}</h4>
  469. <div className="row mb-4">
  470. <div className="col-md-10 offset-md-2">
  471. <div className="form-check form-switch form-check-success">
  472. <input
  473. type="checkbox"
  474. className="form-check-input"
  475. id="is-user-page-deletion-enabled"
  476. checked={adminGeneralSecurityContainer.state.isUsersHomepageDeletionEnabled}
  477. onChange={() => { adminGeneralSecurityContainer.switchIsUsersHomepageDeletionEnabled() }}
  478. />
  479. <label className="form-label form-check-label" htmlFor="is-user-page-deletion-enabled">
  480. {t('security_settings.user_homepage_deletion.enable_user_homepage_deletion')}
  481. </label>
  482. </div>
  483. <div className="custom-control custom-switch custom-checkbox-success mt-2">
  484. <input
  485. type="checkbox"
  486. className="form-check-input"
  487. id="is-force-delete-user-homepage-on-user-deletion"
  488. checked={adminGeneralSecurityContainer.state.isForceDeleteUserHomepageOnUserDeletion}
  489. onChange={() => { adminGeneralSecurityContainer.switchIsForceDeleteUserHomepageOnUserDeletion() }}
  490. disabled={!adminGeneralSecurityContainer.state.isUsersHomepageDeletionEnabled}
  491. />
  492. <label className="form-check-label" htmlFor="is-force-delete-user-homepage-on-user-deletion">
  493. {t('security_settings.user_homepage_deletion.enable_force_delete_user_homepage_on_user_deletion')}
  494. </label>
  495. </div>
  496. <p
  497. className="form-text text-muted small mt-2"
  498. dangerouslySetInnerHTML={{ __html: t('security_settings.user_homepage_deletion.desc') }}
  499. />
  500. </div>
  501. </div>
  502. <h4 className="mb-3">{t('security_settings.comment_manage_rights')}</h4>
  503. <div className="row mb-4">
  504. <div className="col-md-4 text-md-end py-2">
  505. <strong>{t('security_settings.readonly_users_access')}</strong>
  506. </div>
  507. <div className="col-md-8">
  508. <div className="dropdown">
  509. <button
  510. className={`btn btn-outline-secondary dropdown-toggle text-end col-12
  511. col-md-auto ${adminGeneralSecurityContainer.isWikiModeForced && 'disabled'}`}
  512. type="button"
  513. id="dropdownMenuButton"
  514. data-bs-toggle="dropdown"
  515. aria-haspopup="true"
  516. aria-expanded="true"
  517. >
  518. <span className="float-start">
  519. {isRomUserAllowedToComment === true && t('security_settings.read_only_users_comment.accept')}
  520. {isRomUserAllowedToComment === false && t('security_settings.read_only_users_comment.deny')}
  521. </span>
  522. </button>
  523. <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
  524. <button className="dropdown-item" type="button" onClick={() => { adminGeneralSecurityContainer.switchIsRomUserAllowedToComment(false) }}>
  525. {t('security_settings.read_only_users_comment.deny')}
  526. </button>
  527. <button className="dropdown-item" type="button" onClick={() => { adminGeneralSecurityContainer.switchIsRomUserAllowedToComment(true) }}>
  528. {t('security_settings.read_only_users_comment.accept')}
  529. </button>
  530. </div>
  531. </div>
  532. </div>
  533. </div>
  534. <h4>{t('security_settings.session')}</h4>
  535. <div className="row">
  536. <label className="text-start text-md-end col-md-3 col-form-label">{t('security_settings.max_age')}</label>
  537. <div className="col-md-8">
  538. <input
  539. className="form-control col-md-4"
  540. type="text"
  541. value={adminGeneralSecurityContainer.state.sessionMaxAge || ''}
  542. onChange={(e) => {
  543. adminGeneralSecurityContainer.setSessionMaxAge(e.target.value);
  544. }}
  545. placeholder="2592000000"
  546. />
  547. {/* eslint-disable-next-line react/no-danger */}
  548. <p className="form-text text-muted" dangerouslySetInnerHTML={{ __html: t('security_settings.max_age_desc') }} />
  549. <p className="card custom-card bg-warning-subtle">
  550. <span className="text-warning">
  551. <span className="material-symbols-outlined">info</span> {t('security_settings.max_age_caution')}
  552. </span>
  553. </p>
  554. </div>
  555. </div>
  556. <div className="row my-3">
  557. <div className="text-center text-md-start offset-md-3 col-md-5">
  558. <button type="button" className="btn btn-primary" disabled={adminGeneralSecurityContainer.retrieveError != null} onClick={this.putSecuritySetting}>
  559. {t('Update')}
  560. </button>
  561. </div>
  562. </div>
  563. </React.Fragment>
  564. );
  565. }
  566. }
  567. SecuritySetting.propTypes = {
  568. t: PropTypes.func.isRequired, // i18next
  569. adminGeneralSecurityContainer: PropTypes.instanceOf(AdminGeneralSecurityContainer).isRequired,
  570. };
  571. const SecuritySettingWrapperFC = (props) => {
  572. const { t } = useTranslation('admin');
  573. return <SecuritySetting t={t} {...props} />;
  574. };
  575. const SecuritySettingWrapper = withUnstatedContainers(SecuritySettingWrapperFC, [AdminGeneralSecurityContainer]);
  576. export default SecuritySettingWrapper;