Skip to content

Commit 296487b

Browse files
committed
email: Simplify config_created context
1 parent c7572a0 commit 296487b

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

crates/crates_io_database/src/models/krate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use diesel::sql_types::{Bool, Integer, Text};
1212
use diesel_async::scoped_futures::ScopedFutureExt;
1313
use diesel_async::{AsyncConnection, AsyncPgConnection, RunQueryDsl};
1414
use secrecy::SecretString;
15+
use serde::Serialize;
1516
use thiserror::Error;
1617
use tracing::instrument;
1718

@@ -35,7 +36,9 @@ pub struct CrateName {
3536
pub name: String,
3637
}
3738

38-
#[derive(Debug, Clone, Queryable, Identifiable, AsChangeset, QueryableByName, Selectable)]
39+
#[derive(
40+
Debug, Clone, Queryable, Identifiable, AsChangeset, QueryableByName, Selectable, Serialize,
41+
)]
3942
#[diesel(table_name = crates, check_for_backend(diesel::pg::Pg))]
4043
pub struct Crate {
4144
pub id: i32,

crates/crates_io_database/src/models/trustpub/github_config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use crate::schema::trustpub_configs_github;
22
use chrono::{DateTime, Utc};
33
use diesel::prelude::*;
44
use diesel_async::{AsyncPgConnection, RunQueryDsl};
5+
use serde::Serialize;
56

6-
#[derive(Debug, Identifiable, Queryable, Selectable)]
7+
#[derive(Debug, Identifiable, Queryable, Selectable, Serialize)]
78
#[diesel(table_name = trustpub_configs_github, check_for_backend(diesel::pg::Pg))]
89
pub struct GitHubConfig {
910
pub id: i32,

crates/crates_io_database/src/models/user.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ use diesel::sql_types::Integer;
66
use diesel::upsert::excluded;
77
use diesel_async::{AsyncPgConnection, RunQueryDsl};
88
use secrecy::SecretString;
9+
use serde::Serialize;
910

1011
use crate::models::{Crate, CrateOwner, Email, Owner, OwnerKind};
1112
use crate::schema::{crate_owners, emails, users};
1213
use crates_io_diesel_helpers::lower;
1314

1415
/// The model representing a row in the `users` database table.
15-
#[derive(Clone, Debug, Queryable, Identifiable, Selectable)]
16+
#[derive(Clone, Debug, Queryable, Identifiable, Selectable, Serialize)]
1617
pub struct User {
1718
pub id: i32,
1819
#[diesel(deserialize_as = String)]
20+
#[serde(skip)]
1921
pub gh_access_token: SecretString,
2022
pub gh_login: String,
2123
pub name: Option<String>,

src/controllers/trustpub/github_configs/create/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,7 @@ pub async fn create_trustpub_github_config(
108108
.collect::<Vec<_>>();
109109

110110
for (recipient, email_address) in &recipients {
111-
let context = context! {
112-
recipient => recipient,
113-
user => auth_user.gh_login,
114-
krate => krate.name,
115-
repository_owner => saved_config.repository_owner,
116-
repository_name => saved_config.repository_name,
117-
workflow_filename => saved_config.workflow_filename,
118-
environment => saved_config.environment
119-
};
111+
let context = context! { recipient, auth_user, krate, saved_config };
120112

121113
if let Err(err) = send_notification_email(&state, email_address, context).await {
122114
warn!("Failed to send trusted publishing notification to {email_address}: {err}");

src/email/templates/config_created/body.txt.j2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
{% block content %}
44
Hello {{ recipient }}!
55

6-
crates.io user {{ user }} added a new "Trusted Publishing" configuration for GitHub Actions to a crate that you manage ("{{ krate }}"). Trusted publishers act as trusted users and can publish new versions of the crate automatically.
6+
crates.io user {{ auth_user.gh_login }} added a new "Trusted Publishing" configuration for GitHub Actions to a crate that you manage ("{{ krate.name }}"). Trusted publishers act as trusted users and can publish new versions of the crate automatically.
77

88
Trusted Publishing configuration:
99

10-
- Repository owner: {{ repository_owner }}
11-
- Repository name: {{ repository_name }}
12-
- Workflow filename: {{ workflow_filename }}
13-
- Environment: {{ environment or "(not set)" }}
10+
- Repository owner: {{ saved_config.repository_owner }}
11+
- Repository name: {{ saved_config.repository_name }}
12+
- Workflow filename: {{ saved_config.workflow_filename }}
13+
- Environment: {{ saved_config.environment or "(not set)" }}
1414

1515
If you did not make this change and you think it was made maliciously, you can remove the configuration from the crate via the "Settings" tab on the crate's page.
1616

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
crates.io: Trusted Publishing configuration added to {{ krate }}
1+
crates.io: Trusted Publishing configuration added to {{ krate.name }}

0 commit comments

Comments
 (0)