Skip to content

Commit

Permalink
feat(ui): add mail delivery settings (#1403)
Browse files Browse the repository at this point in the history
* feat(ui): mail form

* feat(ui): init mail delivery settings

* [autofix.ci] apply automated fixes

* fix(ui): intrgrations layout

* fix(ui): cmts

* [autofix.ci] apply automated fixes

* fix(ui): mailFormValues

* update schema.graphql

* connect backend

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Meng Zhang <[email protected]>
  • Loading branch information
3 people authored Feb 10, 2024
1 parent 01e728b commit 4c7ca15
Show file tree
Hide file tree
Showing 42 changed files with 707 additions and 104 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ee/tabby-db/migrations/0013_add-smtp-port.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE email_setting DROP COLUMN smtp_port;
1 change: 1 addition & 0 deletions ee/tabby-db/migrations/0013_add-smtp-port.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE email_setting ADD COLUMN smtp_port INTEGER NOT NULL DEFAULT 25;
Binary file modified ee/tabby-db/schema.sqlite
Binary file not shown.
14 changes: 10 additions & 4 deletions ee/tabby-db/src/email_setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct EmailSettingDAO {
pub smtp_username: String,
pub smtp_password: String,
pub smtp_server: String,
pub smtp_port: i64,
pub from_address: String,
pub encryption: String,
pub auth_method: String,
Expand All @@ -19,7 +20,7 @@ impl DbConn {
pub async fn read_email_setting(&self) -> Result<Option<EmailSettingDAO>> {
let setting = query_as!(
EmailSettingDAO,
"SELECT smtp_username, smtp_password, smtp_server, from_address, encryption, auth_method FROM email_setting WHERE id=?",
"SELECT smtp_username, smtp_password, smtp_server, smtp_port, from_address, encryption, auth_method FROM email_setting WHERE id=?",
EMAIL_CREDENTIAL_ROW_ID
)
.fetch_optional(&self.pool)
Expand All @@ -32,6 +33,7 @@ impl DbConn {
smtp_username: String,
smtp_password: Option<String>,
smtp_server: String,
smtp_port: i32,
from_address: String,
encryption: String,
auth_method: String,
Expand All @@ -47,15 +49,17 @@ impl DbConn {
.await
.map_err(|_| anyhow!("smtp_password is required to enable email sending"))?,
};
query!("INSERT INTO email_setting (id, smtp_username, smtp_password, smtp_server, from_address, encryption, auth_method) VALUES ($1, $2, $3, $4, $5, $6, $7)
ON CONFLICT(id) DO UPDATE SET smtp_username = $2, smtp_password = $3, smtp_server = $4, from_address = $5, encryption = $6, auth_method = $7",
query!("INSERT INTO email_setting (id, smtp_username, smtp_password, smtp_server, from_address, encryption, auth_method, smtp_port) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
ON CONFLICT(id) DO UPDATE SET smtp_username = $2, smtp_password = $3, smtp_server = $4, from_address = $5, encryption = $6, auth_method = $7, smtp_port = $8",
EMAIL_CREDENTIAL_ROW_ID,
smtp_username,
smtp_password,
smtp_server,
from_address,
encryption,
auth_method).execute(&mut *transaction).await?;
auth_method,
smtp_port,
).execute(&mut *transaction).await?;
transaction.commit().await?;
Ok(())
}
Expand Down Expand Up @@ -87,6 +91,7 @@ mod tests {
"user".into(),
Some("pass".into()),
"server".into(),
25,
"user".into(),
"STARTTLS".into(),
"".into(),
Expand All @@ -105,6 +110,7 @@ mod tests {
"user2".into(),
None,
"server2".into(),
25,
"user2".into(),
"STARTTLS".into(),
"".into(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function IntegrationsLayout({
children
}: {
children: React.ReactNode
}) {
return <div className="p-6">{children}</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { SubHeader } from '@/components/sub-header'

export const MailDeliveryHeader = ({ className }: { className?: string }) => {
return (
<SubHeader className={className}>
Configuring SMTP information will enable users to receive database reports
via email, such as slow query weekly reports.
</SubHeader>
)
}
Loading

0 comments on commit 4c7ca15

Please sign in to comment.