mirror of
https://github.com/grafana/grafana.git
synced 2026-08-19 01:34:54 -05:00
switch to using featureEnabled for enterprise features (#41559)
* switch to using featureEnabled for enterprise features
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
|
||||
import { connect, ConnectedProps } from 'react-redux';
|
||||
import { NavModel } from '@grafana/data';
|
||||
import { getNavModel } from 'app/core/selectors/navModel';
|
||||
import config from 'app/core/config';
|
||||
import { featureEnabled } from '@grafana/runtime';
|
||||
import Page from 'app/core/components/Page/Page';
|
||||
import { UserProfile } from './UserProfile';
|
||||
import { UserPermissions } from './UserPermissions';
|
||||
@@ -119,7 +119,7 @@ export class UserAdminPage extends PureComponent<Props> {
|
||||
onUserEnable={this.onUserEnable}
|
||||
onPasswordChange={this.onPasswordChange}
|
||||
/>
|
||||
{isLDAPUser && config.licenseInfo.hasLicense && ldapSyncInfo && canReadLDAPStatus && (
|
||||
{isLDAPUser && featureEnabled('ldapsync') && ldapSyncInfo && canReadLDAPStatus && (
|
||||
<UserLdapSyncInfo ldapSyncInfo={ldapSyncInfo} user={user} onUserSync={this.onUserSync} />
|
||||
)}
|
||||
<UserPermissions isGrafanaAdmin={user.isGrafanaAdmin} onGrafanaAdminChange={this.onGrafanaAdminChange} />
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import { connect, ConnectedProps } from 'react-redux';
|
||||
import { NavModel } from '@grafana/data';
|
||||
import { featureEnabled } from '@grafana/runtime';
|
||||
import { Alert, Button, LegacyForms } from '@grafana/ui';
|
||||
const { FormField } = LegacyForms;
|
||||
import { getNavModel } from 'app/core/selectors/navModel';
|
||||
import config from 'app/core/config';
|
||||
import Page from 'app/core/components/Page/Page';
|
||||
import { LdapConnectionStatus } from './LdapConnectionStatus';
|
||||
import { LdapSyncInfo } from './LdapSyncInfo';
|
||||
@@ -99,7 +99,7 @@ export class LdapPage extends PureComponent<Props, State> {
|
||||
|
||||
<LdapConnectionStatus ldapConnectionInfo={ldapConnectionInfo} />
|
||||
|
||||
{config.licenseInfo.hasLicense && ldapSyncInfo && <LdapSyncInfo ldapSyncInfo={ldapSyncInfo} />}
|
||||
{featureEnabled('ldapsync') && ldapSyncInfo && <LdapSyncInfo ldapSyncInfo={ldapSyncInfo} />}
|
||||
|
||||
{canReadLDAPUser && (
|
||||
<>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import config from 'app/core/config';
|
||||
import { dateTimeFormat, dateTimeFormatTimeAgo } from '@grafana/data';
|
||||
import { getBackendSrv, locationService } from '@grafana/runtime';
|
||||
import { featureEnabled, getBackendSrv, locationService } from '@grafana/runtime';
|
||||
import { ThunkResult, LdapUser, UserSession, UserDTO, AccessControlAction, UserFilter } from 'app/types';
|
||||
|
||||
import {
|
||||
@@ -35,7 +35,7 @@ export function loadAdminUserPage(userId: number): ThunkResult<void> {
|
||||
await dispatch(loadUserProfile(userId));
|
||||
await dispatch(loadUserOrgs(userId));
|
||||
await dispatch(loadUserSessions(userId));
|
||||
if (config.ldapEnabled && config.licenseInfo.hasLicense) {
|
||||
if (config.ldapEnabled && featureEnabled('ldapsync')) {
|
||||
await dispatch(loadLdapSyncStatus());
|
||||
}
|
||||
dispatch(userAdminPageLoadedAction(true));
|
||||
@@ -183,7 +183,7 @@ export function loadLdapSyncStatus(): ThunkResult<void> {
|
||||
return async (dispatch) => {
|
||||
// Available only in enterprise
|
||||
const canReadLDAPStatus = contextSrv.hasPermission(AccessControlAction.LDAPStatusRead);
|
||||
if (config.licenseInfo.hasLicense && canReadLDAPStatus) {
|
||||
if (featureEnabled('ldapsync') && canReadLDAPStatus) {
|
||||
const syncStatus = await getBackendSrv().get(`/api/admin/ldap-sync-status`);
|
||||
dispatch(ldapSyncStatusLoadedAction(syncStatus));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DataSourcePluginMeta, PluginType } from '@grafana/data';
|
||||
import { config, featureEnabled } from '@grafana/runtime';
|
||||
import { DataSourcePluginCategory } from 'app/types';
|
||||
import { config } from '../../../core/config';
|
||||
|
||||
export function buildCategories(plugins: DataSourcePluginMeta[]): DataSourcePluginCategory[] {
|
||||
const categories: DataSourcePluginCategory[] = [
|
||||
@@ -23,14 +23,12 @@ export function buildCategories(plugins: DataSourcePluginMeta[]): DataSourcePlug
|
||||
categoryIndex[category.id] = category;
|
||||
}
|
||||
|
||||
const { edition, hasValidLicense } = config.licenseInfo;
|
||||
|
||||
for (const plugin of plugins) {
|
||||
const enterprisePlugin = enterprisePlugins.find((item) => item.id === plugin.id);
|
||||
// Force category for enterprise plugins
|
||||
if (plugin.enterprise || enterprisePlugin) {
|
||||
plugin.category = 'enterprise';
|
||||
plugin.unlicensed = edition !== 'Open Source' && !hasValidLicense;
|
||||
plugin.unlicensed = !featureEnabled('enterprise.plugins');
|
||||
plugin.info.links = enterprisePlugin?.info?.links || plugin.info.links;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DataSourceSettings, PluginType, PluginInclude, NavModel, NavModelItem } from '@grafana/data';
|
||||
import { featureEnabled } from '@grafana/runtime';
|
||||
import config from 'app/core/config';
|
||||
import { contextSrv } from 'app/core/core';
|
||||
import { AccessControlAction } from 'app/types';
|
||||
@@ -47,7 +48,7 @@ export function buildNavModel(dataSource: DataSourceSettings, plugin: GenericDat
|
||||
});
|
||||
}
|
||||
|
||||
if (config.licenseInfo.hasLicense) {
|
||||
if (featureEnabled('dspermissions')) {
|
||||
if (contextSrv.hasPermission(AccessControlAction.DataSourcesPermissionsRead)) {
|
||||
navModel.children!.push({
|
||||
active: false,
|
||||
@@ -57,7 +58,9 @@ export function buildNavModel(dataSource: DataSourceSettings, plugin: GenericDat
|
||||
url: `datasources/edit/${dataSource.id}/permissions`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (featureEnabled('analytics')) {
|
||||
navModel.children!.push({
|
||||
active: false,
|
||||
icon: 'info-circle',
|
||||
@@ -65,7 +68,9 @@ export function buildNavModel(dataSource: DataSourceSettings, plugin: GenericDat
|
||||
text: 'Insights',
|
||||
url: `datasources/edit/${dataSource.id}/insights`,
|
||||
});
|
||||
}
|
||||
|
||||
if (featureEnabled('caching')) {
|
||||
navModel.children!.push({
|
||||
active: false,
|
||||
icon: 'database',
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
import { Badge, Button, HorizontalGroup, PluginSignatureBadge, useStyles2 } from '@grafana/ui';
|
||||
import { CatalogPlugin } from '../../types';
|
||||
import { getBadgeColor } from './sharedStyles';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { featureEnabled } from '@grafana/runtime';
|
||||
|
||||
type Props = { plugin: CatalogPlugin };
|
||||
|
||||
@@ -17,7 +17,7 @@ export function PluginEnterpriseBadge({ plugin }: Props): React.ReactElement {
|
||||
);
|
||||
};
|
||||
|
||||
if (config.licenseInfo?.hasValidLicense) {
|
||||
if (featureEnabled('enterprise.plugins')) {
|
||||
return <Badge text="Enterprise" color="blue" />;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { css } from '@emotion/css';
|
||||
|
||||
import { config } from '@grafana/runtime';
|
||||
import { config, featureEnabled } from '@grafana/runtime';
|
||||
import { HorizontalGroup, Icon, LinkButton, useStyles2 } from '@grafana/ui';
|
||||
import { GrafanaTheme2, PluginType } from '@grafana/data';
|
||||
|
||||
@@ -39,7 +39,7 @@ export const InstallControls = ({ plugin, latestCompatibleVersion }: Props) => {
|
||||
return <div className={styles.message}>Renderer plugins cannot be managed by the Plugin Catalog.</div>;
|
||||
}
|
||||
|
||||
if (plugin.isEnterprise && !config.licenseInfo?.hasValidLicense) {
|
||||
if (plugin.isEnterprise && !featureEnabled('enterprise.plugins')) {
|
||||
return (
|
||||
<HorizontalGroup height="auto" align="center">
|
||||
<span className={styles.message}>No valid Grafana Enterprise license detected.</span>
|
||||
|
||||
@@ -49,14 +49,14 @@ describe('PluginListItemBadges', () => {
|
||||
});
|
||||
|
||||
it('renders an enterprise badge (when a license is valid)', () => {
|
||||
config.licenseInfo.hasValidLicense = true;
|
||||
config.licenseInfo.enabledFeatures = { 'enterprise.plugins': true };
|
||||
render(<PluginListItemBadges plugin={{ ...plugin, isEnterprise: true }} />);
|
||||
expect(screen.getByText(/enterprise/i)).toBeVisible();
|
||||
expect(screen.queryByRole('button', { name: /learn more/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders an enterprise badge with icon and link (when a license is invalid)', () => {
|
||||
config.licenseInfo.hasValidLicense = false;
|
||||
config.licenseInfo.enabledFeatures = {};
|
||||
render(<PluginListItemBadges plugin={{ ...plugin, isEnterprise: true }} />);
|
||||
expect(screen.getByText(/enterprise/i)).toBeVisible();
|
||||
expect(screen.getByLabelText(/lock icon/i)).toBeInTheDocument();
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('Plugin details page', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
config.pluginAdminExternalManageEnabled = false;
|
||||
config.licenseInfo.hasValidLicense = false;
|
||||
config.licenseInfo.enabledFeatures = {};
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
@@ -325,7 +325,7 @@ describe('Plugin details page', () => {
|
||||
});
|
||||
|
||||
it('should display an install button for enterprise plugins if license is valid', async () => {
|
||||
config.licenseInfo.hasValidLicense = true;
|
||||
config.licenseInfo.enabledFeatures = { 'enterprise.plugins': true };
|
||||
|
||||
const { queryByRole } = renderPluginDetails({ id, isInstalled: false, isEnterprise: true });
|
||||
|
||||
@@ -333,7 +333,7 @@ describe('Plugin details page', () => {
|
||||
});
|
||||
|
||||
it('should not display install button for enterprise plugins if license is invalid', async () => {
|
||||
config.licenseInfo.hasValidLicense = false;
|
||||
config.licenseInfo.enabledFeatures = {};
|
||||
|
||||
const { queryByRole, queryByText } = renderPluginDetails({ id, isInstalled: true, isEnterprise: true });
|
||||
|
||||
@@ -772,7 +772,7 @@ describe('Plugin details page', () => {
|
||||
});
|
||||
|
||||
it('should not display an install button for enterprise plugins if license is valid', async () => {
|
||||
config.licenseInfo.hasValidLicense = true;
|
||||
config.licenseInfo.enabledFeatures = { 'enterprise.plugins': true };
|
||||
const { queryByRole, queryByText } = renderPluginDetails({ id, isInstalled: false, isEnterprise: true });
|
||||
|
||||
await waitFor(() => expect(queryByText(PluginTabLabels.OVERVIEW)).toBeInTheDocument());
|
||||
|
||||
@@ -7,10 +7,12 @@ import { User } from 'app/core/services/context_srv';
|
||||
import { NavModel } from '@grafana/data';
|
||||
import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps';
|
||||
|
||||
jest.mock('app/core/config', () => ({
|
||||
...((jest.requireActual('app/core/config') as unknown) as object),
|
||||
licenseInfo: {
|
||||
hasLicense: true,
|
||||
jest.mock('@grafana/runtime/src/config', () => ({
|
||||
...((jest.requireActual('@grafana/runtime/src/config') as unknown) as object),
|
||||
config: {
|
||||
licenseInfo: {
|
||||
enabledFeatures: { teamsync: true },
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import { getTeamLoadingNav } from './state/navModel';
|
||||
import { getNavModel } from 'app/core/selectors/navModel';
|
||||
import { contextSrv } from 'app/core/services/context_srv';
|
||||
import { NavModel } from '@grafana/data';
|
||||
import { featureEnabled } from '@grafana/runtime';
|
||||
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
||||
|
||||
interface TeamPageRouteParams {
|
||||
@@ -67,7 +68,7 @@ export class TeamPages extends PureComponent<Props, State> {
|
||||
|
||||
this.state = {
|
||||
isLoading: false,
|
||||
isSyncEnabled: config.licenseInfo.hasLicense,
|
||||
isSyncEnabled: featureEnabled('teamsync'),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Team, TeamPermissionLevel } from 'app/types';
|
||||
import config from 'app/core/config';
|
||||
import { featureEnabled } from '@grafana/runtime';
|
||||
import { NavModelItem, NavModel } from '@grafana/data';
|
||||
|
||||
export function buildNavModel(team: Team): NavModelItem {
|
||||
@@ -28,7 +28,7 @@ export function buildNavModel(team: Team): NavModelItem {
|
||||
],
|
||||
};
|
||||
|
||||
if (config.licenseInfo.hasLicense) {
|
||||
if (featureEnabled('teamsync')) {
|
||||
navModel.children.push({
|
||||
active: false,
|
||||
icon: 'sync',
|
||||
|
||||
Reference in New Issue
Block a user