]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: disable email workflow type if email not enabled
authorshamoon <4887959+shamoon@users.noreply.github.com>
Tue, 24 Dec 2024 17:31:59 +0000 (09:31 -0800)
committershamoon <4887959+shamoon@users.noreply.github.com>
Tue, 24 Dec 2024 17:31:59 +0000 (09:31 -0800)
src-ui/messages.xlf
src-ui/src/app/components/common/edit-dialog/edit-dialog.component.ts
src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.spec.ts
src-ui/src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts
src-ui/src/app/data/ui-settings.ts
src/documents/tests/test_api_uisettings.py
src/documents/views.py

index 102d50ce3b0e9fb101048fbf0108ca5296ca8a2f..90f9287b763ec39e6d853d769e0acf1ed9168611 100644 (file)
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">59</context>
+          <context context-type="linenumber">60</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">55</context>
+          <context context-type="linenumber">56</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/document-list/document-list.component.html</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">101</context>
+          <context context-type="linenumber">102</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>
         <source>Consume Folder</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">40</context>
+          <context context-type="linenumber">41</context>
         </context-group>
       </trans-unit>
       <trans-unit id="526966086395145275" datatype="html">
         <source>API Upload</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">44</context>
+          <context context-type="linenumber">45</context>
         </context-group>
       </trans-unit>
       <trans-unit id="7502272564743467653" datatype="html">
         <source>Mail Fetch</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">48</context>
+          <context context-type="linenumber">49</context>
         </context-group>
       </trans-unit>
       <trans-unit id="3553216189604488439" datatype="html">
         <source>Modified</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">63</context>
+          <context context-type="linenumber">64</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/data/document.ts</context>
         <source>Custom Field</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">67</context>
+          <context context-type="linenumber">68</context>
         </context-group>
       </trans-unit>
       <trans-unit id="8696908693776094667" datatype="html">
         <source>Consumption Started</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">74</context>
+          <context context-type="linenumber">75</context>
         </context-group>
       </trans-unit>
       <trans-unit id="7858311467093621703" datatype="html">
         <source>Document Added</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">78</context>
+          <context context-type="linenumber">79</context>
         </context-group>
       </trans-unit>
       <trans-unit id="7955486237346046731" datatype="html">
         <source>Document Updated</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">82</context>
+          <context context-type="linenumber">83</context>
         </context-group>
       </trans-unit>
       <trans-unit id="9172233176401579786" datatype="html">
         <source>Scheduled</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">86</context>
+          <context context-type="linenumber">87</context>
         </context-group>
       </trans-unit>
       <trans-unit id="5502398334173581061" datatype="html">
         <source>Assignment</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">93</context>
+          <context context-type="linenumber">94</context>
         </context-group>
       </trans-unit>
       <trans-unit id="6234812824772766804" datatype="html">
         <source>Removal</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">97</context>
+          <context context-type="linenumber">98</context>
         </context-group>
       </trans-unit>
       <trans-unit id="4206419737792796794" datatype="html">
         <source>Webhook</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">105</context>
+          <context context-type="linenumber">106</context>
         </context-group>
       </trans-unit>
       <trans-unit id="3138206142174978019" datatype="html">
         <source>Create new workflow</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">180</context>
+          <context context-type="linenumber">183</context>
         </context-group>
       </trans-unit>
       <trans-unit id="5996779210524133604" datatype="html">
         <source>Edit workflow</source>
         <context-group purpose="location">
           <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.ts</context>
-          <context context-type="linenumber">184</context>
+          <context context-type="linenumber">187</context>
         </context-group>
       </trans-unit>
       <trans-unit id="6381578200008167206" datatype="html">
index 3bcb6e953689f9431fa6e9bbe0016ea871ebe88d..afbc6c73f793a13675c8bdf474d9366aa1b742ce 100644 (file)
@@ -33,7 +33,7 @@ export abstract class EditDialogComponent<
     protected service: AbstractPaperlessService<T>,
     private activeModal: NgbActiveModal,
     private userService: UserService,
-    private settingsService: SettingsService
+    protected settingsService: SettingsService
   ) {
     super()
   }
index 4486c79a5c87ca23077a1d283dc3396558f2ff5b..b790ab73661eba3fc68d3553a5d784f5da5d0570 100644 (file)
@@ -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', () => {
index 2face94a3e11d562e873622911356bc8e589379d..8aeab88c9b067705267b50e8bf78a8a5f761e59b 100644 (file)
@@ -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 {
index dfdebb9e10aacb49dfbe5b2ac6ad7edf674b6299..b8a319d9b72f8968a56a754223c4aa610d739d9a 100644 (file)
@@ -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,
+  },
 ]
index 1743d331f2ac74600c7b361f3142813f20db8fbf..e3b9d4999b3bef3b899dd875fc6f7f3e84a79b6c 100644 (file)
@@ -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,
             },
         )
 
index 8be5f3d63294d773aae34caa785a7b6e7297587b..6d2c8cbd8a9b943d390c440455f4136649857433 100644 (file)
@@ -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,