| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- import { Container } from 'unstated';
- import {
- PageSingleDeleteConfigValue, PageSingleDeleteCompConfigValue,
- PageRecursiveDeleteConfigValue, PageRecursiveDeleteCompConfigValue,
- } from '~/interfaces/page-delete-config';
- import { toastError } from '../util/apiNotification';
- import { removeNullPropertyFromObject } from '~/utils/object-utils';
- /**
- * 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,
- currentPageDeletionAuthority: PageSingleDeleteConfigValue.AdminOnly,
- currentPageRecursiveDeletionAuthority: PageRecursiveDeleteConfigValue.Inherit,
- currentPageCompleteDeletionAuthority: PageSingleDeleteCompConfigValue.AdminOnly,
- currentPageRecursiveCompleteDeletionAuthority: PageRecursiveDeleteCompConfigValue.Inherit,
- expandOtherOptionsForDeletion: false,
- expandOtherOptionsForCompleteDeletion: false,
- 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: [],
- disableLinkSharing: false,
- shareLinks: [],
- totalshareLinks: 0,
- shareLinksPagingLimit: Infinity,
- shareLinksActivePage: 1,
- };
- this.changePageDeletionAuthority = this.changePageDeletionAuthority.bind(this);
- this.changePageCompleteDeletionAuthority = this.changePageCompleteDeletionAuthority.bind(this);
- this.changePageRecursiveDeletionAuthority = this.changePageRecursiveDeletionAuthority.bind(this);
- this.changePageRecursiveCompleteDeletionAuthority = this.changePageRecursiveCompleteDeletionAuthority.bind(this);
- }
- async retrieveSecurityData() {
- await this.retrieveSetupStratedies();
- const response = await this.appContainer.apiv3.get('/security-setting/');
- const { generalSetting, shareLinkSetting, generalAuth } = response.data.securityParams;
- this.setState({
- currentRestrictGuestMode: generalSetting.restrictGuestMode,
- currentPageDeletionAuthority: generalSetting.pageDeletionAuthority,
- currentPageCompleteDeletionAuthority: generalSetting.pageCompleteDeletionAuthority,
- currentPageRecursiveDeletionAuthority: generalSetting.pageRecursiveDeletionAuthority,
- currentPageRecursiveCompleteDeletionAuthority: generalSetting.pageRecursiveCompleteDeletionAuthority,
- isShowRestrictedByOwner: !generalSetting.hideRestrictedByOwner,
- isShowRestrictedByGroup: !generalSetting.hideRestrictedByGroup,
- sessionMaxAge: generalSetting.sessionMaxAge,
- wikiMode: generalSetting.wikiMode,
- disableLinkSharing: shareLinkSetting.disableLinkSharing,
- 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 });
- }
- /**
- * setter for disableLinkSharing
- */
- setDisableLinkSharing(disableLinkSharing) {
- this.setState({ disableLinkSharing });
- }
- /**
- * Change restrictGuestMode
- */
- changeRestrictGuestMode(restrictGuestModeLabel) {
- this.setState({ currentRestrictGuestMode: restrictGuestModeLabel });
- }
- /**
- * Change pageDeletionAuthority
- */
- changePageDeletionAuthority(val) {
- this.setState({ currentPageDeletionAuthority: val });
- }
- /**
- * Change pageCompleteDeletionAuthority
- */
- changePageCompleteDeletionAuthority(val) {
- this.setState({ currentPageCompleteDeletionAuthority: val });
- }
- /**
- * Change pageRecursiveDeletionAuthority
- */
- changePageRecursiveDeletionAuthority(val) {
- this.setState({ currentPageRecursiveDeletionAuthority: val });
- }
- /**
- * Change pageRecursiveCompleteDeletionAuthority
- */
- changePageRecursiveCompleteDeletionAuthority(val) {
- this.setState({ currentPageRecursiveCompleteDeletionAuthority: val });
- }
- /**
- * Switch ExpandOtherOptionsForDeletion
- */
- switchExpandOtherOptionsForDeletion() {
- this.setState({ expandOtherOptionsForDeletion: !this.state.expandOtherOptionsForDeletion });
- }
- /**
- * Switch ExpandOtherOptionsForDeletion
- */
- switchExpandOtherOptionsForCompleteDeletion() {
- this.setState({ expandOtherOptionsForCompleteDeletion: !this.state.expandOtherOptionsForCompleteDeletion });
- }
- /**
- * 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,
- pageDeletionAuthority: this.state.currentPageDeletionAuthority,
- pageCompleteDeletionAuthority: this.state.currentPageCompleteDeletionAuthority,
- pageRecursiveDeletionAuthority: this.state.currentPageRecursiveDeletionAuthority,
- pageRecursiveCompleteDeletionAuthority: this.state.currentPageRecursiveCompleteDeletionAuthority,
- 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 disableLinkSharing
- */
- async switchDisableLinkSharing() {
- const requestParams = {
- disableLinkSharing: !this.state.disableLinkSharing,
- };
- const response = await this.appContainer.apiv3.put('/security-setting/share-link-setting', requestParams);
- this.setDisableLinkSharing(!this.state.disableLinkSharing);
- return response;
- }
- /**
- * 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');
- }
- }
|