SecuritySetting.jsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 col-lg-9">
  54. <thead>
  55. <tr>
  56. <th scope="col">{ t('Scope of page showing') }</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. {/* ゲストユーザーのアクセス */}
  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-6 ml-md-5">
  111. <div className="dropdown">
  112. <button
  113. className={`btn btn-outline-secondary dropdown-toggle ${adminGeneralSecurityContainer.isWikiModeForced && 'disabled'}`}
  114. type="button"
  115. id="dropdownMenuButton"
  116. data-toggle="dropdown"
  117. aria-haspopup="true"
  118. aria-expanded="true"
  119. >
  120. {currentRestrictGuestMode === 'Deny' && t('security_setting.guest_mode.deny')}
  121. {currentRestrictGuestMode === 'Readonly' && t('security_setting.guest_mode.readonly')}
  122. </button>
  123. <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
  124. <a className="dropdown-item" onClick={() => { adminGeneralSecurityContainer.changeRestrictGuestMode('Deny') }}>
  125. {t('security_setting.guest_mode.deny')}
  126. </a>
  127. <a className="dropdown-item" onClick={() => { adminGeneralSecurityContainer.changeRestrictGuestMode('Readonly') }}>
  128. {t('security_setting.guest_mode.readonly')}
  129. </a>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. {adminGeneralSecurityContainer.isWikiModeForced && (
  135. <div className="row mb-4">
  136. <div className="col-xs-offset-3 col-xs-6 text-left">
  137. <p className="alert alert-warning mt-2 text-left">
  138. <i className="icon-exclamation icon-fw">
  139. </i><b>FIXED</b><br />
  140. <b
  141. dangerouslySetInnerHTML={{
  142. __html: t('security_setting.Fixed by env var',
  143. { forcewikimode: 'FORCE_WIKI_MODE', wikimode: adminGeneralSecurityContainer.state.wikiMode }),
  144. }}
  145. />
  146. </p>
  147. </div>
  148. </div>
  149. )}
  150. <div className="row mb-4">
  151. <div className="col-md-3 text-md-right mb-2">
  152. <strong>{t('security_setting.complete_deletion')}</strong>
  153. </div>
  154. <div className="col-md-6 ml-md-5">
  155. <div className="dropdown">
  156. <button
  157. className="btn btn-outline-secondary dropdown-toggle"
  158. type="button"
  159. id="dropdownMenuButton"
  160. data-toggle="dropdown"
  161. aria-haspopup="true"
  162. aria-expanded="true"
  163. >
  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. </button>
  169. <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
  170. <a className="dropdown-item" onClick={() => { adminGeneralSecurityContainer.changePageCompleteDeletionAuthority('anyOne') }}>
  171. {t('security_setting.anyone')}
  172. </a>
  173. <a className="dropdown-item" onClick={() => { adminGeneralSecurityContainer.changePageCompleteDeletionAuthority('adminOnly') }}>
  174. {t('security_setting.admin_only')}
  175. </a>
  176. <a className="dropdown-item" onClick={() => { adminGeneralSecurityContainer.changePageCompleteDeletionAuthority('adminAndAuthor') }}>
  177. {t('security_setting.admin_and_author')}
  178. </a>
  179. </div>
  180. <p className="form-text text-muted small">
  181. {t('security_setting.complete_deletion_explain')}
  182. </p>
  183. </div>
  184. </div>
  185. </div>
  186. <div className="row my-3">
  187. <div className="offset-3 col-5">
  188. <button type="button" className="btn btn-primary" disabled={this.state.retrieveError != null} onClick={this.putSecuritySetting}>
  189. {t('Update')}
  190. </button>
  191. </div>
  192. </div>
  193. </React.Fragment>
  194. );
  195. }
  196. }
  197. SecuritySetting.propTypes = {
  198. t: PropTypes.func.isRequired, // i18next
  199. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  200. csrf: PropTypes.string,
  201. adminGeneralSecurityContainer: PropTypes.instanceOf(AdminGeneralSecurityContainer).isRequired,
  202. };
  203. const SecuritySettingWrapper = (props) => {
  204. return createSubscribedElement(SecuritySetting, props, [AppContainer, AdminGeneralSecurityContainer]);
  205. };
  206. export default withTranslation()(SecuritySettingWrapper);