| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- import { Container } from 'unstated';
- import loggerFactory from '@alias/logger';
- // eslint-disable-next-line no-unused-vars
- const logger = loggerFactory('growi:security:AdminGeneralSecurityContainer');
- /**
- * Service container for admin security page (SecuritySetting.jsx)
- * @extends {Container} unstated Container
- */
- export default class AdminGeneralSecurityContainer extends Container {
- constructor(appContainer) {
- super();
- this.appContainer = appContainer;
- this.state = {
- // TODO GW-583 set value
- isWikiModeForced: false,
- currentRestrictGuestMode: 'deny',
- currentPageCompleteDeletionAuthority: 'anyone',
- isHideRestrictedByOwner: true,
- isHideRestrictedByGroup: true,
- useOnlyEnvVarsForSomeOptions: true,
- appSiteUrl: appContainer.config.crowi.url || '',
- isLocalEnabled: true,
- registrationMode: 'open',
- registrationWhiteList: '',
- isLdapEnabled: true,
- isSamlEnabled: true,
- isOidcEnabled: true,
- isBasicEnabled: true,
- isGoogleOAuthEnabled: true,
- isGithubOAuthEnabled: true,
- isTwitterOAuthEnabled: true,
- };
- this.init();
- this.switchIsLocalEnabled = this.switchIsLocalEnabled.bind(this);
- this.changeRegistrationMode = this.changeRegistrationMode.bind(this);
- this.changeRestrictGuestMode = this.changeRestrictGuestMode.bind(this);
- this.changePageCompleteDeletionAuthority = this.changePageCompleteDeletionAuthority.bind(this);
- this.switchIsHideRestrictedByGroup = this.switchIsHideRestrictedByGroup.bind(this);
- this.switchIsHideRestrictedByOwner = this.switchIsHideRestrictedByOwner.bind(this);
- this.changePageCompleteDeletionAuthority = this.changePageCompleteDeletionAuthority.bind(this);
- }
- init() {
- // TODO GW-583 fetch config value with api
- }
- /**
- * Workaround for the mangling in production build to break constructor.name
- */
- static getClassName() {
- return 'AdminGeneralSecurityContainer';
- }
- /**
- * Change restrictGuestMode
- */
- changeRestrictGuestMode(restrictGuestModeLabel) {
- this.setState({ currentRestrictGuestMode: restrictGuestModeLabel });
- }
- /**
- * Change pageCompleteDeletionAuthority
- */
- changePageCompleteDeletionAuthority(pageCompleteDeletionAuthorityLabel) {
- this.setState({ currentPageCompleteDeletionAuthority: pageCompleteDeletionAuthorityLabel });
- }
- /**
- * Switch hideRestrictedByOwner
- */
- switchIsHideRestrictedByOwner() {
- this.setState({ isHideRestrictedByOwner: !this.state.isHideRestrictedByOwner });
- }
- /**
- * Switch hideRestrictedByGroup
- */
- switchIsHideRestrictedByGroup() {
- this.setState({ isHideRestrictedByGroup: !this.state.isHideRestrictedByGroup });
- }
- /**
- * Update restrictGuestMode
- * @memberOf AdminGeneralSecuritySContainer
- * @return {string} Appearance
- */
- async updateGeneralSecuritySetting() {
- const response = await this.appContainer.apiv3.put('/security-setting/general-setting', {
- restrictGuestMode: this.state.currentRestrictGuestMode,
- pageCompleteDeletionAuthority: this.state.currentPageCompleteDeletionAuthority,
- hideRestrictedByGroup: this.state.isHideRestrictedByGroup,
- hideRestrictedByOwner: this.state.isHideRestrictedByOwner,
- });
- const { securitySettingParams } = response.data;
- return securitySettingParams;
- }
- /**
- * Switch local enabled
- */
- switchIsLocalEnabled() {
- this.setState({ isLocalEnabled: !this.state.isLocalEnabled });
- }
- /**
- * Change registration mode
- */
- changeRegistrationMode(value) {
- this.setState({ registrationMode: value });
- }
- /**
- * Switch LDAP enabled
- */
- switchIsLdapEnabled() {
- this.setState({ isLdapEnabled: !this.state.isLdapEnabled });
- }
- /**
- * Switch SAML enabled
- */
- switchIsSamlEnabled() {
- this.setState({ isSamlEnabled: !this.state.isSamlEnabled });
- }
- /**
- * Switch Oidc enabled
- */
- switchIsOidcEnabled() {
- this.setState({ isOidcEnabled: !this.state.isOidcEnabled });
- }
- /**
- * Switch Basic enabled
- */
- switchIsBasicEnabled() {
- this.setState({ isBasicEnabled: !this.state.isBasicEnabled });
- }
- /**
- * Switch GoogleOAuth enabled
- */
- switchIsGoogleOAuthEnabled() {
- this.setState({ isGoogleOAuthEnabled: !this.state.isGoogleOAuthEnabled });
- }
- /**
- * Switch GithubOAuth enabled
- */
- switchIsGithubOAuthEnabled() {
- this.setState({ isGithubOAuthEnabled: !this.state.isGithubOAuthEnabled });
- }
- /**
- * Switch TwitterOAuth enabled
- */
- switchIsTwitterOAuthEnabled() {
- this.setState({ isTwitterOAuthEnabled: !this.state.isTwitterOAuthEnabled });
- }
- }
|