Skip to content

Commit

Permalink
Add workflowUpdateEnabled boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Tideman committed Jan 15, 2025
1 parent 4e1f90e commit 0e161f2
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/config/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ disableWriteActions: false
workflowTerminateDisabled: false
workflowCancelDisabled: false
workflowSignalDisabled: false
workflowUpdateDisabled: false
workflowResetDisabled: false
batchActionsDisabled: false
startWorkflowDisabled: false
Expand Down
1 change: 1 addition & 0 deletions server/docker/config-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ disableWriteActions: {{ default .Env.TEMPORAL_DISABLE_WRITE_ACTIONS "false" }}
workflowTerminateDisabled: {{ default .Env.TEMPORAL_WORKFLOW_TERMINATE_DISABLED "false" }}
workflowCancelDisabled: {{ default .Env.TEMPORAL_WORKFLOW_CANCEL_DISABLED "false" }}
workflowSignalDisabled: {{ default .Env.TEMPORAL_WORKFLOW_SIGNAL_DISABLED "false" }}
workflowUpdateDisabled: {{ default .Env.TEMPORAL_WORKFLOW_UPDATE_DISABLED "false" }}
workflowResetDisabled: {{ default .Env.TEMPORAL_WORKFLOW_RESET_DISABLED "false" }}
batchActionsDisabled: {{ default .Env.TEMPORAL_BATCH_ACTIONS_DISABLED "false" }}
startWorkflowDisabled: {{ default .Env.TEMPORAL_START_WORKFLOW_DISABLED "false" }}
Expand Down
2 changes: 2 additions & 0 deletions server/server/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type SettingsResponse struct {
WorkflowTerminateDisabled bool
WorkflowCancelDisabled bool
WorkflowSignalDisabled bool
WorkflowUpdateDisabled bool
WorkflowResetDisabled bool
BatchActionsDisabled bool
StartWorkflowDisabled bool
Expand Down Expand Up @@ -142,6 +143,7 @@ func GetSettings(cfgProvider *config.ConfigProviderWithRefresh) func(echo.Contex
WorkflowTerminateDisabled: cfg.WorkflowTerminateDisabled,
WorkflowCancelDisabled: cfg.WorkflowCancelDisabled,
WorkflowSignalDisabled: cfg.WorkflowSignalDisabled,
WorkflowUpdateDisabled: cfg.WorkflowUpdateDisabled,
WorkflowResetDisabled: cfg.WorkflowResetDisabled,
BatchActionsDisabled: cfg.BatchActionsDisabled,
StartWorkflowDisabled: cfg.StartWorkflowDisabled,
Expand Down
1 change: 1 addition & 0 deletions server/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type (
WorkflowTerminateDisabled bool `yaml:"workflowTerminateDisabled"`
WorkflowCancelDisabled bool `yaml:"workflowCancelDisabled"`
WorkflowSignalDisabled bool `yaml:"workflowSignalDisabled"`
WorkflowUpdateDisabled bool `yaml:"workflowUpdateDisabled"`
WorkflowResetDisabled bool `yaml:"workflowResetDisabled"`
// Whether bulk/batch actions are enabled in the UI
BatchActionsDisabled bool `yaml:"batchActionsDisabled"`
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/workflow-actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import { workflowResetEnabled } from '$lib/utilities/workflow-reset-enabled';
import { workflowSignalEnabled } from '$lib/utilities/workflow-signal-enabled';
import { workflowTerminateEnabled } from '$lib/utilities/workflow-terminate-enabled';
import { workflowUpdateEnabled } from '$lib/utilities/workflow-update-enabled';
export let workflow: WorkflowExecution;
export let namespace: string;
Expand Down Expand Up @@ -49,7 +50,7 @@
namespace,
);
$: updateEnabled = workflowSignalEnabled(
$: updateEnabled = workflowUpdateEnabled(
$page.data.settings,
$coreUser,
namespace,
Expand Down
1 change: 1 addition & 0 deletions src/lib/services/settings-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const fetchSettings = async (request = fetch): Promise<Settings> => {
workflowTerminateDisabled: !!settingsResponse?.WorkflowTerminateDisabled,
workflowCancelDisabled: !!settingsResponse?.WorkflowCancelDisabled,
workflowSignalDisabled: !!settingsResponse?.WorkflowSignalDisabled,
workflowUpdateDisabled: !!settingsResponse?.WorkflowUpdateDisabled,
workflowResetDisabled: !!settingsResponse?.WorkflowResetDisabled,
batchActionsDisabled: !!settingsResponse?.BatchActionsDisabled,
startWorkflowDisabled: !!settingsResponse?.StartWorkflowDisabled,
Expand Down
1 change: 1 addition & 0 deletions src/lib/svelte-mocks/app/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const settings: Settings = {
workflowResetDisabled: false,
workflowCancelDisabled: false,
workflowSignalDisabled: false,
workflowUpdateDisabled: false,
workflowTerminateDisabled: false,
hideWorkflowQueryErrors: false,
notifyOnNewVersion: true,
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type Settings = {
workflowTerminateDisabled: boolean;
workflowCancelDisabled: boolean;
workflowSignalDisabled: boolean;
workflowUpdateDisabled: boolean;
workflowResetDisabled: boolean;
hideWorkflowQueryErrors: boolean;
batchActionsDisabled: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export type SettingsResponse = {
WorkflowTerminateDisabled: boolean;
WorkflowCancelDisabled: boolean;
WorkflowSignalDisabled: boolean;
WorkflowUpdateDisabled: boolean;
WorkflowResetDisabled: boolean;
BatchActionsDisabled: boolean;
StartWorkflowDisabled: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/lib/utilities/get-codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const defaultSettings = {
workflowTerminateDisabled: false,
workflowCancelDisabled: false,
workflowSignalDisabled: false,
workflowUpdateDisabled: false,
workflowResetDisabled: false,
batchActionsDisabled: false,
};
Expand Down
75 changes: 75 additions & 0 deletions src/lib/utilities/workflow-update-enabled.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { describe, expect, test } from 'vitest';

import { workflowUpdateEnabled } from './workflow-update-enabled';

describe('workflowUpdateEnabled', () => {
const coreUser = {
namespaceWriteDisabled: (ns: string) => ns === 'ns-write-disabled',
};

test('returns true when global write actions, signal, and namespace write actions are all enabled', () => {
expect(
workflowUpdateEnabled(
{
disableWriteActions: false,
},
coreUser,
'ns-write-enabled',
),
).toBe(true);
});

describe('returns false', () => {
test('when write actions are disabled', () => {
expect(
workflowUpdateEnabled(
{
disableWriteActions: true,
workflowUpdateDisabled: false,
},
coreUser,
'ns-write-enabled',
),
).toBe(false);
});

test('when update is disabled', () => {
expect(
workflowUpdateEnabled(
{
disableWriteActions: false,
workflowUpdateDisabled: true,
},
coreUser,
'ns-write-enabled',
),
).toBe(false);
});

test('when write actions and update are both disabled', () => {
expect(
workflowUpdateEnabled(
{
disableWriteActions: true,
workflowUpdateDisabled: true,
},
coreUser,
'ns-write-enabled',
),
).toBe(false);
});

test('when namespace write actions are disabled', () => {
expect(
workflowUpdateEnabled(
{
disableWriteActions: false,
workflowUpdateDisabled: false,
},
coreUser,
'ns-write-disabled',
),
).toBe(false);
});
});
});
14 changes: 14 additions & 0 deletions src/lib/utilities/workflow-update-enabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { CoreUser } from '$lib/models/core-user';
import type { Settings } from '$lib/types/global';

export const workflowUpdateEnabled = (
settings: Settings,
coreUser: CoreUser,
namespace: string,
): boolean => {
return (
!settings.disableWriteActions &&
!settings.workflowUpdateDisabled &&
!coreUser.namespaceWriteDisabled(namespace)
);
};

0 comments on commit 0e161f2

Please sign in to comment.