Skip to content

Commit

Permalink
update to use existing privileges values
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Mar 3, 2022
1 parent 2d9b73a commit 290bd72
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import { ROLES } from '../../../common/test';
import { getNewRule } from '../../objects/rule';
import { COLLAPSED_ACTION_BTN, RULE_CHECKBOX } from '../../screens/alerts_detection_rules';
import {
COLLAPSED_ACTION_BTN,
RULE_CHECKBOX,
RULE_NAME,
} from '../../screens/alerts_detection_rules';
import { PAGE_TITLE } from '../../screens/common/page';
import { waitForRulesTableToBeLoaded } from '../../tasks/alerts_detection_rules';
import { createCustomRule } from '../../tasks/api_calls/rules';
Expand All @@ -24,6 +28,7 @@ describe('All rules - read only', () => {
createCustomRule(getNewRule(), '1');
loginAndWaitForPageWithoutDateRange(SECURITY_DETECTIONS_RULES_URL, ROLES.reader);
waitForRulesTableToBeLoaded();
cy.get(RULE_NAME).should('have.text', getNewRule().name);
});

it('Does not display select boxes for rules', () => {
Expand All @@ -47,6 +52,7 @@ describe('All rules - read only', () => {
dismissCallOut(MISSING_PRIVILEGES_CALLOUT);
cy.reload();
cy.get(PAGE_TITLE).should('be.visible');
cy.get(RULE_NAME).should('have.text', getNewRule().name);

getCallOut(MISSING_PRIVILEGES_CALLOUT).should('not.exist');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface State {
loading: boolean;
signalIndexName: string | null;
signalIndexMappingOutdated: boolean | null;
isKibanaReadOnly: boolean | null;
}

export const initialState: State = {
Expand All @@ -43,7 +42,6 @@ export const initialState: State = {
loading: true,
signalIndexName: null,
signalIndexMappingOutdated: null,
isKibanaReadOnly: null,
};

export type Action =
Expand Down Expand Up @@ -378,6 +376,5 @@ export const useUserInfo = (): State => {
hasIndexUpdateDelete,
signalIndexName,
signalIndexMappingOutdated,
isKibanaReadOnly: (hasKibanaREAD && !canUserCRUD) || null,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ import { useUserInfo } from './detections/components/user_info';
* privileges
*/
export function useReadonlyHeader(tooltip: string) {
const { isKibanaReadOnly } = useUserInfo();
const { canUserREAD, canUserCRUD } = useUserInfo();
const chrome = useKibana().services.chrome;

// if the user is read only then display the glasses badge in the global navigation header
const setBadge = useCallback(() => {
if (isKibanaReadOnly) {
if (canUserREAD && !canUserCRUD) {
chrome.setBadge({
text: i18n.READ_ONLY_BADGE_TEXT,
tooltip,
iconType: 'glasses',
});
}
}, [chrome, isKibanaReadOnly, tooltip]);
}, [chrome, canUserREAD, canUserCRUD, tooltip]);

useEffect(() => {
setBadge();
Expand Down

0 comments on commit 290bd72

Please sign in to comment.