mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-09-16 21:55:37 -05:00
Feature: OAuth2 Gmail and Outlook email support (#7866)
This commit is contained in:
@@ -2,7 +2,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core'
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { Subject, first, takeUntil } from 'rxjs'
|
||||
import { ObjectWithPermissions } from 'src/app/data/object-with-permissions'
|
||||
import { MailAccount } from 'src/app/data/mail-account'
|
||||
import { MailAccount, MailAccountType } from 'src/app/data/mail-account'
|
||||
import { MailRule } from 'src/app/data/mail-rule'
|
||||
import {
|
||||
PermissionsService,
|
||||
@@ -18,6 +18,9 @@ import { MailAccountEditDialogComponent } from '../../common/edit-dialog/mail-ac
|
||||
import { MailRuleEditDialogComponent } from '../../common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component'
|
||||
import { PermissionsDialogComponent } from '../../common/permissions-dialog/permissions-dialog.component'
|
||||
import { ComponentWithPermissions } from '../../with-permissions/with-permissions.component'
|
||||
import { SettingsService } from 'src/app/services/settings.service'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
import { ActivatedRoute } from '@angular/router'
|
||||
|
||||
@Component({
|
||||
selector: 'pngx-mail',
|
||||
@@ -28,17 +31,30 @@ export class MailComponent
|
||||
extends ComponentWithPermissions
|
||||
implements OnInit, OnDestroy
|
||||
{
|
||||
public MailAccountType = MailAccountType
|
||||
|
||||
mailAccounts: MailAccount[] = []
|
||||
mailRules: MailRule[] = []
|
||||
|
||||
unsubscribeNotifier: Subject<any> = new Subject()
|
||||
oAuthAccountId: number
|
||||
|
||||
public get gmailOAuthUrl(): string {
|
||||
return this.settingsService.get(SETTINGS_KEYS.GMAIL_OAUTH_URL)
|
||||
}
|
||||
|
||||
public get outlookOAuthUrl(): string {
|
||||
return this.settingsService.get(SETTINGS_KEYS.OUTLOOK_OAUTH_URL)
|
||||
}
|
||||
|
||||
constructor(
|
||||
public mailAccountService: MailAccountService,
|
||||
public mailRuleService: MailRuleService,
|
||||
private toastService: ToastService,
|
||||
private modalService: NgbModal,
|
||||
public permissionsService: PermissionsService
|
||||
public permissionsService: PermissionsService,
|
||||
private settingsService: SettingsService,
|
||||
private route: ActivatedRoute
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@@ -50,6 +66,15 @@ export class MailComponent
|
||||
.subscribe({
|
||||
next: (r) => {
|
||||
this.mailAccounts = r.results
|
||||
console.log(this.mailAccounts, this.oAuthAccountId)
|
||||
|
||||
if (this.oAuthAccountId) {
|
||||
this.editMailAccount(
|
||||
this.mailAccounts.find(
|
||||
(account) => account.id === this.oAuthAccountId
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
error: (e) => {
|
||||
this.toastService.showError(
|
||||
@@ -70,6 +95,27 @@ export class MailComponent
|
||||
this.toastService.showError($localize`Error retrieving mail rules`, e)
|
||||
},
|
||||
})
|
||||
|
||||
this.route.queryParamMap.subscribe((params) => {
|
||||
if (params.get('oauth_success')) {
|
||||
const success = params.get('oauth_success') === '1'
|
||||
if (success) {
|
||||
this.toastService.showInfo($localize`OAuth2 authentication success`)
|
||||
this.oAuthAccountId = parseInt(params.get('account_id'))
|
||||
if (this.mailAccounts.length > 0) {
|
||||
this.editMailAccount(
|
||||
this.mailAccounts.find(
|
||||
(account) => account.id === this.oAuthAccountId
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
this.toastService.showError(
|
||||
$localize`OAuth2 authentication failed, see logs for details`
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
|
Reference in New Issue
Block a user