Refactor account type names
This commit is contained in:
parent
5911e59a27
commit
843ad5bdd6
@ -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)">
|
||||
{{account.name}}@switch (account.account_type) {
|
||||
@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.Outlook) {<i-bs name="microsoft" class="ms-2"></i-bs>}
|
||||
@case (MailAccountType.Gmail_OAuth) {<i-bs name="google" class="ms-2"></i-bs>}
|
||||
@case (MailAccountType.Outlook_OAuth) {<i-bs name="microsoft" class="ms-2"></i-bs>}
|
||||
}
|
||||
</button>
|
||||
</div>
|
||||
|
@ -50,7 +50,7 @@ import { SettingsService } from 'src/app/services/settings.service'
|
||||
const mailAccounts = [
|
||||
{ id: 1, name: 'account1', 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 = [
|
||||
{ id: 1, name: 'rule1', owner: 1, account: 1, enabled: true },
|
||||
|
@ -8,8 +8,8 @@ export enum IMAPSecurity {
|
||||
|
||||
export enum MailAccountType {
|
||||
IMAP = 1,
|
||||
Gmail = 2,
|
||||
Outlook = 3,
|
||||
Gmail_OAuth = 2,
|
||||
Outlook_OAuth = 3,
|
||||
}
|
||||
|
||||
export interface MailAccount extends ObjectWithPermissions {
|
||||
|
@ -432,7 +432,7 @@ def refresh_oauth_token(account: MailAccount) -> bool:
|
||||
logger.error(f"Account {account}: No refresh token available.")
|
||||
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"
|
||||
data = {
|
||||
"client_id": settings.GMAIL_OAUTH_CLIENT_ID,
|
||||
@ -440,7 +440,7 @@ def refresh_oauth_token(account: MailAccount) -> bool:
|
||||
"refresh_token": account.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"
|
||||
data = {
|
||||
"client_id": settings.OUTLOOK_OAUTH_CLIENT_ID,
|
||||
|
@ -24,7 +24,7 @@ class Migration(migrations.Migration):
|
||||
model_name="mailaccount",
|
||||
name="account_type",
|
||||
field=models.PositiveIntegerField(
|
||||
choices=[(1, "IMAP"), (2, "Gmail"), (3, "Outlook")],
|
||||
choices=[(1, "IMAP"), (2, "Gmail OAuth"), (3, "Outlook OAuth")],
|
||||
default=1,
|
||||
verbose_name="account type",
|
||||
),
|
||||
|
@ -17,8 +17,8 @@ class MailAccount(document_models.ModelWithOwner):
|
||||
|
||||
class MailAccountType(models.IntegerChoices):
|
||||
IMAP = 1, _("IMAP")
|
||||
GMAIL = 2, _("Gmail")
|
||||
OUTLOOK = 3, _("Outlook")
|
||||
GMAIL_OAUTH = 2, _("Gmail OAuth")
|
||||
OUTLOOK_OAUTH = 3, _("Outlook OAuth")
|
||||
|
||||
name = models.CharField(_("name"), max_length=256, unique=True)
|
||||
|
||||
|
@ -109,7 +109,7 @@ class TestMailOAuth(
|
||||
username="test_username",
|
||||
imap_security=MailAccount.ImapSecurity.SSL,
|
||||
imap_port=993,
|
||||
account_type=MailAccount.MailAccountType.GMAIL,
|
||||
account_type=MailAccount.MailAccountType.GMAIL_OAUTH,
|
||||
is_token=True,
|
||||
refresh_token="test_refresh_token",
|
||||
expiration=timezone.now() - timedelta(days=1),
|
||||
|
@ -112,7 +112,7 @@ class OauthCallbackView(GenericAPIView):
|
||||
if scope is not None and "google" in scope:
|
||||
# Google
|
||||
# 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"
|
||||
defaults = {
|
||||
"name": f"Gmail OAuth {timezone.now()}",
|
||||
@ -129,7 +129,7 @@ class OauthCallbackView(GenericAPIView):
|
||||
elif scope is None:
|
||||
# Outlook
|
||||
# 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"
|
||||
defaults = {
|
||||
"name": f"Outlook OAuth {timezone.now()}",
|
||||
|
Loading…
x
Reference in New Issue
Block a user