Some tweaks

This commit is contained in:
shamoon 2024-10-04 22:32:01 -07:00
parent 5d86c8d6ab
commit c3052dd8ca
5 changed files with 37 additions and 17 deletions

View File

@ -191,6 +191,7 @@ import {
folderFill, folderFill,
funnel, funnel,
gear, gear,
google,
grid, grid,
gripVertical, gripVertical,
hash, hash,
@ -201,6 +202,7 @@ import {
link, link,
listTask, listTask,
listUl, listUl,
microsoft,
nodePlus, nodePlus,
pencil, pencil,
people, people,
@ -295,6 +297,7 @@ const icons = {
folderFill, folderFill,
funnel, funnel,
gear, gear,
google,
grid, grid,
gripVertical, gripVertical,
hash, hash,
@ -305,6 +308,7 @@ const icons = {
link, link,
listTask, listTask,
listUl, listUl,
microsoft,
nodePlus, nodePlus,
pencil, pencil,
people, people,

View File

@ -13,8 +13,16 @@
<button type="button" class="btn btn-sm btn-outline-primary ms-4" (click)="editMailAccount()" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.MailAccount }"> <button type="button" class="btn btn-sm btn-outline-primary ms-4" (click)="editMailAccount()" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.MailAccount }">
<i-bs name="plus-circle"></i-bs>&nbsp;<ng-container i18n>Add Account</ng-container> <i-bs name="plus-circle"></i-bs>&nbsp;<ng-container i18n>Add Account</ng-container>
</button> </button>
<a class="btn btn-sm btn-outline-primary ms-2" [href]="gmailOAuthUrl" i18n>Connect with Gmail</a> @if (gmailOAuthUrl) {
<a class="btn btn-sm btn-outline-primary ms-2" [href]="outlookOAuthUrl" i18n>Connect with Outlook</a> <a class="btn btn-sm btn-outline-secondary ms-2" [href]="gmailOAuthUrl">
<i-bs name="google"></i-bs>&nbsp;<ng-container i18n>Connect Gmail Account</ng-container>
</a>
}
@if (outlookOAuthUrl) {
<a class="btn btn-sm btn-outline-secondary ms-2" [href]="outlookOAuthUrl">
<i-bs name="microsoft"></i-bs>&nbsp;<ng-container i18n>Connect Outlook Account</ng-container>
</a>
}
</h4> </h4>
<ul class="list-group"> <ul class="list-group">
<li class="list-group-item"> <li class="list-group-item">

View File

@ -38,7 +38,7 @@ export class MailComponent
oAuthAccoundId: number oAuthAccoundId: number
public get gmailOAuthUrl(): string { public get gmailOAuthUrl(): string {
return this.settingsService.get(SETTINGS_KEYS.GOOGLE_OAUTH_URL) return this.settingsService.get(SETTINGS_KEYS.GMAIL_OAUTH_URL)
} }
public get outlookOAuthUrl(): string { public get outlookOAuthUrl(): string {
@ -94,12 +94,20 @@ export class MailComponent
this.route.queryParamMap.subscribe((params) => { this.route.queryParamMap.subscribe((params) => {
if (params.get('oauth_success')) { if (params.get('oauth_success')) {
this.oAuthAccoundId = parseInt(params.get('account_id')) const success = params.get('oauth_success') === '1'
if (this.mailAccounts.length > 0) { if (success) {
this.editMailAccount( this.toastService.showInfo($localize`OAuth2 authentication success`)
this.mailAccounts.find( this.oAuthAccoundId = parseInt(params.get('account_id'))
(account) => account.id === this.oAuthAccoundId if (this.mailAccounts.length > 0) {
this.editMailAccount(
this.mailAccounts.find(
(account) => account.id === this.oAuthAccoundId
)
) )
}
} else {
this.toastService.showError(
$localize`OAuth2 authentication failed, see logs for details`
) )
} }
} }

View File

@ -64,7 +64,7 @@ export const SETTINGS_KEYS = {
SEARCH_DB_ONLY: 'general-settings:search:db-only', SEARCH_DB_ONLY: 'general-settings:search:db-only',
SEARCH_FULL_TYPE: 'general-settings:search:more-link', SEARCH_FULL_TYPE: 'general-settings:search:more-link',
EMPTY_TRASH_DELAY: 'trash_delay', EMPTY_TRASH_DELAY: 'trash_delay',
GOOGLE_OAUTH_URL: 'google_oauth_url', GMAIL_OAUTH_URL: 'gmail_oauth_url',
OUTLOOK_OAUTH_URL: 'outlook_oauth_url', OUTLOOK_OAUTH_URL: 'outlook_oauth_url',
} }
@ -245,7 +245,7 @@ export const SETTINGS: UiSetting[] = [
default: 30, default: 30,
}, },
{ {
key: SETTINGS_KEYS.GOOGLE_OAUTH_URL, key: SETTINGS_KEYS.GMAIL_OAUTH_URL,
type: 'string', type: 'string',
default: '', default: '',
}, },

View File

@ -1566,7 +1566,6 @@ class UiSettingsView(GenericAPIView):
return url return url
def generate_outlook_oauth_url(self) -> str: def generate_outlook_oauth_url(self) -> str:
# https://login.microsoftonline.com/common/oauth2/v2.0/authorize ?
token_request_uri = ( token_request_uri = (
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize" "https://login.microsoftonline.com/common/oauth2/v2.0/authorize"
) )
@ -1608,7 +1607,7 @@ class UiSettingsView(GenericAPIView):
ui_settings["auditlog_enabled"] = settings.AUDIT_LOG_ENABLED ui_settings["auditlog_enabled"] = settings.AUDIT_LOG_ENABLED
if settings.GMAIL_OAUTH_ENABLED: if settings.GMAIL_OAUTH_ENABLED:
ui_settings["google_oauth_url"] = self.generate_gmail_oauth_url() ui_settings["gmail_oauth_url"] = self.generate_gmail_oauth_url()
if settings.OUTLOOK_OAUTH_ENABLED: if settings.OUTLOOK_OAUTH_ENABLED:
ui_settings["outlook_oauth_url"] = self.generate_outlook_oauth_url() ui_settings["outlook_oauth_url"] = self.generate_outlook_oauth_url()
@ -2225,7 +2224,9 @@ class OauthCallbackView(GenericAPIView):
if "error" in data: if "error" in data:
logger.error(f"Error {response.status_code} getting access token: {data}") logger.error(f"Error {response.status_code} getting access token: {data}")
return HttpResponseBadRequest(data["error"]) return HttpResponseRedirect(
"http://localhost:4200/mail?oauth_success=0",
)
elif "access_token" in data: elif "access_token" in data:
access_token = data["access_token"] access_token = data["access_token"]
# if "refresh_token" in data: # if "refresh_token" in data:
@ -2237,7 +2238,6 @@ class OauthCallbackView(GenericAPIView):
imap_server=imap_server, imap_server=imap_server,
defaults=defaults, defaults=defaults,
) )
return HttpResponseRedirect(
return HttpResponseRedirect( f"http://localhost:4200/mail?oauth_success=1&account_id={account.pk}",
f"http://localhost:4200/mail?oauth_success=1&account_id={account.pk}", )
)