Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat(role-fga): added feature flag gate on roles fga - create and details page (#11350)

SagarRajput-7d5a50fe4560d
diff --git a/frontend/src/components/RolesSelect/RolesSelect.tsx b/frontend/src/components/RolesSelect/RolesSelect.tsx
index 7607d5d8c1..34c6e2ac0b 100644
--- a/frontend/src/components/RolesSelect/RolesSelect.tsx
+++ b/frontend/src/components/RolesSelect/RolesSelect.tsx
@@ -144,6 +144,7 @@ function RolesSelect(props: RolesSelectProps): JSX.Element {
loading={loading}
notFoundContent={notFoundContent}
options={options}
+ optionFilterProp="label"
optionRender={(option): JSX.Element => (
<Checkbox
checked={value.includes(option.value as string)}
@@ -162,6 +163,7 @@ function RolesSelect(props: RolesSelectProps): JSX.Element {
return (
<Select
id={id}
+ showSearch
value={value || undefined}
onChange={onChange}
placeholder={placeholder}
@@ -170,6 +172,7 @@ function RolesSelect(props: RolesSelectProps): JSX.Element {
loading={loading}
notFoundContent={notFoundContent}
options={options}
+ optionFilterProp="label"
getPopupContainer={getPopupContainer}
disabled={disabled}
/>
diff --git a/frontend/src/constants/features.ts b/frontend/src/constants/features.ts
index 928b1d7647..7991b5a3be 100644
--- a/frontend/src/constants/features.ts
+++ b/frontend/src/constants/features.ts
@@ -10,4 +10,5 @@ export enum FeatureKeys {
ONBOARDING_V3 = 'onboarding_v3',
DOT_METRICS_ENABLED = 'dot_metrics_enabled',
USE_JSON_BODY = 'use_json_body',
+ USE_FINE_GRAINED_AUTHZ = 'use_fine_grained_authz',
}
diff --git a/frontend/src/container/RolesSettings/RoleDetails/RoleDetailsPage.tsx b/frontend/src/container/RolesSettings/RoleDetails/RoleDetailsPage.tsx
index 5a004e9307..5eb4b5247e 100644
--- a/frontend/src/container/RolesSettings/RoleDetails/RoleDetailsPage.tsx
+++ b/frontend/src/container/RolesSettings/RoleDetails/RoleDetailsPage.tsx
@@ -21,14 +21,13 @@ import {
buildRoleUpdatePermission,
} from 'hooks/useAuthZ/permissions/role.permissions';
import { useAuthZ } from 'hooks/useAuthZ/useAuthZ';
+import { useRolesFeatureGate } from 'hooks/useRolesFeatureGate';
import type { AuthzResources } from '../utils';
import ErrorInPlace from 'components/ErrorInPlace/ErrorInPlace';
import ROUTES from 'constants/routes';
import { capitalize } from 'lodash-es';
-import { useAppContext } from 'providers/App/App';
import { useErrorModal } from 'providers/ErrorModalProvider';
-import { LicenseStatus } from 'types/api/licensesV3/getActive';
import { RoleType } from 'types/roles';
import { handleApiError, toAPIError } from 'utils/errorUtils';
@@ -54,7 +53,8 @@ function RoleDetailsPage(): JSX.Element {
const queryClient = useQueryClient();
const { showErrorModal } = useErrorModal();
- const { activeLicense, isFetchingActiveLicense } = useAppContext();
+ const { isRolesEnabled, isLoading: isRolesGateLoading } =
+ useRolesFeatureGate();
const authzResources: AuthzResources = permissionsType.data;
@@ -161,7 +161,7 @@ function RoleDetailsPage(): JSX.Element {
},
});
- if (isFetchingActiveLicense) {
+ if (isRolesGateLoading) {
return (
<div className="role-details-page">
<Skeleton
@@ -173,7 +173,7 @@ function RoleDetailsPage(): JSX.Element {
);
}
- if (activeLicense?.status !== LicenseStatus.VALID) {
+ if (!isRolesEnabled) {
return <Redirect to={ROUTES.ROLES_SETTINGS} />;
}
diff --git a/frontend/src/container/RolesSettings/RoleDetails/__tests__/RoleDetailsPage.test.tsx b/frontend/src/container/RolesSettings/RoleDetails/__tests__/RoleDetailsPage.test.tsx
index 5bba9b9504..512e5ff963 100644
--- a/frontend/src/container/RolesSettings/RoleDetails/__tests__/RoleDetailsPage.test.tsx
+++ b/frontend/src/container/RolesSettings/RoleDetails/__tests__/RoleDetailsPage.test.tsx
@@ -7,6 +7,7 @@ import { server } from 'mocks-server/server';
import { rest } from 'msw';
import { Route, Switch } from 'react-router-dom';
import {
+ defaultFeatureFlags,
fireEvent,
render,
screen,
@@ -14,6 +15,7 @@ import {
waitFor,
within,
} from 'tests/test-utils';
+import { FeatureKeys } from 'constants/features';
import { useAuthZ } from 'hooks/useAuthZ/useAuthZ';
import {
invalidLicense,
@@ -254,6 +256,34 @@ describe('RoleDetailsPage', () => {
).resolves.toBeInTheDocument();
});
+ it('redirects to the roles list when fine-grained authz flag is inactive', async () => {
+ render(
+ <Switch>
+ <Route path="/settings/roles/:roleId">
+ <RoleDetailsPage />
+ </Route>
+ <Route path="/settings/roles" exact>
+ <div data-testid="roles-list-redirect-target" />
+ </Route>
+ </Switch>,
+ undefined,
+ {
+ initialRoute: `/settings/roles/${CUSTOM_ROLE_ID}`,
+ appContextOverrides: {
+ featureFlags: defaultFeatureFlags.map((f) =>
+ f.name === FeatureKeys.USE_FINE_GRAINED_AUTHZ
+ ? { ...f, active: false }
+ : f,
+ ),
+ },
+ },
+ );
+
+ await expect(
+ screen.findByTestId('roles-list-redirect-target'),
+ ).resolves.toBeInTheDocument();
+ });
+
describe('permission side panel', () => {
beforeEach(() => {
// Both hooks mocked so data renders synchronously — no React Query scheduler or MSW round-trip.
diff --git a/frontend/src/container/RolesSettings/RolesComponents/RolesListingTable.tsx b/frontend/src/container/RolesSettings/RolesComponents/RolesListingTable.tsx
index f9718eb110..55421c50ab 100644
--- a/frontend/src/container/RolesSettings/RolesComponents/RolesListingTable.tsx
+++ b/frontend/src/container/RolesSettings/RolesComponents/RolesListingTable.tsx
@@ -9,11 +9,10 @@ import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';
import ROUTES from 'constants/routes';
import { RoleListPermission } from 'hooks/useAuthZ/permissions/role.permissions';
import { useAuthZ } from 'hooks/useAuthZ/useAuthZ';
+import { useRolesFeatureGate } from 'hooks/useRolesFeatureGate';
import useUrlQuery from 'hooks/useUrlQuery';
import LineClampedText from 'periscope/components/LineClampedText/LineClampedText';
-import { useAppContext } from 'providers/App/App';
import { useTimezone } from 'providers/Timezone';
-import { LicenseStatus } from 'types/api/licensesV3/getActive';
import { RoleType } from 'types/roles';
import { toAPIError } from 'utils/errorUtils';
@@ -32,8 +31,7 @@ interface RolesListingTableProps {
function RolesListingTable({
searchQuery,
}: RolesListingTableProps): JSX.Element {
- const { activeLicense } = useAppContext();
- const isValidLicense = activeLicense?.status === LicenseStatus.VALID;
+ const { isRolesEnabled } = useRolesFeatureGate();
const { permissions: listPerms, isLoading: isAuthZLoading } = useAuthZ([
RoleListPermission,
@@ -208,11 +206,11 @@ function RolesListingTable({
const renderRow = (role: AuthtypesRoleDTO): JSX.Element => (
<div
key={role.id}
- className={`roles-table-row${isValidLicense ? ' roles-table-row--clickable' : ''}`}
- role={isValidLicense ? 'button' : undefined}
- tabIndex={isValidLicense ? 0 : undefined}
+ className={`roles-table-row${isRolesEnabled ? ' roles-table-row--clickable' : ''}`}
+ role={isRolesEnabled ? 'button' : undefined}
+ tabIndex={isRolesEnabled ? 0 : undefined}
onClick={
- isValidLicense
+ isRolesEnabled
? (): void => {
if (role.id) {
navigateToRole(role.id, role.name);
@@ -221,7 +219,7 @@ function RolesListingTable({
: undefined
}
onKeyDown={
- isValidLicense
+ isRolesEnabled
? (e): void => {
if ((e.key === 'Enter' || e.key === ' ') && role.id) {
navigateToRole(role.id, role.name);
diff --git a/frontend/src/container/RolesSettings/RolesSettings.tsx b/frontend/src/container/RolesSettings/RolesSettings.tsx
index 7e07dff0ee..0b287fd785 100644
--- a/frontend/src/container/RolesSettings/RolesSettings.tsx
+++ b/frontend/src/container/RolesSettings/RolesSettings.tsx
@@ -4,8 +4,7 @@ import { Button } from '@signozhq/ui/button';
import { Input } from '@signozhq/ui/input';
import AuthZTooltip from 'components/AuthZTooltip/AuthZTooltip';
import { RoleCreatePermission } from 'hooks/useAuthZ/permissions/role.permissions';
-import { useAppContext } from 'providers/App/App';
-import { LicenseStatus } from 'types/api/licensesV3/getActive';
+import { useRolesFeatureGate } from 'hooks/useRolesFeatureGate';
import CreateRoleModal from './RolesComponents/CreateRoleModal';
import RolesListingTable from './RolesComponents/RolesListingTable';
@@ -15,8 +14,7 @@ import './RolesSettings.styles.scss';
function RolesSettings(): JSX.Element {
const [searchQuery, setSearchQuery] = useState('');
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
- const { activeLicense } = useAppContext();
- const isValidLicense = activeLicense?.status === LicenseStatus.VALID;
+ const { isRolesEnabled } = useRolesFeatureGate();
return (
<div className="roles-settings" data-testid="roles-settings">
@@ -42,7 +40,7 @@ function RolesSettings(): JSX.Element {
value={searchQuery}
onChange={(e): void => setSearchQuery(e.target.value)}
/>
- {isValidLicense && (
+ {isRolesEnabled && (
<AuthZTooltip checks={[RoleCreatePermission]}>
<Button
variant="solid"
diff --git a/frontend/src/container/RolesSettings/__tests__/RolesSettings.test.tsx b/frontend/src/container/RolesSettings/__tests__/RolesSettings.test.tsx
index 0d942b54c9..21611f172e 100644
--- a/frontend/src/container/RolesSettings/__tests__/RolesSettings.test.tsx
+++ b/frontend/src/container/RolesSettings/__tests__/RolesSettings.test.tsx
@@ -4,7 +4,13 @@ import {
} from 'mocks-server/__mockdata__/roles';
import { server } from 'mocks-server/server';
import { rest } from 'msw';
-import { fireEvent, render, screen } from 'tests/test-utils';
+import {
+ defaultFeatureFlags,
+ fireEvent,
+ render,
+ screen,
+} from 'tests/test-utils';
+import { FeatureKeys } from 'constants/features';
import { useAuthZ } from 'hooks/useAuthZ/useAuthZ';
import { invalidLicense, mockUseAuthZGrantAll } from 'tests/authz-test-utils';
@@ -176,6 +182,30 @@ describe('RolesSettings', () => {
}
});
+ it('hides the create button and disables row clicks when fine-grained authz flag is inactive', async () => {
+ render(<RolesSettings />, undefined, {
+ appContextOverrides: {
+ featureFlags: defaultFeatureFlags.map((f) =>
+ f.name === FeatureKeys.USE_FINE_GRAINED_AUTHZ
+ ? { ...f, active: false }
+ : f,
+ ),
+ },
+ });
+
+ await expect(screen.findByText('signoz-admin')).resolves.toBeInTheDocument();
+
+ expect(
+ screen.queryByRole('button', { name: /custom role/i }),
+ ).not.toBeInTheDocument();
+
+ const rows = document.querySelectorAll('.roles-table-row');
+ rows.forEach((row) => {
+ expect(row).not.toHaveClass('roles-table-row--clickable');
+ expect(row.getAttribute('role')).not.toBe('button');
+ });
+ });
+
it('hides the create button and disables row clicks when license is not valid', async () => {
render(<RolesSettings />, undefined, {
appContextOverrides: { activeLicense: invalidLicense },
diff --git a/frontend/src/hooks/useRolesFeatureGate.ts b/frontend/src/hooks/useRolesFeatureGate.ts
new file mode 100644
index 0000000000..ae7442dabc
--- /dev/null
+++ b/frontend/src/hooks/useRolesFeatureGate.ts
@@ -0,0 +1,27 @@
+import { FeatureKeys } from 'constants/features';
+import { useAppContext } from 'providers/App/App';
+import { LicenseStatus } from 'types/api/licensesV3/getActive';
+
+export const useRolesFeatureGate = (): {
+ isRolesEnabled: boolean;
+ isLoading: boolean;
+} => {
+ const {
+ activeLicense,
+ featureFlags,
+ isFetchingActiveLicense,
+ isFetchingFeatureFlags,
+ } = useAppContext();
+
+ const isValidLicense = activeLicense?.status === LicenseStatus.VALID;
+ const isFineGrainedAuthzEnabled =
+ featureFlags?.find((f) => f.name === FeatureKeys.USE_FINE_GRAINED_AUTHZ)
+ ?.active ?? false;
+
+ return {
+ isRolesEnabled: isValidLicense && isFineGrainedAuthzEnabled,
+ isLoading:
+ (isFetchingActiveLicense && !activeLicense) ||
+ (isFetchingFeatureFlags && !featureFlags),
+ };
+};
diff --git a/frontend/src/tests/test-utils.tsx b/frontend/src/tests/test-utils.tsx
index 3ea8ecc5e4..b86ed8d34a 100644
--- a/frontend/src/tests/test-utils.tsx
+++ b/frontend/src/tests/test-utils.tsx
@@ -105,6 +105,59 @@ jest.mock('react-i18next', () => ({
}),
}));
+export const defaultFeatureFlags = [
+ { name: FeatureKeys.SSO, active: true, usage: 0, usage_limit: -1, route: '' },
+ {
+ name: FeatureKeys.USE_SPAN_METRICS,
+ active: false,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+ {
+ name: FeatureKeys.GATEWAY,
+ active: true,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+ {
+ name: FeatureKeys.PREMIUM_SUPPORT,
+ active: true,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+ {
+ name: FeatureKeys.ANOMALY_DETECTION,
+ active: true,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+ {
+ name: FeatureKeys.ONBOARDING,
+ active: true,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+ {
+ name: FeatureKeys.CHAT_SUPPORT,
+ active: true,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+ {
+ name: FeatureKeys.USE_FINE_GRAINED_AUTHZ,
+ active: true,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+];
+
export function getAppContextMock(
role: string,
appContextOverrides?: Partial<IAppContext>,
@@ -168,57 +221,7 @@ export function getAppContextMock(
hasEditPermission: role === USER_ROLES.ADMIN || role === USER_ROLES.EDITOR,
isFetchingUser: false,
userFetchError: null,
- featureFlags: [
- {
- name: FeatureKeys.SSO,
- active: true,
- usage: 0,
- usage_limit: -1,
- route: '',
- },
- {
- name: FeatureKeys.USE_SPAN_METRICS,
- active: false,
- usage: 0,
- usage_limit: -1,
- route: '',
- },
- {
- name: FeatureKeys.GATEWAY,
- active: true,
- usage: 0,
- usage_limit: -1,
- route: '',
- },
- {
- name: FeatureKeys.PREMIUM_SUPPORT,
- active: true,
- usage: 0,
- usage_limit: -1,
- route: '',
- },
- {
- name: FeatureKeys.ANOMALY_DETECTION,
- active: true,
- usage: 0,
- usage_limit: -1,
- route: '',
- },
- {
- name: FeatureKeys.ONBOARDING,
- active: true,
- usage: 0,
- usage_limit: -1,
- route: '',
- },
- {
- name: FeatureKeys.CHAT_SUPPORT,
- active: true,
- usage: 0,
- usage_limit: -1,
- route: '',
- },
- ],
+ featureFlags: defaultFeatureFlags,
isFetchingFeatureFlags: false,
featureFlagsFetchError: null,
hostsData: null,