Skip to content

Commit

Permalink
remove userHasNoPermissions function and remove tests, replace with j…
Browse files Browse the repository at this point in the history
…ust not canUserCRUD
  • Loading branch information
dhurley14 committed Apr 3, 2020
1 parent ad80e2d commit 93912e7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { StepScheduleRule } from '../components/step_schedule_rule';
import { StepRuleActions } from '../components/step_rule_actions';
import { DetectionEngineHeaderPage } from '../../components/detection_engine_header_page';
import * as RuleI18n from '../translations';
import { redirectToDetections, getActionMessageParams, userHasNoPermissions } from '../helpers';
import { redirectToDetections, getActionMessageParams } from '../helpers';
import {
AboutStepRule,
DefineStepRule,
Expand Down Expand Up @@ -271,7 +271,7 @@ const CreateRulePageComponent: React.FC = () => {

if (redirectToDetections(isSignalIndexExists, isAuthenticated, hasEncryptionKey)) {
return <Redirect to={`/${DETECTION_ENGINE_PAGE_NAME}`} />;
} else if (userHasNoPermissions(canUserCRUD)) {
} else if (!canUserCRUD) {
return <Redirect to={`/${DETECTION_ENGINE_PAGE_NAME}/rules`} />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import * as detectionI18n from '../../translations';
import { ReadOnlyCallOut } from '../components/read_only_callout';
import { RuleSwitch } from '../components/rule_switch';
import { StepPanel } from '../components/step_panel';
import { getStepsData, redirectToDetections, userHasNoPermissions } from '../helpers';
import { getStepsData, redirectToDetections } from '../helpers';
import * as ruleI18n from '../translations';
import * as i18n from './translations';
import { GlobalTime } from '../../../../containers/global_time';
Expand Down Expand Up @@ -224,7 +224,7 @@ const RuleDetailsPageComponent: FC<PropsFromRedux> = ({
return (
<>
{hasIndexWrite != null && !hasIndexWrite && <NoWriteSignalsCallOut />}
{userHasNoPermissions(canUserCRUD) && <ReadOnlyCallOut />}
{!canUserCRUD && <ReadOnlyCallOut />}
<WithSource sourceId="default" indexToAdd={indexToAdd}>
{({ indicesExist, indexPattern }) => {
return indicesExistOrDataTemporarilyUnavailable(indicesExist) ? (
Expand Down Expand Up @@ -261,7 +261,7 @@ const RuleDetailsPageComponent: FC<PropsFromRedux> = ({
<EuiFlexItem grow={false}>
<RuleSwitch
id={rule?.id ?? '-1'}
isDisabled={userHasNoPermissions(canUserCRUD)}
isDisabled={!canUserCRUD}
enabled={rule?.enabled ?? false}
optionLabel={i18n.ACTIVATE_RULE}
onChange={handleOnChangeEnabledRule}
Expand All @@ -274,15 +274,15 @@ const RuleDetailsPageComponent: FC<PropsFromRedux> = ({
<EuiButton
href={getEditRuleUrl(ruleId ?? '')}
iconType="controlsHorizontal"
isDisabled={userHasNoPermissions(canUserCRUD) ?? true}
isDisabled={!canUserCRUD}
>
{ruleI18n.EDIT_RULE_SETTINGS}
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<RuleActionsOverflow
rule={rule}
userHasNoPermissions={userHasNoPermissions(canUserCRUD)}
userHasNoPermissions={!canUserCRUD}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ import { StepDefineRule } from '../components/step_define_rule';
import { StepScheduleRule } from '../components/step_schedule_rule';
import { StepRuleActions } from '../components/step_rule_actions';
import { formatRule } from '../create/helpers';
import {
getStepsData,
redirectToDetections,
getActionMessageParams,
userHasNoPermissions,
} from '../helpers';
import { getStepsData, redirectToDetections, getActionMessageParams } from '../helpers';
import * as ruleI18n from '../translations';
import {
RuleStep,
Expand Down Expand Up @@ -347,7 +342,7 @@ const EditRulePageComponent: FC = () => {

if (redirectToDetections(isSignalIndexExists, isAuthenticated, hasEncryptionKey)) {
return <Redirect to={`/${DETECTION_ENGINE_PAGE_NAME}`} />;
} else if (userHasNoPermissions(canUserCRUD)) {
} else if (!canUserCRUD) {
return <Redirect to={`/${DETECTION_ENGINE_PAGE_NAME}/rules/id/${ruleId}`} />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,27 +338,4 @@ describe('rule helpers', () => {
expect(result).toEqual(aboutRuleDetailsData);
});
});

describe('userHasNoPermissions', () => {
test("returns false when user's CRUD operations are null", () => {
const result: boolean = userHasNoPermissions(null);
const userHasNoPermissionsExpectedResult = false;

expect(result).toEqual(userHasNoPermissionsExpectedResult);
});

test('returns true when user cannot CRUD', () => {
const result: boolean = userHasNoPermissions(false);
const userHasNoPermissionsExpectedResult = true;

expect(result).toEqual(userHasNoPermissionsExpectedResult);
});

test('returns false when user can CRUD', () => {
const result: boolean = userHasNoPermissions(true);
const userHasNoPermissionsExpectedResult = false;

expect(result).toEqual(userHasNoPermissionsExpectedResult);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,3 @@ export const getActionMessageParams = memoizeOne((ruleType: RuleType | undefined
...actionMessageRuleParams.map(param => `context.rule.${param}`),
];
});

// typed as null not undefined as the initial state for this value is null.
export const userHasNoPermissions = (canUserCRUD: boolean | null): boolean =>
canUserCRUD != null ? !canUserCRUD : false;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { AllRules } from './all';
import { ImportDataModal } from '../../../components/import_data_modal';
import { ReadOnlyCallOut } from './components/read_only_callout';
import { UpdatePrePackagedRulesCallOut } from './components/pre_packaged_rules/update_callout';
import { getPrePackagedRuleStatus, redirectToDetections, userHasNoPermissions } from './helpers';
import { getPrePackagedRuleStatus, redirectToDetections } from './helpers';
import * as i18n from './translations';

type Func = (refreshPrePackagedRule?: boolean) => void;
Expand Down Expand Up @@ -90,7 +90,7 @@ const RulesPageComponent: React.FC = () => {

return (
<>
{userHasNoPermissions(canUserCRUD) && <ReadOnlyCallOut />}
{!canUserCRUD && <ReadOnlyCallOut />}
<ImportDataModal
checkBoxLabel={i18n.OVERWRITE_WITH_SAME_NAME}
closeModal={() => setShowImportModal(false)}
Expand Down Expand Up @@ -120,7 +120,7 @@ const RulesPageComponent: React.FC = () => {
<EuiButton
iconType="indexOpen"
isLoading={loadingCreatePrePackagedRules}
isDisabled={userHasNoPermissions(canUserCRUD) || loading}
isDisabled={!canUserCRUD || loading}
onClick={handleCreatePrePackagedRules}
>
{i18n.LOAD_PREPACKAGED_RULES}
Expand All @@ -133,7 +133,7 @@ const RulesPageComponent: React.FC = () => {
data-test-subj="reloadPrebuiltRulesBtn"
iconType="plusInCircle"
isLoading={loadingCreatePrePackagedRules}
isDisabled={userHasNoPermissions(canUserCRUD) || loading}
isDisabled={!canUserCRUD || loading}
onClick={handleCreatePrePackagedRules}
>
{i18n.RELOAD_MISSING_PREPACKAGED_RULES(rulesNotInstalled ?? 0)}
Expand All @@ -143,7 +143,7 @@ const RulesPageComponent: React.FC = () => {
<EuiFlexItem grow={false}>
<EuiButton
iconType="importAction"
isDisabled={userHasNoPermissions(canUserCRUD) || loading}
isDisabled={!canUserCRUD || loading}
onClick={() => {
setShowImportModal(true);
}}
Expand All @@ -157,7 +157,7 @@ const RulesPageComponent: React.FC = () => {
fill
href={getCreateRuleUrl()}
iconType="plusInCircle"
isDisabled={userHasNoPermissions(canUserCRUD) || loading}
isDisabled={!canUserCRUD || loading}
>
{i18n.ADD_NEW_RULE}
</EuiButton>
Expand All @@ -175,7 +175,7 @@ const RulesPageComponent: React.FC = () => {
createPrePackagedRules={createPrePackagedRules}
loading={loading || prePackagedRuleLoading}
loadingCreatePrePackagedRules={loadingCreatePrePackagedRules}
hasNoPermissions={userHasNoPermissions(canUserCRUD)}
hasNoPermissions={!canUserCRUD}
refetchPrePackagedRulesStatus={handleRefetchPrePackagedRulesStatus}
rulesCustomInstalled={rulesCustomInstalled}
rulesInstalled={rulesInstalled}
Expand Down

0 comments on commit 93912e7

Please sign in to comment.