AdminGeneralSecurityContainer.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { Container } from 'unstated';
  2. import loggerFactory from '@alias/logger';
  3. // eslint-disable-next-line no-unused-vars
  4. const logger = loggerFactory('growi:security:AdminGeneralSecurityContainer');
  5. /**
  6. * Service container for admin security page (SecuritySetting.jsx)
  7. * @extends {Container} unstated Container
  8. */
  9. export default class AdminGeneralSecurityContainer extends Container {
  10. constructor(appContainer) {
  11. super();
  12. this.appContainer = appContainer;
  13. this.state = {
  14. // TODO GW-583 set value
  15. isWikiModeForced: false,
  16. currentRestrictGuestMode: 'deny',
  17. currentPageCompleteDeletionAuthority: 'anyone',
  18. isHideRestrictedByOwner: true,
  19. isHideRestrictedByGroup: true,
  20. useOnlyEnvVarsForSomeOptions: true,
  21. appSiteUrl: appContainer.config.crowi.url || '',
  22. isLocalEnabled: true,
  23. registrationMode: 'open',
  24. registrationWhiteList: '',
  25. isLdapEnabled: true,
  26. isSamlEnabled: true,
  27. isOidcEnabled: true,
  28. isBasicEnabled: true,
  29. isGoogleOAuthEnabled: true,
  30. isGithubOAuthEnabled: true,
  31. isTwitterOAuthEnabled: true,
  32. };
  33. this.init();
  34. this.switchIsLocalEnabled = this.switchIsLocalEnabled.bind(this);
  35. this.changeRegistrationMode = this.changeRegistrationMode.bind(this);
  36. this.changeRestrictGuestMode = this.changeRestrictGuestMode.bind(this);
  37. this.changePageCompleteDeletionAuthority = this.changePageCompleteDeletionAuthority.bind(this);
  38. this.switchIsHideRestrictedByGroup = this.switchIsHideRestrictedByGroup.bind(this);
  39. this.switchIsHideRestrictedByOwner = this.switchIsHideRestrictedByOwner.bind(this);
  40. this.changePageCompleteDeletionAuthority = this.changePageCompleteDeletionAuthority.bind(this);
  41. }
  42. init() {
  43. // TODO GW-583 fetch config value with api
  44. }
  45. /**
  46. * Workaround for the mangling in production build to break constructor.name
  47. */
  48. static getClassName() {
  49. return 'AdminGeneralSecurityContainer';
  50. }
  51. /**
  52. * Change restrictGuestMode
  53. */
  54. changeRestrictGuestMode(restrictGuestModeLabel) {
  55. this.setState({ currentRestrictGuestMode: restrictGuestModeLabel });
  56. }
  57. /**
  58. * Change pageCompleteDeletionAuthority
  59. */
  60. changePageCompleteDeletionAuthority(pageCompleteDeletionAuthorityLabel) {
  61. this.setState({ currentPageCompleteDeletionAuthority: pageCompleteDeletionAuthorityLabel });
  62. }
  63. /**
  64. * Switch hideRestrictedByOwner
  65. */
  66. switchIsHideRestrictedByOwner() {
  67. this.setState({ isHideRestrictedByOwner: !this.state.isHideRestrictedByOwner });
  68. }
  69. /**
  70. * Switch hideRestrictedByGroup
  71. */
  72. switchIsHideRestrictedByGroup() {
  73. this.setState({ isHideRestrictedByGroup: !this.state.isHideRestrictedByGroup });
  74. }
  75. /**
  76. * Update restrictGuestMode
  77. * @memberOf AdminGeneralSecuritySContainer
  78. * @return {string} Appearance
  79. */
  80. async updateGeneralSecuritySetting() {
  81. const response = await this.appContainer.apiv3.put('/security-setting/general-setting', {
  82. restrictGuestMode: this.state.currentRestrictGuestMode,
  83. pageCompleteDeletionAuthority: this.state.currentPageCompleteDeletionAuthority,
  84. hideRestrictedByGroup: this.state.isHideRestrictedByGroup,
  85. hideRestrictedByOwner: this.state.isHideRestrictedByOwner,
  86. });
  87. const { securitySettingParams } = response.data;
  88. return securitySettingParams;
  89. }
  90. /**
  91. * Switch local enabled
  92. */
  93. switchIsLocalEnabled() {
  94. this.setState({ isLocalEnabled: !this.state.isLocalEnabled });
  95. }
  96. /**
  97. * Change registration mode
  98. */
  99. changeRegistrationMode(value) {
  100. this.setState({ registrationMode: value });
  101. }
  102. /**
  103. * Switch LDAP enabled
  104. */
  105. switchIsLdapEnabled() {
  106. this.setState({ isLdapEnabled: !this.state.isLdapEnabled });
  107. }
  108. /**
  109. * Switch SAML enabled
  110. */
  111. switchIsSamlEnabled() {
  112. this.setState({ isSamlEnabled: !this.state.isSamlEnabled });
  113. }
  114. /**
  115. * Switch Oidc enabled
  116. */
  117. switchIsOidcEnabled() {
  118. this.setState({ isOidcEnabled: !this.state.isOidcEnabled });
  119. }
  120. /**
  121. * Switch Basic enabled
  122. */
  123. switchIsBasicEnabled() {
  124. this.setState({ isBasicEnabled: !this.state.isBasicEnabled });
  125. }
  126. /**
  127. * Switch GoogleOAuth enabled
  128. */
  129. switchIsGoogleOAuthEnabled() {
  130. this.setState({ isGoogleOAuthEnabled: !this.state.isGoogleOAuthEnabled });
  131. }
  132. /**
  133. * Switch GithubOAuth enabled
  134. */
  135. switchIsGithubOAuthEnabled() {
  136. this.setState({ isGithubOAuthEnabled: !this.state.isGithubOAuthEnabled });
  137. }
  138. /**
  139. * Switch TwitterOAuth enabled
  140. */
  141. switchIsTwitterOAuthEnabled() {
  142. this.setState({ isTwitterOAuthEnabled: !this.state.isTwitterOAuthEnabled });
  143. }
  144. }