Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
MM-29670 - Hide payment screen in system Console if in free tier (#6797)
Browse files Browse the repository at this point in the history
  • Loading branch information
alifarooq0 committed Oct 15, 2020
1 parent 604163e commit b873644
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
1 change: 1 addition & 0 deletions components/admin_console/admin_console.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('components/AdminConsole', () => {
},
adminDefinition: AdminDefinition,
license: {},
cloud: {},
buildEnterpriseReady: true,
match: {
url: '',
Expand Down
14 changes: 8 additions & 6 deletions components/admin_console/admin_console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {AdminConfig, EnvironmentConfig, ClientLicense} from 'mattermost-redux/ty
import {Role} from 'mattermost-redux/types/roles';
import {ConsoleAccess} from 'mattermost-redux/types/admin';
import {Dictionary} from 'mattermost-redux/types/utilities';
import {CloudState} from 'mattermost-redux/types/cloud';

import AnnouncementBar from 'components/announcement_bar';
import SystemNotice from 'components/system_notice';
Expand All @@ -36,6 +37,7 @@ type Props = {
isCurrentUserSystemAdmin: boolean;
currentUserHasAnAdminRole: boolean;
consoleAccess: ConsoleAccess;
cloud: CloudState;
actions: {
getConfig: () => ActionFunc;
getEnvironmentConfig: () => ActionFunc;
Expand Down Expand Up @@ -67,8 +69,8 @@ type ExtraProps = {
}

type Item = {
isHidden?: (config?: Record<string, any>, state?: Record<string, any>, license?: Record<string, any>, buildEnterpriseReady?: boolean, consoleAccess?: ConsoleAccess) => boolean;
isDisabled?: (config?: Record<string, any>, state?: Record<string, any>, license?: Record<string, any>, buildEnterpriseReady?: boolean, consoleAccess?: ConsoleAccess) => boolean;
isHidden?: (config?: Record<string, any>, state?: Record<string, any>, license?: Record<string, any>, buildEnterpriseReady?: boolean, consoleAccess?: ConsoleAccess, cloud?: CloudState) => boolean;
isDisabled?: (config?: Record<string, any>, state?: Record<string, any>, license?: Record<string, any>, buildEnterpriseReady?: boolean, consoleAccess?: ConsoleAccess, cloud?: CloudState) => boolean;
schema: Record<string, any>;
url: string;
}
Expand Down Expand Up @@ -109,7 +111,7 @@ export default class AdminConsole extends React.PureComponent<Props, State> {
}

private renderRoutes = (extraProps: ExtraProps) => {
const {adminDefinition, config, license, buildEnterpriseReady, consoleAccess} = this.props;
const {adminDefinition, config, license, buildEnterpriseReady, consoleAccess, cloud} = this.props;

const schemas: Item[] = Object.values(adminDefinition).reduce((acc, section) => {
let items: Item[] = [];
Expand All @@ -118,7 +120,7 @@ export default class AdminConsole extends React.PureComponent<Props, State> {
Object.entries(section).find(([key, value]) => {
if (key === 'isHidden') {
if (typeof value === 'function') {
isSectionHidden = value(config, this.state, license, buildEnterpriseReady, consoleAccess);
isSectionHidden = value(config, this.state, license, buildEnterpriseReady, consoleAccess, cloud);
} else {
isSectionHidden = Boolean(value);
}
Expand All @@ -136,7 +138,7 @@ export default class AdminConsole extends React.PureComponent<Props, State> {

const schemaRoutes = schemas.map((item: Item, index: number) => {
if (typeof item.isHidden !== 'undefined') {
const isHidden = (typeof item.isHidden === 'function') ? item.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess) : Boolean(item.isHidden);
const isHidden = (typeof item.isHidden === 'function') ? item.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess, cloud) : Boolean(item.isHidden);
if (isHidden) {
return false;
}
Expand All @@ -145,7 +147,7 @@ export default class AdminConsole extends React.PureComponent<Props, State> {
let isItemDisabled: boolean;

if (typeof item.isDisabled === 'function') {
isItemDisabled = item.isDisabled(config, this.state, license, buildEnterpriseReady, consoleAccess);
isItemDisabled = item.isDisabled(config, this.state, license, buildEnterpriseReady, consoleAccess, cloud);
} else {
isItemDisabled = Boolean(item.isDisabled);
}
Expand Down
19 changes: 13 additions & 6 deletions components/admin_console/admin_definition.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,20 @@ const SAML_SETTINGS_CANONICAL_ALGORITHM_C14N11 = 'Canonical1.1';
// - fileType: A list of extensions separated by ",". E.g. ".jpg,.png,.gif".

export const it = {
not: (func) => (config, state, license, enterpriseReady, consoleAccess) => {
return typeof func === 'function' ? !func(config, state, license, enterpriseReady, consoleAccess) : !func;
not: (func) => (config, state, license, enterpriseReady, consoleAccess, cloud) => {
return typeof func === 'function' ? !func(config, state, license, enterpriseReady, consoleAccess, cloud) : !func;
},
all: (...funcs) => (config, state, license, enterpriseReady, consoleAccess) => {
all: (...funcs) => (config, state, license, enterpriseReady, consoleAccess, cloud) => {
for (const func of funcs) {
if (typeof func === 'function' ? !func(config, state, license, enterpriseReady, consoleAccess) : !func) {
if (typeof func === 'function' ? !func(config, state, license, enterpriseReady, consoleAccess, cloud) : !func) {
return false;
}
}
return true;
},
any: (...funcs) => (config, state, license, enterpriseReady, consoleAccess) => {
any: (...funcs) => (config, state, license, enterpriseReady, consoleAccess, cloud) => {
for (const func of funcs) {
if (typeof func === 'function' ? func(config, state, license, enterpriseReady, consoleAccess) : func) {
if (typeof func === 'function' ? func(config, state, license, enterpriseReady, consoleAccess, cloud) : func) {
return true;
}
}
Expand All @@ -175,6 +175,12 @@ export const it = {
enterpriseReady: (config, state, license, enterpriseReady) => enterpriseReady,
licensed: (config, state, license) => license.IsLicensed === 'true',
licensedForFeature: (feature) => (config, state, license) => license.IsLicensed && license[feature] === 'true',
isPaidTier: (config, state, license, enterpriseReady, consoleAccess, cloud) => {
if (!cloud?.subscription) {
return false;
}
return cloud.subscription.is_paid_tier === 'true';
},
userHasReadPermissionOnResource: (key) => (config, state, license, enterpriseReady, consoleAccess) => consoleAccess?.read?.[key],
userHasWritePermissionOnResource: (key) => (config, state, license, enterpriseReady, consoleAccess) => consoleAccess?.write?.[key],
};
Expand Down Expand Up @@ -264,6 +270,7 @@ const AdminDefinition = {
url: 'billing/payment_info',
title: t('admin.sidebar.payment_info'),
title_default: 'Payment Information',
isHidden: it.not(it.isPaidTier),
searchableStrings: [
'admin.billing.payment_info.title',
],
Expand Down
11 changes: 6 additions & 5 deletions components/admin_console/admin_sidebar/admin_sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AdminSidebar extends React.PureComponent {
config: PropTypes.object,
plugins: PropTypes.object,
adminDefinition: PropTypes.object,
cloud: PropTypes.object,
buildEnterpriseReady: PropTypes.bool,
siteName: PropTypes.string,
onFilterChange: PropTypes.func.isRequired,
Expand Down Expand Up @@ -145,7 +146,7 @@ class AdminSidebar extends React.PureComponent {
}

visibleSections = () => {
const {config, license, buildEnterpriseReady, consoleAccess, adminDefinition} = this.props;
const {config, license, buildEnterpriseReady, consoleAccess, adminDefinition, cloud} = this.props;
const isVisible = (item) => {
if (!item.schema) {
return false;
Expand All @@ -155,7 +156,7 @@ class AdminSidebar extends React.PureComponent {
return false;
}

if (item.isHidden && item.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess)) {
if (item.isHidden && item.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess, cloud)) {
return false;
}
return true;
Expand All @@ -172,12 +173,12 @@ class AdminSidebar extends React.PureComponent {
}

renderRootMenu = (definition) => {
const {config, license, buildEnterpriseReady, consoleAccess} = this.props;
const {config, license, buildEnterpriseReady, consoleAccess, cloud} = this.props;
const sidebarSections = [];
Object.entries(definition).forEach(([key, section]) => {
let isSectionHidden = false;
if (section.isHidden) {
isSectionHidden = typeof section.isHidden === 'function' ? section.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess) : Boolean(section.isHidden);
isSectionHidden = typeof section.isHidden === 'function' ? section.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess, cloud) : Boolean(section.isHidden);
}
if (!isSectionHidden) {
const sidebarItems = [];
Expand All @@ -187,7 +188,7 @@ class AdminSidebar extends React.PureComponent {
}

if (item.isHidden) {
if (typeof item.isHidden === 'function' ? item.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess) : Boolean(item.isHidden)) {
if (typeof item.isHidden === 'function' ? item.isHidden(config, this.state, license, buildEnterpriseReady, consoleAccess, cloud) : Boolean(item.isHidden)) {
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions components/admin_console/admin_sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function mapStateToProps(state) {
siteName,
adminDefinition,
consoleAccess,
cloud: state.entities.cloud,
};
}

Expand Down
1 change: 1 addition & 0 deletions components/admin_console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function mapStateToProps(state: GlobalState) {
roles: getRoles(state),
adminDefinition,
consoleAccess,
cloud: state.entities.cloud,
};
}

Expand Down

0 comments on commit b873644

Please sign in to comment.