SecuritySetting.jsx 9.8 KB

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