From 8291ec17d49ecbe69a744b6a1b6d417d640ab4a3 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 24 Dec 2024 09:31:59 -0800 Subject: [PATCH] Fix: disable email workflow type if email not enabled --- src-ui/messages.xlf | 34 +++++++++---------- .../edit-dialog/edit-dialog.component.ts | 2 +- .../workflow-edit-dialog.component.spec.ts | 10 +++++- .../workflow-edit-dialog.component.ts | 10 +++++- src-ui/src/app/data/ui-settings.ts | 6 ++++ src/documents/tests/test_api_uisettings.py | 2 ++ src/documents/views.py | 2 ++ 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index 102d50ce3..90f9287b7 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -1707,7 +1707,7 @@ src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 59 + 60 src/app/components/document-list/document-list.component.html @@ -3434,7 +3434,7 @@ src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 55 + 56 src/app/components/document-list/document-list.component.html @@ -4233,7 +4233,7 @@ src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 101 + 102 src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html @@ -4805,28 +4805,28 @@ Consume Folder src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 40 + 41 API Upload src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 44 + 45 Mail Fetch src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 48 + 49 Modified src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 63 + 64 src/app/data/document.ts @@ -4837,70 +4837,70 @@ Custom Field src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 67 + 68 Consumption Started src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 74 + 75 Document Added src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 78 + 79 Document Updated src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 82 + 83 Scheduled src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 86 + 87 Assignment src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 93 + 94 Removal src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 97 + 98 Webhook src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 105 + 106 Create new workflow src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 180 + 183 Edit workflow src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts - 184 + 187 diff --git a/src-ui/src/app/components/common/edit-dialog/edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/edit-dialog.component.ts index 3bcb6e953..afbc6c73f 100644 --- a/src-ui/src/app/components/common/edit-dialog/edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/edit-dialog.component.ts @@ -33,7 +33,7 @@ export abstract class EditDialogComponent< protected service: AbstractPaperlessService, private activeModal: NgbActiveModal, private userService: UserService, - private settingsService: SettingsService + protected settingsService: SettingsService ) { super() } diff --git a/src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.spec.ts b/src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.spec.ts index 4486c79a5..b790ab736 100644 --- a/src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.spec.ts @@ -200,7 +200,8 @@ describe('WorkflowEditDialogComponent', () => { }) it('should return source options, type options, type name, schedule date field options', () => { - // coverage + jest.spyOn(settingsService, 'get').mockReturnValue(true) + component.ngOnInit() expect(component.sourceOptions).toEqual(DOCUMENT_SOURCE_OPTIONS) expect(component.triggerTypeOptions).toEqual(WORKFLOW_TYPE_OPTIONS) expect( @@ -216,6 +217,13 @@ describe('WorkflowEditDialogComponent', () => { expect(component.scheduleDateFieldOptions).toEqual( SCHEDULE_DATE_FIELD_OPTIONS ) + + // Email disabled + jest.spyOn(settingsService, 'get').mockReturnValue(false) + component.ngOnInit() + expect(component.actionTypeOptions).toEqual( + WORKFLOW_ACTION_OPTIONS.filter((a) => a.id !== WorkflowActionType.Email) + ) }) it('should support add and remove triggers and actions', () => { diff --git a/src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts index 2face94a3..8aeab88c9 100644 --- a/src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts +++ b/src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts @@ -13,6 +13,7 @@ import { MATCH_NONE, } from 'src/app/data/matching-model' import { StoragePath } from 'src/app/data/storage-path' +import { SETTINGS_KEYS } from 'src/app/data/ui-settings' import { Workflow } from 'src/app/data/workflow' import { WorkflowAction, @@ -132,6 +133,8 @@ export class WorkflowEditDialogComponent expandedItem: number = null + private allowedActionTypes = [] + constructor( service: WorkflowService, activeModal: NgbActiveModal, @@ -206,6 +209,11 @@ export class WorkflowEditDialogComponent this.checkRemovalActionFields.bind(this) ) this.checkRemovalActionFields(this.objectForm.value) + this.allowedActionTypes = this.settingsService.get( + SETTINGS_KEYS.EMAIL_ENABLED + ) + ? WORKFLOW_ACTION_OPTIONS + : WORKFLOW_ACTION_OPTIONS.filter((a) => a.id !== WorkflowActionType.Email) } private checkRemovalActionFields(formWorkflow: Workflow) { @@ -486,7 +494,7 @@ export class WorkflowEditDialogComponent } get actionTypeOptions() { - return WORKFLOW_ACTION_OPTIONS + return this.allowedActionTypes } getActionTypeOptionName(type: WorkflowActionType): string { diff --git a/src-ui/src/app/data/ui-settings.ts b/src-ui/src/app/data/ui-settings.ts index dfdebb9e1..b8a319d9b 100644 --- a/src-ui/src/app/data/ui-settings.ts +++ b/src-ui/src/app/data/ui-settings.ts @@ -70,6 +70,7 @@ export const SETTINGS_KEYS = { EMPTY_TRASH_DELAY: 'trash_delay', GMAIL_OAUTH_URL: 'gmail_oauth_url', OUTLOOK_OAUTH_URL: 'outlook_oauth_url', + EMAIL_ENABLED: 'email_enabled', } export const SETTINGS: UiSetting[] = [ @@ -263,4 +264,9 @@ export const SETTINGS: UiSetting[] = [ type: 'string', default: null, }, + { + key: SETTINGS_KEYS.EMAIL_ENABLED, + type: 'boolean', + default: false, + }, ] diff --git a/src/documents/tests/test_api_uisettings.py b/src/documents/tests/test_api_uisettings.py index 1743d331f..e3b9d4999 100644 --- a/src/documents/tests/test_api_uisettings.py +++ b/src/documents/tests/test_api_uisettings.py @@ -23,6 +23,7 @@ class TestApiUiSettings(DirectoriesMixin, APITestCase): def test_api_get_ui_settings(self): response = self.client.get(self.ENDPOINT, format="json") self.assertEqual(response.status_code, status.HTTP_200_OK) + self.maxDiff = None self.assertDictEqual( response.data["user"], { @@ -45,6 +46,7 @@ class TestApiUiSettings(DirectoriesMixin, APITestCase): "update_checking": { "backend_setting": "default", }, + "email_enabled": False, }, ) diff --git a/src/documents/views.py b/src/documents/views.py index 8be5f3d63..6d2c8cbd8 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1714,6 +1714,8 @@ class UiSettingsView(GenericAPIView): manager.get_outlook_authorization_url() ) + ui_settings["email_enabled"] = settings.EMAIL_ENABLED + user_resp = { "id": user.id, "username": user.username,