AdminSecurityContainer.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { Container } from 'unstated';
  2. import loggerFactory from '@alias/logger';
  3. // eslint-disable-next-line no-unused-vars
  4. const logger = loggerFactory('growi:services:AdminSecurityContainer');
  5. /**
  6. * Service container for admin security page (SecurityManagement.jsx)
  7. * @extends {Container} unstated Container
  8. */
  9. export default class AdminSecurityContainer extends Container {
  10. constructor(appContainer) {
  11. super();
  12. this.appContainer = appContainer;
  13. this.state = {
  14. // TODO GW-583 set value
  15. useOnlyEnvVarsForSomeOptions: true,
  16. isLocalEnabled: true,
  17. registrationMode: 'open',
  18. registrationWhiteList: '',
  19. ldapConfig: {
  20. isEnabled: true,
  21. serverUrl: '',
  22. bindMode: 'manager',
  23. bindDN: '',
  24. bindDNPassword: '',
  25. },
  26. };
  27. this.init();
  28. this.switchIsLocalEnabled = this.switchIsLocalEnabled.bind(this);
  29. this.changeRegistrationMode = this.changeRegistrationMode.bind(this);
  30. this.switchIsLdapEnabled = this.switchIsLdapEnabled.bind(this);
  31. this.changeLdapBindMode = this.changeLdapBindMode.bind(this);
  32. }
  33. init() {
  34. // TODO GW-583 fetch config value with api
  35. }
  36. /**
  37. * Workaround for the mangling in production build to break constructor.name
  38. */
  39. static getClassName() {
  40. return 'AdminSecurityContainer';
  41. }
  42. /**
  43. * Switch local enabled
  44. */
  45. switchIsLocalEnabled() {
  46. this.setState({ isLocalEnabled: !this.state.isLocalEnabled });
  47. }
  48. /**
  49. * Change registration mode
  50. */
  51. changeRegistrationMode(value) {
  52. this.setState({ registrationMode: value });
  53. }
  54. // LDAP function
  55. /**
  56. * Switch local enabled
  57. */
  58. switchIsLdapEnabled() {
  59. const newLdapConfig = this.state.ldapConfig;
  60. newLdapConfig.isEnabled = !this.state.ldapConfig.isEnabled;
  61. this.setState({ newLdapConfig });
  62. }
  63. /**
  64. * Change server url
  65. */
  66. changeServerUrl(inputValue) {
  67. const newLdapConfig = this.state.ldapConfig;
  68. newLdapConfig.serverUrl = inputValue;
  69. this.setState({ newLdapConfig });
  70. }
  71. /**
  72. * Change ldap bind mode
  73. */
  74. changeLdapBindMode(mode) {
  75. const newLdapConfig = this.state.ldapConfig;
  76. newLdapConfig.bindMode = mode;
  77. this.setState({ newLdapConfig });
  78. }
  79. /**
  80. * Change bind DN
  81. */
  82. changeBindDN(inputValue) {
  83. const newLdapConfig = this.state.ldapConfig;
  84. newLdapConfig.bindDN = inputValue;
  85. this.setState({ newLdapConfig });
  86. }
  87. /**
  88. * Change bind DN password
  89. */
  90. changeBindDNPassword(inputValue) {
  91. const newLdapConfig = this.state.ldapConfig;
  92. newLdapConfig.bindDNPassword = inputValue;
  93. this.setState({ newLdapConfig });
  94. }
  95. }