| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- import { isServer } from '@growi/core/dist/utils';
- import { Container } from 'unstated';
- import {
- PageSingleDeleteConfigValue, PageSingleDeleteCompConfigValue,
- PageRecursiveDeleteConfigValue, PageRecursiveDeleteCompConfigValue,
- } from '~/interfaces/page-delete-config';
- import { removeNullPropertyFromObject } from '~/utils/object-utils';
- import { apiv3Get, apiv3Put } from '../util/apiv3-client';
- import { toastError } from '../util/toastr';
- /**
- * Service container for admin security page (SecuritySetting.jsx)
- * @extends {Container} unstated Container
- */
- export default class AdminGeneralSecurityContainer extends Container {
- constructor(appContainer) {
- super();
- if (isServer()) {
- return;
- }
- this.state = {
- retrieveError: null,
- sessionMaxAge: null,
- wikiMode: '',
- currentRestrictGuestMode: '',
- currentPageDeletionAuthority: PageSingleDeleteConfigValue.AdminOnly,
- currentPageRecursiveDeletionAuthority: PageRecursiveDeleteConfigValue.Inherit,
- currentPageCompleteDeletionAuthority: PageSingleDeleteCompConfigValue.AdminOnly,
- currentPageRecursiveCompleteDeletionAuthority: PageRecursiveDeleteCompConfigValue.Inherit,
- currentGroupRestrictionDisplayMode: 'Hidden',
- currentOwnerRestrictionDisplayMode: 'Hidden',
- isAllGroupMembershipRequiredForPageCompleteDeletion: true,
- previousPageRecursiveDeletionAuthority: null,
- previousPageRecursiveCompleteDeletionAuthority: null,
- expandOtherOptionsForDeletion: false,
- expandOtherOptionsForCompleteDeletion: false,
- isShowRestrictedByOwner: false,
- isUsersHomepageDeletionEnabled: false,
- isForceDeleteUserHomepageOnUserDeletion: false,
- isRomUserAllowedToComment: false,
- isLocalEnabled: false,
- isLdapEnabled: false,
- isSamlEnabled: false,
- isOidcEnabled: false,
- isGoogleEnabled: false,
- isGitHubEnabled: false,
- setupStrategies: [],
- disableLinkSharing: false,
- shareLinks: [],
- totalshareLinks: 0,
- shareLinksPagingLimit: Infinity,
- shareLinksActivePage: 1,
- };
- this.changeOwnerRestrictionDisplayMode = this.changeOwnerRestrictionDisplayMode.bind(this);
- this.changeGroupRestrictionDisplayMode = this.changeGroupRestrictionDisplayMode.bind(this);
- this.changePageDeletionAuthority = this.changePageDeletionAuthority.bind(this);
- this.changePageCompleteDeletionAuthority = this.changePageCompleteDeletionAuthority.bind(this);
- this.changePageRecursiveDeletionAuthority = this.changePageRecursiveDeletionAuthority.bind(this);
- this.changePageRecursiveCompleteDeletionAuthority = this.changePageRecursiveCompleteDeletionAuthority.bind(this);
- this.changePreviousPageRecursiveDeletionAuthority = this.changePreviousPageRecursiveDeletionAuthority.bind(this);
- this.changePreviousPageRecursiveCompleteDeletionAuthority = this.changePreviousPageRecursiveCompleteDeletionAuthority.bind(this);
- }
- async retrieveSecurityData() {
- await this.retrieveSetupStratedies();
- const response = await apiv3Get('/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,
- isAllGroupMembershipRequiredForPageCompleteDeletion: generalSetting.isAllGroupMembershipRequiredForPageCompleteDeletion,
- // Set display to 'Hidden' if hideRestrictedByOwner is anything but false.
- currentOwnerRestrictionDisplayMode: generalSetting.hideRestrictedByOwner === false ? 'Displayed' : 'Hidden',
- currentGroupRestrictionDisplayMode: generalSetting.hideRestrictedByGroup === false ? 'Displayed' : 'Hidden',
- isUsersHomepageDeletionEnabled: generalSetting.isUsersHomepageDeletionEnabled,
- isForceDeleteUserHomepageOnUserDeletion: generalSetting.isForceDeleteUserHomepageOnUserDeletion,
- isRomUserAllowedToComment: generalSetting.isRomUserAllowedToComment,
- sessionMaxAge: generalSetting.sessionMaxAge,
- wikiMode: generalSetting.wikiMode,
- disableLinkSharing: shareLinkSetting.disableLinkSharing,
- isLocalEnabled: generalAuth.isLocalEnabled,
- isLdapEnabled: generalAuth.isLdapEnabled,
- isSamlEnabled: generalAuth.isSamlEnabled,
- isOidcEnabled: generalAuth.isOidcEnabled,
- isGoogleEnabled: generalAuth.isGoogleEnabled,
- isGitHubEnabled: generalAuth.isGitHubEnabled,
- });
- }
- /**
- * 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 ownerRestrictionDisplayMode
- */
- changeOwnerRestrictionDisplayMode(mode) {
- this.setState({ currentOwnerRestrictionDisplayMode: mode });
- }
- /**
- * Change groupRestrictionDisplayMode
- */
- changeGroupRestrictionDisplayMode(mode) {
- this.setState({ currentGroupRestrictionDisplayMode: mode });
- }
- /**
- * 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 isAllGroupMembershipRequiredForPageCompleteDeletion
- */
- switchIsAllGroupMembershipRequiredForPageCompleteDeletion() {
- this.setState({ isAllGroupMembershipRequiredForPageCompleteDeletion: !this.state.isAllGroupMembershipRequiredForPageCompleteDeletion });
- }
- /**
- * Change previousPageRecursiveDeletionAuthority
- */
- changePreviousPageRecursiveDeletionAuthority(val) {
- this.setState({ previousPageRecursiveDeletionAuthority: val });
- }
- /**
- * Change previousPageRecursiveCompleteDeletionAuthority
- */
- changePreviousPageRecursiveCompleteDeletionAuthority(val) {
- this.setState({ previousPageRecursiveCompleteDeletionAuthority: val });
- }
- /**
- * Switch ExpandOtherOptionsForDeletion
- */
- switchExpandOtherOptionsForDeletion(bool) {
- this.setState({ expandOtherOptionsForDeletion: bool });
- }
- /**
- * Switch ExpandOtherOptionsForDeletion
- */
- switchExpandOtherOptionsForCompleteDeletion(bool) {
- this.setState({ expandOtherOptionsForCompleteDeletion: bool });
- }
- /**
- * Switch isUsersHomepageDeletionEnabled
- */
- switchIsUsersHomepageDeletionEnabled() {
- this.setState({ isUsersHomepageDeletionEnabled: !this.state.isUsersHomepageDeletionEnabled });
- }
- /**
- * Switch isForceDeleteUserHomepageOnUserDeletion
- */
- switchIsForceDeleteUserHomepageOnUserDeletion() {
- this.setState({ isForceDeleteUserHomepageOnUserDeletion: !this.state.isForceDeleteUserHomepageOnUserDeletion });
- }
- /**
- * switch isRomUserAllowedToComment
- */
- switchIsRomUserAllowedToComment(bool) {
- this.setState({ isRomUserAllowedToComment: bool });
- }
- /**
- * 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,
- isAllGroupMembershipRequiredForPageCompleteDeletion: this.state.isAllGroupMembershipRequiredForPageCompleteDeletion,
- hideRestrictedByGroup: this.state.currentGroupRestrictionDisplayMode === 'Hidden',
- hideRestrictedByOwner: this.state.currentOwnerRestrictionDisplayMode === 'Hidden',
- isUsersHomepageDeletionEnabled: this.state.isUsersHomepageDeletionEnabled,
- isForceDeleteUserHomepageOnUserDeletion: this.state.isForceDeleteUserHomepageOnUserDeletion,
- isRomUserAllowedToComment: this.state.isRomUserAllowedToComment,
- };
- requestParams = await removeNullPropertyFromObject(requestParams);
- const response = await apiv3Put('/security-setting/general-setting', requestParams);
- const { securitySettingParams } = response.data;
- return securitySettingParams;
- }
- /**
- * Switch disableLinkSharing
- */
- async switchDisableLinkSharing() {
- const requestParams = {
- disableLinkSharing: !this.state.disableLinkSharing,
- };
- const response = await apiv3Put('/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 apiv3Put('/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 apiv3Get('/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 apiv3Get('/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 GoogleOAuth enabled
- */
- async switchIsGoogleOAuthEnabled() {
- this.switchAuthentication('isGoogleEnabled', 'google');
- }
- /**
- * Switch GitHubOAuth enabled
- */
- async switchIsGitHubOAuthEnabled() {
- this.switchAuthentication('isGitHubEnabled', 'github');
- }
- }
|