| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- import { Container } from 'unstated';
- import loggerFactory from '@alias/logger';
- import { toastError } from '../util/apiNotification';
- // 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 = {
- isWikiModeForced: false,
- wikiMode: '',
- 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,
- isGoogleEnabled: true,
- isGithubEnabled: true,
- isTwitterEnabled: true,
- };
- this.onIsWikiModeForced = this.onIsWikiModeForced.bind(this);
- }
- async retrieveSecurityData() {
- const response = await this.appContainer.apiv3.get('/security-setting/');
- const { generalSetting } = response.data.securityParams;
- const { localSetting } = response.data.securityParams;
- this.onIsWikiModeForced(generalSetting.wikiMode);
- this.setState({
- currentRestrictGuestMode: generalSetting.restrictGuestMode || 'deny',
- currentPageCompleteDeletionAuthority: generalSetting.pageCompleteDeletionAuthority || 'anyone',
- isHideRestrictedByOwner: generalSetting.hideRestrictedByOwner || false,
- isHideRestrictedByGroup: generalSetting.hideRestrictedByGroup || false,
- wikiMode: generalSetting.wikiMode || '',
- isLocalEnabled: localSetting.isLocalEnabled || false,
- registrationMode: localSetting.registrationMode || 'open',
- registrationWhiteList: localSetting.registrationWhiteList.join('\n') || '',
- });
- }
- /**
- * 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 });
- }
- onIsWikiModeForced(wikiModeSetting) {
- if (wikiModeSetting === 'private') {
- this.setState({ isWikiModeForced: true });
- }
- else {
- this.setState({ isWikiModeForced: false });
- }
- }
- /**
- * 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 authentication
- */
- async switchAuthentication(stateVariableName, authId) {
- const isEnabled = !this.state[stateVariableName];
- try {
- await this.appContainer.apiv3.put('/security-setting/authentication/enabled', {
- isEnabled,
- authId,
- });
- this.setState({ [stateVariableName]: isEnabled });
- }
- catch (err) {
- toastError(err);
- }
- }
- /**
- * Switch local enabled
- */
- async switchIsLocalEnabled() {
- this.switchAuthentication('isLocalEnabled', 'local');
- }
- /**
- * Change registration mode
- */
- changeRegistrationMode(value) {
- this.setState({ registrationMode: value });
- }
- /**
- * Change registration white list
- */
- changeRegistrationWhiteList(value) {
- this.setState({ registrationWhiteList: value });
- }
- /**
- * update local security setting
- */
- async updateLocalSecuritySetting() {
- let { registrationWhiteList } = this.state;
- registrationWhiteList = Array.isArray(registrationWhiteList) ? registrationWhiteList : registrationWhiteList.split('\n');
- const response = await this.appContainer.apiv3.put('/security-setting/local-setting', {
- isLocalEnabled: this.state.isLocalEnabled,
- registrationMode: this.state.registrationMode,
- registrationWhiteList,
- });
- const { localSecuritySettingParams } = response.data;
- return localSecuritySettingParams;
- }
- /**
- * Switch LDAP enabled
- */
- async switchIsLdapEnabled() {
- this.switchAuthentication('isLdapEnabled', 'ldap');
- }
- /**
- * Switch SAML enabled
- */
- async switchIsSamlEnabled() {
- this.switchAuthentication('isSamlEnabled', 'saml');
- }
- /**
- * Switch Oidc enabled
- */
- async switchIsOidcEnabled() {
- this.switchAuthentication('isOidcEnabled', 'oidc');
- }
- /**
- * Switch Basic enabled
- */
- async switchIsBasicEnabled() {
- this.switchAuthentication('isBasicEnabled', 'basic');
- }
- /**
- * Switch GoogleOAuth enabled
- */
- async switchIsGoogleOAuthEnabled() {
- this.switchAuthentication('isGoogleEnabled', 'google');
- }
- /**
- * Switch GithubOAuth enabled
- */
- async switchIsGithubOAuthEnabled() {
- this.switchAuthentication('isGitHubEnabled', 'github');
- }
- /**
- * Switch TwitterOAuth enabled
- */
- async switchIsTwitterOAuthEnabled() {
- this.switchAuthentication('isTwitterEnabled', 'twitter');
- }
- }
|