SecuritySetting.jsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /* eslint-disable react/no-danger */
  2. import React from 'react';
  3. import PropTypes from 'prop-types';
  4. import { withTranslation } from 'react-i18next';
  5. import { createSubscribedElement } from '../../UnstatedUtils';
  6. import { toastSuccess, toastError } from '../../../util/apiNotification';
  7. import AppContainer from '../../../services/AppContainer';
  8. import AdminGeneralSecurityContainer from '../../../services/AdminGeneralSecurityContainer';
  9. class SecuritySetting extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. retrieveError: null,
  14. };
  15. this.putSecuritySetting = this.putSecuritySetting.bind(this);
  16. }
  17. async componentDidMount() {
  18. const { adminGeneralSecurityContainer } = this.props;
  19. try {
  20. await adminGeneralSecurityContainer.retrieveSecurityData();
  21. }
  22. catch (err) {
  23. toastError(err);
  24. this.setState({ retrieveError: err.message });
  25. }
  26. }
  27. async putSecuritySetting() {
  28. const { t, adminGeneralSecurityContainer } = this.props;
  29. try {
  30. await adminGeneralSecurityContainer.updateGeneralSecuritySetting();
  31. toastSuccess(t('security_setting.updated_general_security_setting'));
  32. }
  33. catch (err) {
  34. toastError(err);
  35. }
  36. }
  37. render() {
  38. const { t, adminGeneralSecurityContainer } = this.props;
  39. const { currentRestrictGuestMode, currentPageCompleteDeletionAuthority } = adminGeneralSecurityContainer.state;
  40. return (
  41. <React.Fragment>
  42. <h2 className="alert-anchor border-bottom">
  43. {t('security_settings')}
  44. </h2>
  45. {this.state.retrieveError != null && (
  46. <div className="alert alert-danger">
  47. <p>{t('Error occurred')} : {this.state.retrieveError}</p>
  48. </div>
  49. )}
  50. <h4 className="mt-4">
  51. { t('page_list_and_search_results') }
  52. </h4>
  53. <table className="table table-bordered col-lg-9 mb-5">
  54. <thead>
  55. <tr>
  56. <th scope="col">{ t('scope_of_page_disclosure') }</th>
  57. <th scope="col">{ t('set_point') }</th>
  58. </tr>
  59. </thead>
  60. <tbody>
  61. <tr>
  62. <th scope="row">{ t('Public') }</th>
  63. <td>{ t('always_displayed') }</td>
  64. </tr>
  65. <tr>
  66. <th scope="row">{ t('Anyone with the link') }</th>
  67. <td>{ t('always_hidden') }</td>
  68. </tr>
  69. <tr>
  70. <th scope="row">{ t('Just me') }</th>
  71. <td>
  72. <div className="custom-control custom-switch custom-checkbox-success">
  73. <input
  74. type="checkbox"
  75. className="custom-control-input"
  76. id="isShowRestrictedByOwner"
  77. checked={adminGeneralSecurityContainer.state.isShowRestrictedByOwner}
  78. onChange={() => { adminGeneralSecurityContainer.switchIsShowRestrictedByOwner() }}
  79. />
  80. <label className="custom-control-label" htmlFor="isShowRestrictedByOwner">
  81. {t('displayed_or_hidden')}
  82. </label>
  83. </div>
  84. </td>
  85. </tr>
  86. <tr>
  87. <th scope="row">{ t('Only inside the group') }</th>
  88. <td>
  89. <div className="custom-control custom-switch custom-checkbox-success">
  90. <input
  91. type="checkbox"
  92. className="custom-control-input"
  93. id="isShowRestrictedByGroup"
  94. checked={adminGeneralSecurityContainer.state.isShowRestrictedByGroup}
  95. onChange={() => { adminGeneralSecurityContainer.switchIsShowRestrictedByGroup() }}
  96. />
  97. <label className="custom-control-label" htmlFor="isShowRestrictedByGroup">
  98. {t('displayed_or_hidden')}
  99. </label>
  100. </div>
  101. </td>
  102. </tr>
  103. </tbody>
  104. </table>
  105. <h4>{t('page_access_and_delete_rights')}</h4>
  106. <div className="row mb-4">
  107. <div className="col-md-3 text-md-right py-2">
  108. <strong>{t('security_setting.Guest Users Access')}</strong>
  109. </div>
  110. <div className="col-md-9">
  111. <div className="dropdown">
  112. <button
  113. className={`btn btn-outline-secondary dropdown-toggle text-right col-12
  114. col-md-auto ${adminGeneralSecurityContainer.isWikiModeForced && 'disabled'}`}
  115. type="button"
  116. id="dropdownMenuButton"
  117. data-toggle="dropdown"
  118. aria-haspopup="true"
  119. aria-expanded="true"
  120. >
  121. <span className="float-left">
  122. {currentRestrictGuestMode === 'Deny' && t('security_setting.guest_mode.deny')}
  123. {currentRestrictGuestMode === 'Readonly' && t('security_setting.guest_mode.readonly')}
  124. </span>
  125. </button>
  126. <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
  127. <button className="dropdown-item" type="button" onClick={() => { adminGeneralSecurityContainer.changeRestrictGuestMode('Deny') }}>
  128. {t('security_setting.guest_mode.deny')}
  129. </button>
  130. <button className="dropdown-item" type="button" onClick={() => { adminGeneralSecurityContainer.changeRestrictGuestMode('Readonly') }}>
  131. {t('security_setting.guest_mode.readonly')}
  132. </button>
  133. </div>
  134. </div>
  135. {adminGeneralSecurityContainer.isWikiModeForced && (
  136. <p className="alert alert-warning mt-2 text-left offset-3 col-6">
  137. <i className="icon-exclamation icon-fw">
  138. </i><b>FIXED</b><br />
  139. <b
  140. dangerouslySetInnerHTML={{
  141. __html: t('security_setting.Fixed by env var',
  142. { forcewikimode: 'FORCE_WIKI_MODE', wikimode: adminGeneralSecurityContainer.state.wikiMode }),
  143. }}
  144. />
  145. </p>
  146. )}
  147. </div>
  148. </div>
  149. <div className="row mb-4">
  150. <div className="col-md-3 text-md-right mb-2">
  151. <strong>{t('security_setting.complete_deletion')}</strong>
  152. </div>
  153. <div className="col-md-6">
  154. <div className="dropdown">
  155. <button
  156. className="btn btn-outline-secondary dropdown-toggle text-right col-12 col-md-auto"
  157. type="button"
  158. id="dropdownMenuButton"
  159. data-toggle="dropdown"
  160. aria-haspopup="true"
  161. aria-expanded="true"
  162. >
  163. <span className="float-left">
  164. {currentPageCompleteDeletionAuthority === 'anyOne' && t('security_setting.anyone')}
  165. {currentPageCompleteDeletionAuthority === 'adminOnly' && t('security_setting.admin_only')}
  166. {(currentPageCompleteDeletionAuthority === 'adminAndAuthor' || currentPageCompleteDeletionAuthority == null)
  167. && t('security_setting.admin_and_author')}
  168. </span>
  169. </button>
  170. <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
  171. <button className="dropdown-item" type="button" onClick={() => { adminGeneralSecurityContainer.changePageCompleteDeletionAuthority('anyOne') }}>
  172. {t('security_setting.anyone')}
  173. </button>
  174. <button
  175. className="dropdown-item"
  176. type="button"
  177. onClick={() => { adminGeneralSecurityContainer.changePageCompleteDeletionAuthority('adminOnly') }}
  178. >
  179. {t('security_setting.admin_only')}
  180. </button>
  181. <button
  182. className="dropdown-item"
  183. type="button"
  184. onClick={() => { adminGeneralSecurityContainer.changePageCompleteDeletionAuthority('adminAndAuthor') }}
  185. >
  186. {t('security_setting.admin_and_author')}
  187. </button>
  188. </div>
  189. <p className="form-text text-muted small">
  190. {t('security_setting.complete_deletion_explain')}
  191. </p>
  192. </div>
  193. </div>
  194. </div>
  195. <div className="row my-3">
  196. <div className="text-center text-md-left offset-md-3 col-md-5">
  197. <button type="button" className="btn btn-primary" disabled={this.state.retrieveError != null} onClick={this.putSecuritySetting}>
  198. {t('Update')}
  199. </button>
  200. </div>
  201. </div>
  202. </React.Fragment>
  203. );
  204. }
  205. }
  206. SecuritySetting.propTypes = {
  207. t: PropTypes.func.isRequired, // i18next
  208. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  209. csrf: PropTypes.string,
  210. adminGeneralSecurityContainer: PropTypes.instanceOf(AdminGeneralSecurityContainer).isRequired,
  211. };
  212. const SecuritySettingWrapper = (props) => {
  213. return createSubscribedElement(SecuritySetting, props, [AppContainer, AdminGeneralSecurityContainer]);
  214. };
  215. export default withTranslation()(SecuritySettingWrapper);