mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Enhancement: process mail button (#8466)
This commit is contained in:
@@ -65,19 +65,27 @@
|
||||
<button (click)="editMailAccount(account)" *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.MailAccount }" ngbDropdownItem i18n>Edit</button>
|
||||
<button (click)="editPermissions(account)" *pngxIfOwner="account" ngbDropdownItem i18n>Permissions</button>
|
||||
<button (click)="deleteMailAccount(account)" *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailAccount }" ngbDropdownItem i18n>Delete</button>
|
||||
<button (click)="processAccount(account)" *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.MailAccount }" ngbDropdownItem i18n>Process Mail</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group d-none d-sm-block">
|
||||
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.MailAccount }" [disabled]="!userCanEdit(account)" class="btn btn-sm btn-outline-secondary" type="button" (click)="editMailAccount(account)">
|
||||
<i-bs width="1em" height="1em" name="pencil"></i-bs> <ng-container i18n>Edit</ng-container>
|
||||
</button>
|
||||
<button *pngxIfOwner="account" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(account)">
|
||||
<i-bs width="1em" height="1em" name="person-lock"></i-bs> <ng-container i18n>Permissions</ng-container>
|
||||
</button>
|
||||
<button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailAccount }" [disabled]="!userIsOwner(account)" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteMailAccount(account)">
|
||||
<i-bs width="1em" height="1em" name="trash"></i-bs> <ng-container i18n>Delete</ng-container>
|
||||
</button>
|
||||
<div class="btn-toolbar d-none d-sm-flex gap-2" role="toolbar">
|
||||
<div class="btn-group">
|
||||
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.MailAccount }" [disabled]="!userCanEdit(account)" class="btn btn-sm btn-outline-secondary" type="button" (click)="editMailAccount(account)">
|
||||
<i-bs width="1em" height="1em" name="pencil"></i-bs> <ng-container i18n>Edit</ng-container>
|
||||
</button>
|
||||
<button *pngxIfOwner="account" class="btn btn-sm btn-outline-secondary" type="button" (click)="editPermissions(account)">
|
||||
<i-bs width="1em" height="1em" name="person-lock"></i-bs> <ng-container i18n>Permissions</ng-container>
|
||||
</button>
|
||||
<button *pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.MailAccount }" [disabled]="!userIsOwner(account)" class="btn btn-sm btn-outline-danger" type="button" (click)="deleteMailAccount(account)">
|
||||
<i-bs width="1em" height="1em" name="trash"></i-bs> <ng-container i18n>Delete</ng-container>
|
||||
</button>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.MailAccount }" class="btn btn-sm btn-outline-secondary" type="button" (click)="processAccount(account)">
|
||||
<i-bs width="1em" height="1em" name="arrow-clockwise"></i-bs> <ng-container i18n>Process Mail</ng-container>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -219,6 +219,23 @@ describe('MailComponent', () => {
|
||||
expect(toastInfoSpy).toHaveBeenCalledWith('Deleted mail account')
|
||||
})
|
||||
|
||||
it('should support process mail account, show error if needed', () => {
|
||||
completeSetup()
|
||||
const processSpy = jest.spyOn(mailAccountService, 'processAccount')
|
||||
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||
const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
|
||||
component.processAccount(mailAccounts[0] as MailAccount)
|
||||
expect(processSpy).toHaveBeenCalled()
|
||||
processSpy.mockReturnValueOnce(
|
||||
throwError(() => new Error('error processing mail account'))
|
||||
)
|
||||
component.processAccount(mailAccounts[0] as MailAccount)
|
||||
expect(toastErrorSpy).toHaveBeenCalled()
|
||||
processSpy.mockReturnValueOnce(of(true))
|
||||
component.processAccount(mailAccounts[0] as MailAccount)
|
||||
expect(toastInfoSpy).toHaveBeenCalledWith('Processing mail account')
|
||||
})
|
||||
|
||||
it('should support edit / create mail rule, show error if needed', () => {
|
||||
completeSetup()
|
||||
let modal: NgbModalRef
|
||||
|
@@ -202,6 +202,17 @@ export class MailComponent
|
||||
})
|
||||
}
|
||||
|
||||
processAccount(account: MailAccount) {
|
||||
this.mailAccountService.processAccount(account).subscribe({
|
||||
next: () => {
|
||||
this.toastService.showInfo($localize`Processing mail account`)
|
||||
},
|
||||
error: (e) => {
|
||||
this.toastService.showError($localize`Error processing mail account`, e)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
editMailRule(rule: MailRule = null, forceCreate = false) {
|
||||
const modal = this.modalService.open(MailRuleEditDialogComponent, {
|
||||
backdrop: 'static',
|
||||
|
@@ -68,6 +68,14 @@ describe(`Additional service tests for MailAccountService`, () => {
|
||||
expect(service.allAccounts).toEqual(mail_accounts)
|
||||
})
|
||||
|
||||
it('should support processAccount', () => {
|
||||
subscription = service.processAccount(mail_accounts[0]).subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}${endpoint}/${mail_accounts[0].id}/process/`
|
||||
)
|
||||
expect(req.request.method).toEqual('POST')
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
// Dont need to setup again
|
||||
|
||||
|
@@ -47,4 +47,8 @@ export class MailAccountService extends AbstractPaperlessService<MailAccount> {
|
||||
delete account['set_permissions']
|
||||
return this.http.post(this.getResourceUrl() + 'test/', account)
|
||||
}
|
||||
|
||||
processAccount(account: MailAccount) {
|
||||
return this.http.post(this.getResourceUrl(account.id, 'process'), {})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user