| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- import { Container } from 'unstated';
- import { toastError } from '../util/apiNotification';
- import removeNullPropertyFromObject from '../../../lib/util/removeNullPropertyFromObject';
- /**
- * 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.dummyCurrentRestrictGuestMode = 0;
- this.dummyCurrentRestrictGuestModeForError = 1;
- this.state = {
- retrieveError: null,
- sessionMaxAge: null,
- wikiMode: '',
- // set dummy value tile for using suspense
- currentRestrictGuestMode: this.dummyCurrentRestrictGuestMode,
- currentPageCompleteDeletionAuthority: 'adminOnly',
- isShowRestrictedByOwner: false,
- isShowRestrictedByGroup: false,
- appSiteUrl: appContainer.config.crowi.url || '',
- isLocalEnabled: false,
- isLdapEnabled: false,
- isSamlEnabled: false,
- isOidcEnabled: false,
- isBasicEnabled: false,
- isGoogleEnabled: false,
- isGitHubEnabled: false,
- isTwitterEnabled: false,
- setupStrategies: [],
- shareLinks: [],
- totalshareLinks: 0,
- shareLinksPagingLimit: Infinity,
- shareLinksActivePage: 1,
- };
- }
- async retrieveSecurityData() {
- await this.retrieveSetupStratedies();
- const response = await this.appContainer.apiv3.get('/security-setting/');
- const { generalSetting, generalAuth } = response.data.securityParams;
- this.setState({
- currentRestrictGuestMode: generalSetting.restrictGuestMode,
- currentPageCompleteDeletionAuthority: generalSetting.pageCompleteDeletionAuthority,
- isShowRestrictedByOwner: !generalSetting.hideRestrictedByOwner,
- isShowRestrictedByGroup: !generalSetting.hideRestrictedByGroup,
- sessionMaxAge: generalSetting.sessionMaxAge,
- wikiMode: generalSetting.wikiMode,
- isLocalEnabled: generalAuth.isLocalEnabled,
- isLdapEnabled: generalAuth.isLdapEnabled,
- isSamlEnabled: generalAuth.isSamlEnabled,
- isOidcEnabled: generalAuth.isOidcEnabled,
- isBasicEnabled: generalAuth.isBasicEnabled,
- isGoogleEnabled: generalAuth.isGoogleEnabled,
- isGitHubEnabled: generalAuth.isGitHubEnabled,
- isTwitterEnabled: generalAuth.isTwitterEnabled,
- });
- }
- /**
- * Workaround for the mangling in production build to break constructor.name
- */
- static getClassName() {
- return 'AdminGeneralSecurityContainer';
- }
- /**
- * get isWikiModeForced
- * @return {bool} isWikiModeForced
- */
- get isWikiModeForced() {
- return this.state.wikiMode === 'public' || this.state.wikiMode === 'private';
- }
- /**
- * setter for sessionMaxAge
- */
- setSessionMaxAge(sessionMaxAge) {
- this.setState({ sessionMaxAge });
- }
- /**
- * Change restrictGuestMode
- */
- changeRestrictGuestMode(restrictGuestModeLabel) {
- this.setState({ currentRestrictGuestMode: restrictGuestModeLabel });
- }
- /**
- * Change pageCompleteDeletionAuthority
- */
- changePageCompleteDeletionAuthority(pageCompleteDeletionAuthorityLabel) {
- this.setState({ currentPageCompleteDeletionAuthority: pageCompleteDeletionAuthorityLabel });
- }
- /**
- * Switch showRestrictedByOwner
- */
- switchIsShowRestrictedByOwner() {
- this.setState({ isShowRestrictedByOwner: !this.state.isShowRestrictedByOwner });
- }
- /**
- * Switch showRestrictedByGroup
- */
- switchIsShowRestrictedByGroup() {
- this.setState({ isShowRestrictedByGroup: !this.state.isShowRestrictedByGroup });
- }
- /**
- * Update restrictGuestMode
- * @memberOf AdminGeneralSecuritySContainer
- * @return {string} Appearance
- */
- async updateGeneralSecuritySetting() {
- let requestParams = {
- sessionMaxAge: this.state.sessionMaxAge,
- restrictGuestMode: this.state.currentRestrictGuestMode,
- pageCompleteDeletionAuthority: this.state.currentPageCompleteDeletionAuthority,
- hideRestrictedByGroup: !this.state.isShowRestrictedByGroup,
- hideRestrictedByOwner: !this.state.isShowRestrictedByOwner,
- };
- requestParams = await removeNullPropertyFromObject(requestParams);
- const response = await this.appContainer.apiv3.put('/security-setting/general-setting', requestParams);
- 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,
- });
- await this.retrieveSetupStratedies();
- this.setState({ [stateVariableName]: isEnabled });
- }
- catch (err) {
- toastError(err);
- }
- }
- /**
- * Retrieve SetupStratedies
- */
- async retrieveSetupStratedies() {
- try {
- const response = await this.appContainer.apiv3.get('/security-setting/authentication');
- const { setupStrategies } = response.data;
- this.setState({ setupStrategies });
- }
- catch (err) {
- toastError(err);
- }
- }
- /**
- * Retrieve All Sharelinks
- */
- async retrieveShareLinksByPagingNum(page) {
- const params = {
- page,
- };
- const { data } = await this.appContainer.apiv3.get('/security-setting/all-share-links', params);
- if (data.paginateResult == null) {
- throw new Error('data must conclude \'paginateResult\' property.');
- }
- const { docs: shareLinks, totalDocs: totalshareLinks, limit: shareLinksPagingLimit } = data.paginateResult;
- this.setState({
- shareLinks,
- totalshareLinks,
- shareLinksPagingLimit,
- shareLinksActivePage: page,
- });
- }
- /**
- * Switch local enabled
- */
- async switchIsLocalEnabled() {
- this.switchAuthentication('isLocalEnabled', 'local');
- }
- /**
- * 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');
- }
- }
|