Skip to content

Commit

Permalink
make permission errors consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
duranb committed Oct 31, 2024
1 parent ef5c351 commit 95c2dd5
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 37 deletions.
44 changes: 33 additions & 11 deletions src/components/constraints/ConstraintListItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import VisibleShowIcon from '@nasa-jpl/stellar/icons/visible_show.svg?component';
import WarningIcon from '@nasa-jpl/stellar/icons/warning.svg?component';
import { createEventDispatcher } from 'svelte';
import { PlanStatusMessages } from '../../enums/planStatusMessages';
import { SearchParameters } from '../../enums/searchParameters';
import { Status } from '../../enums/status';
import type {
Expand All @@ -31,10 +30,11 @@
export let constraint: ConstraintMetadata;
export let constraintPlanSpec: ConstraintPlanSpecification;
export let constraintResponse: ConstraintResponse;
export let editPermissionError: string = 'You do not have permission to edit constraints for this plan.';
export let modelId: number | undefined;
export let hasReadPermission: boolean = false;
export let hasEditPermission: boolean = false;
export let readOnly: boolean = false;
export let readPermissionError: string = 'You do not have permission to view this constraint.';
export let totalViolationCount: number = 0;
export let visible: boolean = true;
Expand Down Expand Up @@ -117,9 +117,7 @@
on:click|stopPropagation
use:permissionHandler={{
hasPermission: hasEditPermission,
permissionError: readOnly
? PlanStatusMessages.READ_ONLY
: 'You do not have permission to edit plan constraints',
permissionError: editPermissionError,
}}
use:tooltip={{
content: `${constraintPlanSpec.enabled ? 'Disable constraint' : 'Enable constraint'} on plan`,
Expand Down Expand Up @@ -173,9 +171,7 @@
on:click|stopPropagation
use:permissionHandler={{
hasPermission: hasEditPermission,
permissionError: readOnly
? PlanStatusMessages.READ_ONLY
: 'You do not have permission to edit plan constraints',
permissionError: editPermissionError,
}}
>
<option value={null}>Always use latest</option>
Expand Down Expand Up @@ -206,16 +202,42 @@
permissionHandler,
{
hasPermission: hasReadPermission,
permissionError: 'You do not have permission to edit this constraint',
permissionError: readPermissionError,
},
],
]}
>
View Constraint
</ContextMenuItem>
{#if version?.type === 'JAR'}
<ContextMenuItem on:click={onDuplicateConstraintInvocation}>Duplicate Invocation</ContextMenuItem>
<ContextMenuItem on:click={onDeleteConstraintInvocation}>Delete Invocation</ContextMenuItem>
<ContextMenuItem
on:click={onDuplicateConstraintInvocation}
use={[
[
permissionHandler,
{
hasPermission: hasEditPermission,
permissionError: editPermissionError,
},
],
]}
>
Duplicate Invocation
</ContextMenuItem>
<ContextMenuItem
on:click={onDeleteConstraintInvocation}
use={[
[
permissionHandler,
{
hasPermission: hasEditPermission,
permissionError: editPermissionError,
},
],
]}
>
Delete Invocation
</ContextMenuItem>
{/if}
</svelte:fragment>

Expand Down
7 changes: 6 additions & 1 deletion src/components/constraints/ConstraintsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
let showAll: boolean = true;
let filterText: string = '';
let filteredConstraints: ConstraintPlanSpecification[] = [];
let hasSpecEditPermission: boolean;
let endTime: string;
let endTimeField: FieldStore<string>;
let numOfPrivateConstraints: number = 0;
Expand All @@ -72,6 +73,7 @@
} else {
endTime = '';
}
hasSpecEditPermission = featurePermissions.constraintsPlanSpec.canUpdate(user, $plan) && !$planReadOnly;
}
$: startTimeField = field<string>(startTime, [required, $plugins.time.primary.validate]);
Expand Down Expand Up @@ -377,8 +379,11 @@
constraint={$constraintsMap[constraint.constraint_id]}
constraintPlanSpec={$allowedConstraintPlanSpecMap[constraint.constraint_id]}
constraintResponse={constraintToConstraintResponseMap[constraint.constraint_id]}
editPermissionError={$planReadOnly
? PlanStatusMessages.READ_ONLY
: 'You do not have permission to edit constraints for this plan.'}
hasEditPermission={hasSpecEditPermission}
hasReadPermission={featurePermissions.constraints.canRead(user)}
hasEditPermission={$plan ? featurePermissions.constraintsPlanSpec.canUpdate(user, $plan) : false}
modelId={$plan?.model.id}
totalViolationCount={$constraintResponseMap[constraint.constraint_id]?.results.violations?.length || 0}
visible={$constraintVisibilityMap[constraint.constraint_id]}
Expand Down
9 changes: 7 additions & 2 deletions src/components/scheduling/SchedulingConditionsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
let activeElement: HTMLElement;
let conditionsFilterText: string = '';
let hasSpecEditPermission: boolean;
let filteredSchedulingConditionSpecs: SchedulingConditionPlanSpecification[] = [];
let numOfPrivateConditions: number = 0;
let visibleSchedulingConditionSpecs: SchedulingConditionPlanSpecification[] = [];
$: if ($plan) {
hasSpecEditPermission = featurePermissions.schedulingConditionsPlanSpec.canUpdate(user, $plan) && !$planReadOnly;
}
// TODO: remove this after db merge as it becomes redundant
$: visibleSchedulingConditionSpecs = $allowedSchedulingConditionSpecs.filter(
({ condition_metadata: conditionMetadata }) => {
Expand Down Expand Up @@ -132,9 +136,10 @@
<SchedulingCondition
condition={$schedulingConditionsMap[specCondition.condition_id]}
conditionPlanSpec={specCondition}
hasEditPermission={$plan ? featurePermissions.schedulingConditionsPlanSpec.canUpdate(user, $plan) : false}
hasEditPermission={hasSpecEditPermission}
hasReadPermission={featurePermissions.schedulingConditions.canRead(user)}
modelId={$plan?.model.id}
permissionError={$planReadOnly
editPermissionError={$planReadOnly
? PlanStatusMessages.READ_ONLY
: 'You do not have permission to edit scheduling conditions for this plan.'}
on:updateConditionPlanSpec={onUpdateCondition}
Expand Down
7 changes: 4 additions & 3 deletions src/components/scheduling/SchedulingGoalsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,14 @@
{#each filteredSchedulingGoalSpecs as specGoal (specGoal.goal_invocation_id)}
{#if $schedulingGoalsMap[specGoal.goal_id]}
<SchedulingGoal
editPermissionError={$planReadOnly
? PlanStatusMessages.READ_ONLY
: 'You do not have permission to edit scheduling goals for this plan.'}
hasEditPermission={hasSpecEditPermission}
hasReadPermission={featurePermissions.schedulingGoals.canRead(user)}
goal={$schedulingGoalsMap[specGoal.goal_id]}
goalPlanSpec={specGoal}
modelId={$plan?.model.id}
permissionError={$planReadOnly
? PlanStatusMessages.READ_ONLY
: 'You do not have permission to edit scheduling goals for this plan.'}
on:updateGoalPlanSpec={onUpdateGoal}
on:duplicateGoalInvocation={onDuplicateGoalInvocation}
on:deleteGoalInvocation={onDeleteGoalInvocation}
Expand Down
16 changes: 7 additions & 9 deletions src/components/scheduling/conditions/SchedulingCondition.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<script lang="ts">
import { base } from '$app/paths';
import { createEventDispatcher } from 'svelte';
import { PlanStatusMessages } from '../../../enums/planStatusMessages';
import { SearchParameters } from '../../../enums/searchParameters';
import type { SchedulingConditionMetadata, SchedulingConditionPlanSpecification } from '../../../types/scheduling';
import { getTarget } from '../../../utilities/generic';
Expand All @@ -14,10 +13,11 @@
export let condition: SchedulingConditionMetadata;
export let conditionPlanSpec: SchedulingConditionPlanSpecification;
export let editPermissionError: string = 'You do not have permission to edit scheduling conditions for this plan.';
export let hasEditPermission: boolean = false;
export let hasReadPermission: boolean = false;
export let modelId: number | undefined;
export let permissionError: string = '';
export let readOnly: boolean = false;
export let readPermissionError: string = 'You do not have permission to view this scheduling condition.';
const dispatch = createEventDispatcher<{
updateConditionPlanSpec: SchedulingConditionPlanSpecification;
Expand Down Expand Up @@ -56,7 +56,7 @@
on:click|stopPropagation
use:permissionHandler={{
hasPermission: hasEditPermission,
permissionError,
permissionError: editPermissionError,
}}
use:tooltip={{
content: `${conditionPlanSpec.enabled ? 'Disable condition' : 'Enable condition'} on plan`,
Expand All @@ -75,9 +75,7 @@
on:click|stopPropagation
use:permissionHandler={{
hasPermission: hasEditPermission,
permissionError: readOnly
? PlanStatusMessages.READ_ONLY
: 'You do not have permission to edit plan conditions',
permissionError: editPermissionError,
}}
>
<option value={null}>Always use latest</option>
Expand All @@ -103,8 +101,8 @@
[
permissionHandler,
{
hasPermission: hasEditPermission,
permissionError,
hasPermission: hasReadPermission,
permissionError: readPermissionError,
},
],
]}
Expand Down
48 changes: 37 additions & 11 deletions src/components/scheduling/goals/SchedulingGoal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import CaretDownFillIcon from 'bootstrap-icons/icons/caret-down-fill.svg?component';
import CaretUpFillIcon from 'bootstrap-icons/icons/caret-up-fill.svg?component';
import { createEventDispatcher } from 'svelte';
import { PlanStatusMessages } from '../../../enums/planStatusMessages';
import { SearchParameters } from '../../../enums/searchParameters';
import type { FormParameter } from '../../../types/parameter';
import type {
Expand All @@ -22,12 +21,13 @@
import SchedulingGoalAnalysesActivities from './SchedulingGoalAnalysesActivities.svelte';
import SchedulingGoalAnalysesBadge from './SchedulingGoalAnalysesBadge.svelte';
export let editPermissionError: string = 'You do not have permission to edit scheduling goals for this plan.';
export let goal: SchedulingGoalMetadata;
export let goalPlanSpec: SchedulingGoalPlanSpecification;
export let hasEditPermission: boolean = false;
export let hasReadPermission: boolean = false;
export let modelId: number | undefined;
export let permissionError: string = '';
export let readOnly: boolean = false;
export let readPermissionError: string = 'You do not have permission to view this scheduling goal.';
const dispatch = createEventDispatcher<{
deleteGoalInvocation: SchedulingGoalPlanSpecification;
Expand Down Expand Up @@ -157,7 +157,7 @@
on:click|stopPropagation
use:permissionHandler={{
hasPermission: hasEditPermission,
permissionError,
permissionError: editPermissionError,
}}
use:tooltip={{
content: `${enabled ? 'Disable goal' : 'Enable goal'} on plan`,
Expand All @@ -183,7 +183,7 @@
on:keydown={onKeyDown}
use:permissionHandler={{
hasPermission: hasEditPermission,
permissionError,
permissionError: editPermissionError,
}}
/>
{#if hasEditPermission}
Expand Down Expand Up @@ -214,7 +214,7 @@
on:click|stopPropagation
use:permissionHandler={{
hasPermission: hasEditPermission,
permissionError: readOnly ? PlanStatusMessages.READ_ONLY : 'You do not have permission to edit plan goals',
permissionError: editPermissionError,
}}
>
<option value={null}>Always use latest</option>
Expand Down Expand Up @@ -246,8 +246,8 @@
[
permissionHandler,
{
hasPermission: hasEditPermission,
permissionError,
hasPermission: hasReadPermission,
permissionError: readPermissionError,
},
],
]}
Expand All @@ -260,7 +260,7 @@
permissionHandler,
{
hasPermission: hasEditPermission,
permissionError,
permissionError: editPermissionError,
},
],
]}
Expand All @@ -277,8 +277,34 @@
</div>
</ContextMenuItem>
{#if version?.type === 'JAR'}
<ContextMenuItem on:click={onDuplicateGoalInvocation}>Duplicate Invocation</ContextMenuItem>
<ContextMenuItem on:click={onDeleteGoalInvocation}>Delete Invocation</ContextMenuItem>
<ContextMenuItem
on:click={onDuplicateGoalInvocation}
use={[
[
permissionHandler,
{
hasPermission: hasEditPermission,
permissionError: editPermissionError,
},
],
]}
>
Duplicate Invocation
</ContextMenuItem>
<ContextMenuItem
on:click={onDeleteGoalInvocation}
use={[
[
permissionHandler,
{
hasPermission: hasEditPermission,
permissionError: editPermissionError,
},
],
]}
>
Delete Invocation
</ContextMenuItem>
{/if}
</svelte:fragment>
</Collapse>
Expand Down

0 comments on commit 95c2dd5

Please sign in to comment.