From 2b1087d8376d472b61d3b9e495e4acf4de5b99de Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 5 Oct 2024 11:52:04 -0700 Subject: [PATCH] Actually leave it to refresh on test, just make sure we dont overwrite --- ...mail-account-edit-dialog.component.spec.ts | 3 ++- .../rest/mail-account.service.spec.ts | 19 ++++--------------- .../app/services/rest/mail-account.service.ts | 10 +++------- .../services/rest/mail-rule.service.spec.ts | 15 --------------- .../app/services/rest/mail-rule.service.ts | 6 ------ src/paperless_mail/views.py | 6 ++++-- 6 files changed, 13 insertions(+), 46 deletions(-) diff --git a/src-ui/src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.spec.ts b/src-ui/src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.spec.ts index 83262464b..408667f62 100644 --- a/src-ui/src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.spec.ts @@ -11,7 +11,7 @@ import { import { FormsModule, ReactiveFormsModule } from '@angular/forms' import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap' import { NgSelectModule } from '@ng-select/ng-select' -import { IMAPSecurity } from 'src/app/data/mail-account' +import { IMAPSecurity, MailAccountType } from 'src/app/data/mail-account' import { IfOwnerDirective } from 'src/app/directives/if-owner.directive' import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive' import { SettingsService } from 'src/app/services/settings.service' @@ -82,6 +82,7 @@ describe('MailAccountEditDialogComponent', () => { imap_port: 443, imap_security: IMAPSecurity.SSL, is_token: false, + account_type: MailAccountType.IMAP, } // success diff --git a/src-ui/src/app/services/rest/mail-account.service.spec.ts b/src-ui/src/app/services/rest/mail-account.service.spec.ts index 64974d834..c9d1da7d1 100644 --- a/src-ui/src/app/services/rest/mail-account.service.spec.ts +++ b/src-ui/src/app/services/rest/mail-account.service.spec.ts @@ -4,7 +4,7 @@ import { TestBed } from '@angular/core/testing' import { environment } from 'src/environments/environment' import { commonAbstractPaperlessServiceTests } from './abstract-paperless-service.spec' import { MailAccountService } from './mail-account.service' -import { IMAPSecurity } from 'src/app/data/mail-account' +import { IMAPSecurity, MailAccountType } from 'src/app/data/mail-account' let httpTestingController: HttpTestingController let service: MailAccountService @@ -20,6 +20,7 @@ const mail_accounts = [ username: 'user', password: 'pass', is_token: false, + account_type: MailAccountType.IMAP, }, { name: 'Mail Account 2', @@ -30,6 +31,7 @@ const mail_accounts = [ username: 'user', password: 'pass', is_token: false, + account_type: MailAccountType.IMAP, }, { name: 'Mail Account 3', @@ -40,6 +42,7 @@ const mail_accounts = [ username: 'user', password: 'pass', is_token: false, + account_type: MailAccountType.IMAP, }, ] @@ -55,20 +58,6 @@ describe(`Additional service tests for MailAccountService`, () => { expect(req.request.method).toEqual('POST') }) - it('should support patchMany', () => { - subscription = service.patchMany(mail_accounts).subscribe() - mail_accounts.forEach((mail_account) => { - const req = httpTestingController.expectOne( - `${environment.apiBaseUrl}${endpoint}/${mail_account.id}/` - ) - expect(req.request.method).toEqual('PATCH') - req.flush(mail_account) - }) - httpTestingController.expectOne( - `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000` - ) - }) - it('should support reload', () => { service['reload']() const req = httpTestingController.expectOne( diff --git a/src-ui/src/app/services/rest/mail-account.service.ts b/src-ui/src/app/services/rest/mail-account.service.ts index fb0b0ed23..7e06cfaee 100644 --- a/src-ui/src/app/services/rest/mail-account.service.ts +++ b/src-ui/src/app/services/rest/mail-account.service.ts @@ -1,6 +1,5 @@ import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' -import { combineLatest, Observable } from 'rxjs' import { tap } from 'rxjs/operators' import { MailAccount } from 'src/app/data/mail-account' import { AbstractPaperlessService } from './abstract-paperless-service' @@ -34,15 +33,12 @@ export class MailAccountService extends AbstractPaperlessService { } update(o: MailAccount) { + // Remove refresh_token and expiration from the object before updating + delete o.refresh_token + delete o.expiration return super.update(o).pipe(tap(() => this.reload())) } - patchMany(objects: MailAccount[]): Observable { - return combineLatest(objects.map((o) => super.patch(o))).pipe( - tap(() => this.reload()) - ) - } - delete(o: MailAccount) { return super.delete(o).pipe(tap(() => this.reload())) } diff --git a/src-ui/src/app/services/rest/mail-rule.service.spec.ts b/src-ui/src/app/services/rest/mail-rule.service.spec.ts index 87e21172c..b0e1d7de3 100644 --- a/src-ui/src/app/services/rest/mail-rule.service.spec.ts +++ b/src-ui/src/app/services/rest/mail-rule.service.spec.ts @@ -76,21 +76,6 @@ const mail_rules = [ commonAbstractPaperlessServiceTests(endpoint, MailRuleService) describe(`Additional service tests for MailRuleService`, () => { - it('should support patchMany', () => { - subscription = service.patchMany(mail_rules).subscribe() - mail_rules.forEach((mail_rule) => { - const req = httpTestingController.expectOne( - `${environment.apiBaseUrl}${endpoint}/${mail_rule.id}/` - ) - expect(req.request.method).toEqual('PATCH') - req.flush(mail_rule) - }) - const reloadReq = httpTestingController.expectOne( - `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000` - ) - reloadReq.flush({ results: mail_rules }) - }) - it('should support reload', () => { service['reload']() const req = httpTestingController.expectOne( diff --git a/src-ui/src/app/services/rest/mail-rule.service.ts b/src-ui/src/app/services/rest/mail-rule.service.ts index caa73ed2c..b5a0c0ec1 100644 --- a/src-ui/src/app/services/rest/mail-rule.service.ts +++ b/src-ui/src/app/services/rest/mail-rule.service.ts @@ -37,12 +37,6 @@ export class MailRuleService extends AbstractPaperlessService { return super.update(o).pipe(tap(() => this.reload())) } - patchMany(objects: MailRule[]): Observable { - return combineLatest(objects.map((o) => super.patch(o))).pipe( - tap(() => this.reload()) - ) - } - delete(o: MailRule) { return super.delete(o).pipe(tap(() => this.reload())) } diff --git a/src/paperless_mail/views.py b/src/paperless_mail/views.py index 2c3d9dd77..a641aa360 100644 --- a/src/paperless_mail/views.py +++ b/src/paperless_mail/views.py @@ -80,8 +80,10 @@ class MailAccountTestView(GenericAPIView): and account.expiration is not None and account.expiration < timezone.now() ): - if refresh_oauth_token(account): - account.refresh_from_db() + if refresh_oauth_token(existing_account): + # User is not changing password and token needs to be refreshed + existing_account.refresh_from_db() + account.password = existing_account.password else: raise MailError("Unable to refresh oauth token")