AdminGeneralSecurityContainer.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 (SecurityManagement.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: ' ',
  18. hideRestrictedByOwner: true,
  19. hideRestrictedByGroup: true,
  20. useOnlyEnvVarsForSomeOptions: true,
  21. isLocalEnabled: true,
  22. registrationMode: 'open',
  23. registrationWhiteList: '',
  24. isLdapEnabled: true,
  25. isSamlEnabled: true,
  26. };
  27. this.init();
  28. this.switchIsLocalEnabled = this.switchIsLocalEnabled.bind(this);
  29. this.changeRegistrationMode = this.changeRegistrationMode.bind(this);
  30. this.changeRestrictGuestMode = this.changeRestrictGuestMode.bind(this);
  31. }
  32. init() {
  33. // TODO GW-583 fetch config value with api
  34. }
  35. /**
  36. * Workaround for the mangling in production build to break constructor.name
  37. */
  38. static getClassName() {
  39. return 'AdminGeneralSecurityContainer';
  40. }
  41. /**
  42. * Switch local enabled
  43. */
  44. switchIsLocalEnabled() {
  45. this.setState({ isLocalEnabled: !this.state.isLocalEnabled });
  46. }
  47. /**
  48. * Change registration mode
  49. */
  50. changeRegistrationMode(value) {
  51. this.setState({ registrationMode: value });
  52. }
  53. /**
  54. * Switch LDAP enabled
  55. */
  56. switchIsLdapEnabled() {
  57. this.setState({ isLdapEnabled: !this.state.isLdapEnabled });
  58. }
  59. /**
  60. * Switch SAML enabled
  61. */
  62. switchIsSamlEnabled() {
  63. this.setState({ isSamlEnabled: !this.state.isSamlEnabled });
  64. }
  65. /**
  66. * Change restrictGuestMode
  67. */
  68. changeRestrictGuestMode(restrictGuestModeLabel) {
  69. this.setState({ currentRestrictGuestMode: restrictGuestModeLabel });
  70. }
  71. /**
  72. * Switch pageCompleteDeletionAuthority
  73. */
  74. switchPageCompleteDeletionAuthority(pageCompleteDeletionAuthorityLabel) {
  75. this.setState({ currentpageCompleteDeletionAuthority: pageCompleteDeletionAuthorityLabel });
  76. }
  77. /**
  78. * Switch hideRestrictedByOwner
  79. */
  80. switchHideRestrictedByOwner() {
  81. this.setState({ hideRestrictedByOwner: !this.state.hideRestrictedByOwner });
  82. }
  83. /**
  84. * Switch hideRestrictedByGroup
  85. */
  86. switchHideRestrictedByGroup() {
  87. this.setState({ hideRestrictedByGroup: !this.state.hideRestrictedByGroup });
  88. }
  89. /**
  90. * Update restrictGuestMode
  91. * @memberOf AdminSecuritySettingContainer
  92. * @return {string} Appearance
  93. */
  94. async updateRestrictGuestMode() {
  95. const response = await this.appContainer.apiv3.put('/security-setting/guest-mode', {
  96. restrictGuestMode: this.state.currentRestrictGuestMode,
  97. });
  98. const { securitySettingParams } = response.data;
  99. return securitySettingParams;
  100. }
  101. /**
  102. * Update pageDeletion
  103. * @memberOf AdminSecuritySettingContainer
  104. * @return {string} pageDeletion
  105. */
  106. async updatePageCompleteDeletionAuthority() {
  107. const response = await this.appContainer.apiv3.put('/security-setting/page-deletion', {
  108. pageCompleteDeletionAuthority: this.state.currentPageCompleteDeletionAuthority,
  109. });
  110. const { securitySettingParams } = response.data;
  111. return securitySettingParams;
  112. }
  113. /**
  114. * Update function
  115. * @memberOf AdminSecucitySettingContainer
  116. * @return {string} Functions
  117. */
  118. async updateSecurityFunction() {
  119. const response = await this.appContainer.apiv3.put('/security-setting/function', {
  120. hideRestrictedByGroup: this.state.hideRestrictedByGroup,
  121. hideRestrictedByOwner: this.state.hideRestrictedByOwner,
  122. });
  123. const { securitySettingParams } = response.data;
  124. return securitySettingParams;
  125. }
  126. }