Refactor account type names

This commit is contained in:
shamoon 2024-10-05 20:56:03 -07:00
parent 5911e59a27
commit 843ad5bdd6
8 changed files with 13 additions and 13 deletions

View File

@ -41,8 +41,8 @@
<button class="btn btn-link p-0 text-start" type="button" (click)="editMailAccount(account)" [disabled]="!permissionsService.currentUserCan(PermissionAction.Change, PermissionType.MailAccount)"> <button class="btn btn-link p-0 text-start" type="button" (click)="editMailAccount(account)" [disabled]="!permissionsService.currentUserCan(PermissionAction.Change, PermissionType.MailAccount)">
{{account.name}}@switch (account.account_type) { {{account.name}}@switch (account.account_type) {
@case (MailAccountType.IMAP) {<i-bs name="envelope-at-fill" class="ms-2"></i-bs>} @case (MailAccountType.IMAP) {<i-bs name="envelope-at-fill" class="ms-2"></i-bs>}
@case (MailAccountType.Gmail) {<i-bs name="google" class="ms-2"></i-bs>} @case (MailAccountType.Gmail_OAuth) {<i-bs name="google" class="ms-2"></i-bs>}
@case (MailAccountType.Outlook) {<i-bs name="microsoft" class="ms-2"></i-bs>} @case (MailAccountType.Outlook_OAuth) {<i-bs name="microsoft" class="ms-2"></i-bs>}
} }
</button> </button>
</div> </div>

View File

@ -50,7 +50,7 @@ import { SettingsService } from 'src/app/services/settings.service'
const mailAccounts = [ const mailAccounts = [
{ id: 1, name: 'account1', account_type: MailAccountType.IMAP }, { id: 1, name: 'account1', account_type: MailAccountType.IMAP },
{ id: 2, name: 'account2', account_type: MailAccountType.IMAP }, { id: 2, name: 'account2', account_type: MailAccountType.IMAP },
{ id: 3, name: 'account3', accout_type: MailAccountType.Gmail }, { id: 3, name: 'account3', accout_type: MailAccountType.Gmail_OAuth },
] ]
const mailRules = [ const mailRules = [
{ id: 1, name: 'rule1', owner: 1, account: 1, enabled: true }, { id: 1, name: 'rule1', owner: 1, account: 1, enabled: true },

View File

@ -8,8 +8,8 @@ export enum IMAPSecurity {
export enum MailAccountType { export enum MailAccountType {
IMAP = 1, IMAP = 1,
Gmail = 2, Gmail_OAuth = 2,
Outlook = 3, Outlook_OAuth = 3,
} }
export interface MailAccount extends ObjectWithPermissions { export interface MailAccount extends ObjectWithPermissions {

View File

@ -432,7 +432,7 @@ def refresh_oauth_token(account: MailAccount) -> bool:
logger.error(f"Account {account}: No refresh token available.") logger.error(f"Account {account}: No refresh token available.")
return False return False
if account.account_type == MailAccount.MailAccountType.GMAIL: if account.account_type == MailAccount.MailAccountType.GMAIL_OAUTH:
url = "https://accounts.google.com/o/oauth2/token" url = "https://accounts.google.com/o/oauth2/token"
data = { data = {
"client_id": settings.GMAIL_OAUTH_CLIENT_ID, "client_id": settings.GMAIL_OAUTH_CLIENT_ID,
@ -440,7 +440,7 @@ def refresh_oauth_token(account: MailAccount) -> bool:
"refresh_token": account.refresh_token, "refresh_token": account.refresh_token,
"grant_type": "refresh_token", "grant_type": "refresh_token",
} }
elif account.account_type == MailAccount.MailAccountType.OUTLOOK: elif account.account_type == MailAccount.MailAccountType.OUTLOOK_OAUTH:
url = "https://login.microsoftonline.com/common/oauth2/v2.0/token" url = "https://login.microsoftonline.com/common/oauth2/v2.0/token"
data = { data = {
"client_id": settings.OUTLOOK_OAUTH_CLIENT_ID, "client_id": settings.OUTLOOK_OAUTH_CLIENT_ID,

View File

@ -24,7 +24,7 @@ class Migration(migrations.Migration):
model_name="mailaccount", model_name="mailaccount",
name="account_type", name="account_type",
field=models.PositiveIntegerField( field=models.PositiveIntegerField(
choices=[(1, "IMAP"), (2, "Gmail"), (3, "Outlook")], choices=[(1, "IMAP"), (2, "Gmail OAuth"), (3, "Outlook OAuth")],
default=1, default=1,
verbose_name="account type", verbose_name="account type",
), ),

View File

@ -17,8 +17,8 @@ class MailAccount(document_models.ModelWithOwner):
class MailAccountType(models.IntegerChoices): class MailAccountType(models.IntegerChoices):
IMAP = 1, _("IMAP") IMAP = 1, _("IMAP")
GMAIL = 2, _("Gmail") GMAIL_OAUTH = 2, _("Gmail OAuth")
OUTLOOK = 3, _("Outlook") OUTLOOK_OAUTH = 3, _("Outlook OAuth")
name = models.CharField(_("name"), max_length=256, unique=True) name = models.CharField(_("name"), max_length=256, unique=True)

View File

@ -109,7 +109,7 @@ class TestMailOAuth(
username="test_username", username="test_username",
imap_security=MailAccount.ImapSecurity.SSL, imap_security=MailAccount.ImapSecurity.SSL,
imap_port=993, imap_port=993,
account_type=MailAccount.MailAccountType.GMAIL, account_type=MailAccount.MailAccountType.GMAIL_OAUTH,
is_token=True, is_token=True,
refresh_token="test_refresh_token", refresh_token="test_refresh_token",
expiration=timezone.now() - timedelta(days=1), expiration=timezone.now() - timedelta(days=1),

View File

@ -112,7 +112,7 @@ class OauthCallbackView(GenericAPIView):
if scope is not None and "google" in scope: if scope is not None and "google" in scope:
# Google # Google
# Gmail setup guide: https://postmansmtp.com/how-to-configure-post-smtp-with-gmailgsuite-using-oauth/ # Gmail setup guide: https://postmansmtp.com/how-to-configure-post-smtp-with-gmailgsuite-using-oauth/
account_type = MailAccount.MailAccountType.GMAIL account_type = MailAccount.MailAccountType.GMAIL_OAUTH
imap_server = "imap.gmail.com" imap_server = "imap.gmail.com"
defaults = { defaults = {
"name": f"Gmail OAuth {timezone.now()}", "name": f"Gmail OAuth {timezone.now()}",
@ -129,7 +129,7 @@ class OauthCallbackView(GenericAPIView):
elif scope is None: elif scope is None:
# Outlook # Outlook
# Outlok setup guide: https://medium.com/@manojkumardhakad/python-read-and-send-outlook-mail-using-oauth2-token-and-graph-api-53de606ecfa1 # Outlok setup guide: https://medium.com/@manojkumardhakad/python-read-and-send-outlook-mail-using-oauth2-token-and-graph-api-53de606ecfa1
account_type = MailAccount.MailAccountType.OUTLOOK account_type = MailAccount.MailAccountType.OUTLOOK_OAUTH
imap_server = "outlook.office365.com" imap_server = "outlook.office365.com"
defaults = { defaults = {
"name": f"Outlook OAuth {timezone.now()}", "name": f"Outlook OAuth {timezone.now()}",