Skip to content

Commit 02256ea

Browse files
committed
feat: add new role IsDatabaseAllowed and shrink breadcrumbs
1 parent 932917b commit 02256ea

File tree

7 files changed

+35
-9
lines changed

7 files changed

+35
-9
lines changed

src/containers/Header/Header.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {DEVELOPER_UI_TITLE} from '../../utils/constants';
1414
import {createDeveloperUIInternalPageHref} from '../../utils/developerUI/developerUI';
1515
import {useTypedSelector} from '../../utils/hooks';
1616
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
17-
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
17+
import {
18+
useIsOnlyDatabaseUser,
19+
useIsUserAllowedToMakeChanges,
20+
} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
1821

1922
import {getBreadcrumbs} from './breadcrumbs';
2023
import {headerKeyset} from './i18n';
@@ -27,6 +30,7 @@ function Header() {
2730
const {page, pageBreadcrumbsOptions} = useTypedSelector((state) => state.header);
2831
const singleClusterMode = useTypedSelector((state) => state.singleClusterMode);
2932
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
33+
const isOnlyDatabaseUser = useIsOnlyDatabaseUser();
3034

3135
const {title: clusterTitle} = useClusterBaseInfo();
3236

@@ -39,7 +43,7 @@ function Header() {
3943
useAddClusterFeatureAvailable() && uiFactory.onAddCluster !== undefined;
4044

4145
const breadcrumbItems = React.useMemo(() => {
42-
let options = {...pageBreadcrumbsOptions, singleClusterMode};
46+
let options = {...pageBreadcrumbsOptions, singleClusterMode, isOnlyDatabaseUser};
4347

4448
if (clusterTitle) {
4549
options = {
@@ -53,7 +57,7 @@ function Header() {
5357
return breadcrumbs.map((item) => {
5458
return {...item, action: () => {}};
5559
});
56-
}, [clusterTitle, page, pageBreadcrumbsOptions, singleClusterMode]);
60+
}, [clusterTitle, page, pageBreadcrumbsOptions, singleClusterMode, isOnlyDatabaseUser]);
5761

5862
const renderRightControls = () => {
5963
const elements: React.ReactNode[] = [];

src/containers/Header/breadcrumbs.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ const getQueryForTenant = (type: 'nodes' | 'tablets') => ({
4646
[TenantTabsGroups.diagnosticsTab]: TENANT_DIAGNOSTICS_TABS_IDS[type],
4747
});
4848

49-
const getClustersBreadcrumbs: GetBreadcrumbs<ClustersBreadcrumbsOptions> = () => {
49+
const getClustersBreadcrumbs: GetBreadcrumbs<ClustersBreadcrumbsOptions> = (options) => {
50+
if (options.isOnlyDatabaseUser) {
51+
return [];
52+
}
5053
return [
5154
{
5255
text: headerKeyset('breadcrumbs.clusters'),
@@ -56,7 +59,11 @@ const getClustersBreadcrumbs: GetBreadcrumbs<ClustersBreadcrumbsOptions> = () =>
5659
};
5760

5861
const getClusterBreadcrumbs: GetBreadcrumbs<ClusterBreadcrumbsOptions> = (options, query = {}) => {
59-
const {clusterName, clusterTab, singleClusterMode} = options;
62+
const {clusterName, clusterTab, singleClusterMode, isOnlyDatabaseUser} = options;
63+
64+
if (isOnlyDatabaseUser) {
65+
return [];
66+
}
6067

6168
let breadcrumbs: RawBreadcrumbItem[] = [];
6269

src/store/reducers/authentication/authentication.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export const slice = createSlice({
2626
}
2727
},
2828
setUser: (state, action: PayloadAction<TUserToken>) => {
29-
const {UserSID, AuthType, IsMonitoringAllowed} = action.payload;
29+
const {UserSID, AuthType, IsMonitoringAllowed, IsDatabaseAllowed, IsViewerAllowed} =
30+
action.payload;
3031

3132
state.user = AuthType === 'Login' ? UserSID : undefined;
3233

@@ -35,17 +36,20 @@ export const slice = createSlice({
3536
// Otherwise every user is allowed to make changes
3637
// Anyway there will be guards on backend
3738
state.isUserAllowedToMakeChanges = IsMonitoringAllowed !== false;
39+
state.isOnlyDatabaseUser = IsDatabaseAllowed && IsViewerAllowed === false;
3840
},
3941
},
4042
selectors: {
4143
selectIsUserAllowedToMakeChanges: (state) => state.isUserAllowedToMakeChanges,
44+
selectIsOnlyDatabaseUser: (state) => state.isOnlyDatabaseUser,
4245
selectUser: (state) => state.user,
4346
},
4447
});
4548

4649
export default slice.reducer;
4750
export const {setIsAuthenticated, setUser} = slice.actions;
48-
export const {selectIsUserAllowedToMakeChanges, selectUser} = slice.selectors;
51+
export const {selectIsUserAllowedToMakeChanges, selectIsOnlyDatabaseUser, selectUser} =
52+
slice.selectors;
4953

5054
export const authenticationApi = api.injectEndpoints({
5155
endpoints: (build) => ({
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export interface AuthenticationState {
22
isAuthenticated: boolean;
33
isUserAllowedToMakeChanges?: boolean;
4+
isOnlyDatabaseUser?: boolean;
45
user: string | undefined;
56
}

src/store/reducers/header/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export type Page =
1515
| 'storageGroup'
1616
| undefined;
1717

18-
export interface ClustersBreadcrumbsOptions {}
18+
export interface ClustersBreadcrumbsOptions {
19+
isOnlyDatabaseUser?: boolean;
20+
}
1921

2022
export interface ClusterBreadcrumbsOptions extends ClustersBreadcrumbsOptions {
2123
clusterName?: string;

src/types/api/whoami.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export interface TUserToken {
99
OriginalUserToken?: string;
1010
AuthType?: string;
1111

12+
/** Is user allowed to view only database specific data */
13+
IsDatabaseAllowed?: boolean;
1214
/** Is user allowed to view data */
1315
IsViewerAllowed?: boolean;
1416
/** Is user allowed to view deeper and make simple changes */
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
1+
import {
2+
selectIsOnlyDatabaseUser,
3+
selectIsUserAllowedToMakeChanges,
4+
} from '../../store/reducers/authentication/authentication';
25

36
import {useTypedSelector} from './useTypedSelector';
47

58
export function useIsUserAllowedToMakeChanges() {
69
return useTypedSelector(selectIsUserAllowedToMakeChanges);
710
}
11+
export function useIsOnlyDatabaseUser() {
12+
return useTypedSelector(selectIsOnlyDatabaseUser);
13+
}

0 commit comments

Comments
 (0)