AdminSecuritySettingContainer.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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:AdminSecuritySettingContainer');
  5. /**
  6. * Service container for admin security setting page (SecuritySetting.jsx)
  7. * @extends {Container} unstated Container
  8. */
  9. export default class AdminSecuritySettingContainer extends Container {
  10. constructor(appContainer) {
  11. super();
  12. this.appContainer = appContainer;
  13. this.state = {
  14. // TODO GW-583 set Data from apiv3
  15. isWikiModeForced: false,
  16. currentRestrictGuestMode: 'deny',
  17. currentpageCompleteDeletionAuthority: 'anyone',
  18. isHideRestrictedByOwner: true,
  19. isHideRestrictedByGroup: true,
  20. };
  21. this.init();
  22. this.changeRestrictGuestMode = this.changeRestrictGuestMode.bind(this);
  23. this.switchIsHideRestrictedByGroup = this.switchIsHideRestrictedByGroup.bind(this);
  24. this.switchIsHideRestrictedByOwner = this.switchIsHideRestrictedByOwner.bind(this);
  25. this.changePageCompleteDeletionAuthority = this.changePageCompleteDeletionAuthority.bind(this);
  26. }
  27. /**
  28. * retrieve security data
  29. */
  30. async init() {
  31. // TODO GW-583 init state by apiv3
  32. }
  33. /**
  34. * Workaround for the mangling in production build to break constructor.name
  35. */
  36. static getClassName() {
  37. return 'AdminGeneralSecurityContainer';
  38. }
  39. /**
  40. * Change restrictGuestMode
  41. */
  42. changeRestrictGuestMode(restrictGuestModeLabel) {
  43. this.setState({ currentRestrictGuestMode: restrictGuestModeLabel });
  44. }
  45. /**
  46. * Change pageCompleteDeletionAuthority
  47. */
  48. changePageCompleteDeletionAuthority(pageCompleteDeletionAuthorityLabel) {
  49. this.setState({ currentpageCompleteDeletionAuthority: pageCompleteDeletionAuthorityLabel });
  50. }
  51. /**
  52. * Switch hideRestrictedByOwner
  53. */
  54. switchIsHideRestrictedByOwner() {
  55. this.setState({ isHideRestrictedByOwner: !this.state.isHideRestrictedByOwner });
  56. }
  57. /**
  58. * Switch hideRestrictedByGroup
  59. */
  60. switchIsHideRestrictedByGroup() {
  61. this.setState({ isHideRestrictedByGroup: !this.state.isHideRestrictedByGroup });
  62. }
  63. /**
  64. * Update restrictGuestMode
  65. * @memberOf AdminSecuritySettingContainer
  66. * @return {string} Appearance
  67. */
  68. async updateRestrictGuestMode() {
  69. const response = await this.appContainer.apiv3.put('/security-setting/guest-mode', {
  70. restrictGuestMode: this.state.currentRestrictGuestMode,
  71. });
  72. const { securitySettingParams } = response.data;
  73. return securitySettingParams;
  74. }
  75. /**
  76. * Update pageDeletion
  77. * @memberOf AdminSecuritySettingContainer
  78. * @return {string} pageDeletion
  79. */
  80. async updatePageCompleteDeletionAuthority() {
  81. const response = await this.appContainer.apiv3.put('/security-setting/page-deletion', {
  82. pageCompleteDeletionAuthority: this.state.currentPageCompleteDeletionAuthority,
  83. });
  84. const { securitySettingParams } = response.data;
  85. return securitySettingParams;
  86. }
  87. /**
  88. * Update function
  89. * @memberOf AdminSecucitySettingContainer
  90. * @return {string} Functions
  91. */
  92. async updateSecurityFunction() {
  93. const response = await this.appContainer.apiv3.put('/security-setting/function', {
  94. hideRestrictedByGroup: this.state.hideRestrictedByGroup,
  95. hideRestrictedByOwner: this.state.hideRestrictedByOwner,
  96. });
  97. const { securitySettingParams } = response.data;
  98. return securitySettingParams;
  99. }
  100. }