SecuritySetting.jsx 8.8 KB

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