Fix: disable email workflow type if email not enabled

This commit is contained in:
shamoon
2024-12-24 09:31:59 -08:00
parent 5007855904
commit 8291ec17d4
7 changed files with 46 additions and 20 deletions

View 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()
}

View 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', () => {

View 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 {

View 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,
},
]