UNPKG

mattermost-redux

Version:

Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client

110 lines (109 loc) 5.89 kB
"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.getCustomProfileAttributes = exports.getUsersStatusAndProfileFetchingPollInterval = exports.isMarketplaceEnabled = exports.getServerVersion = exports.getManagedResourcePaths = exports.getAutolinkedUrlSchemes = exports.canDownloadFilesOnMobile = exports.canUploadFilesOnMobile = exports.isCloudLicense = exports.getPasswordConfig = void 0; exports.getConfig = getConfig; exports.getFeatureFlagValue = getFeatureFlagValue; exports.getLicense = getLicense; exports.isCompatibleWithJoinViewTeamPermissions = isCompatibleWithJoinViewTeamPermissions; exports.getFirstAdminVisitMarketplaceStatus = getFirstAdminVisitMarketplaceStatus; exports.getFirstAdminSetupComplete = getFirstAdminSetupComplete; exports.isPerformanceDebuggingEnabled = isPerformanceDebuggingEnabled; exports.developerModeEnabled = developerModeEnabled; exports.testingEnabled = testingEnabled; exports.getIsCrossTeamSearchEnabled = getIsCrossTeamSearchEnabled; exports.getCWSAvailability = getCWSAvailability; const constants_1 = require("mattermost-redux/constants"); const create_selector_1 = require("mattermost-redux/selectors/create_selector"); const helpers_1 = require("mattermost-redux/utils/helpers"); function getConfig(state) { return state.entities.general.config; } /** * Safely get value of a specific or known FeatureFlag */ function getFeatureFlagValue(state, key) { return getConfig(state)?.[`FeatureFlag${key}`]; } exports.getPasswordConfig = (0, create_selector_1.createSelector)('getPasswordConfig', getConfig, (config) => { return { minimumLength: parseInt(config.PasswordMinimumLength, 10), requireLowercase: config.PasswordRequireLowercase === 'true', requireUppercase: config.PasswordRequireUppercase === 'true', requireNumber: config.PasswordRequireNumber === 'true', requireSymbol: config.PasswordRequireSymbol === 'true', }; }); function getLicense(state) { return state.entities.general.license; } exports.isCloudLicense = (0, create_selector_1.createSelector)('isCloudLicense', getLicense, (license) => license?.Cloud === 'true'); function isCompatibleWithJoinViewTeamPermissions(state) { const version = state.entities.general.serverVersion; return (0, helpers_1.isMinimumServerVersion)(version, 5, 10, 0) || (version.indexOf('dev') !== -1 && (0, helpers_1.isMinimumServerVersion)(version, 5, 8, 0)) || (version.match(/^5.8.\d.\d\d\d\d.*$/) !== null && (0, helpers_1.isMinimumServerVersion)(version, 5, 8, 0)); } exports.canUploadFilesOnMobile = (0, create_selector_1.createSelector)('canUploadFilesOnMobile', getConfig, getLicense, (config, license) => { // Defaults to true if either setting doesn't exist return config.EnableFileAttachments !== 'false' && (license.IsLicensed === 'false' || license.Compliance === 'false' || config.EnableMobileFileUpload !== 'false'); }); exports.canDownloadFilesOnMobile = (0, create_selector_1.createSelector)('canDownloadFilesOnMobile', getConfig, getLicense, (config, license) => { // Defaults to true if the setting doesn't exist return license.IsLicensed === 'false' || license.Compliance === 'false' || config.EnableMobileFileDownload !== 'false'; }); exports.getAutolinkedUrlSchemes = (0, create_selector_1.createSelector)('getAutolinkedUrlSchemes', getConfig, (config) => { if (!config.CustomUrlSchemes) { return constants_1.General.DEFAULT_AUTOLINKED_URL_SCHEMES; } return [ ...constants_1.General.DEFAULT_AUTOLINKED_URL_SCHEMES, ...config.CustomUrlSchemes.split(','), ]; }); exports.getManagedResourcePaths = (0, create_selector_1.createSelector)('getManagedResourcePaths', getConfig, (config) => { if (!config.ManagedResourcePaths) { return []; } return config.ManagedResourcePaths.split(',').map((path) => path.trim()); }); const getServerVersion = (state) => { return state.entities.general.serverVersion; }; exports.getServerVersion = getServerVersion; function getFirstAdminVisitMarketplaceStatus(state) { return state.entities.general.firstAdminVisitMarketplaceStatus; } function getFirstAdminSetupComplete(state) { return state.entities.general.firstAdminCompleteSetup; } function isPerformanceDebuggingEnabled(state) { return state.entities.general.config.EnableClientPerformanceDebugging === 'true'; } exports.isMarketplaceEnabled = (0, create_selector_1.createSelector)('isMarketplaceEnabled', getConfig, (config) => { return config.PluginsEnabled === 'true' && config.EnableMarketplace === 'true'; }); exports.getUsersStatusAndProfileFetchingPollInterval = (0, create_selector_1.createSelector)('getUsersStatusAndProfileFetchingPollInterval', getConfig, (config) => { const usersStatusAndProfileFetchingPollInterval = config.UsersStatusAndProfileFetchingPollIntervalMilliseconds; if (usersStatusAndProfileFetchingPollInterval) { return parseInt(usersStatusAndProfileFetchingPollInterval, 10); } return null; }); function developerModeEnabled(state) { return state.entities.general.config.EnableDeveloper === 'true'; } function testingEnabled(state) { return state.entities.general.config.EnableTesting === 'true'; } exports.getCustomProfileAttributes = (0, create_selector_1.createSelector)('getCustomProfileAttributes', (state) => state.entities.general.customProfileAttributes, (fields) => { return Object.values(fields).sort((a, b) => (a.attrs?.sort_order ?? 0) - (b.attrs?.sort_order ?? 0)); }); function getIsCrossTeamSearchEnabled(state) { return state.entities.general.config.EnableCrossTeamSearch === 'true'; } function getCWSAvailability(state) { return state.entities.general.cwsAvailability; }