Skip to content

Commit d871b37

Browse files
committed
email: Simplify config_deleted context
1 parent b9b1513 commit d871b37

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::email::EmailMessage;
44
use crate::util::errors::{AppResult, bad_request, not_found};
55
use anyhow::Context;
66
use axum::extract::Path;
7-
use crates_io_database::models::OwnerKind;
87
use crates_io_database::models::trustpub::GitHubConfig;
8+
use crates_io_database::models::{Crate, OwnerKind};
99
use crates_io_database::schema::{crate_owners, crates, emails, trustpub_configs_github, users};
1010
use diesel::prelude::*;
1111
use diesel_async::RunQueryDsl;
@@ -39,12 +39,12 @@ pub async fn delete_trustpub_github_config(
3939
let auth_user = auth.user();
4040

4141
// Check that a trusted publishing config with the given ID exists,
42-
// and fetch the corresponding crate ID and name.
43-
let (config, crate_name) = trustpub_configs_github::table
42+
// and fetch the corresponding crate.
43+
let (config, krate) = trustpub_configs_github::table
4444
.inner_join(crates::table)
4545
.filter(trustpub_configs_github::id.eq(id))
46-
.select((GitHubConfig::as_select(), crates::name))
47-
.first::<(GitHubConfig, String)>(&mut conn)
46+
.select((GitHubConfig::as_select(), Crate::as_select()))
47+
.first::<(GitHubConfig, Crate)>(&mut conn)
4848
.await
4949
.optional()?
5050
.ok_or_else(not_found)?;
@@ -79,15 +79,7 @@ pub async fn delete_trustpub_github_config(
7979
.collect::<Vec<_>>();
8080

8181
for (recipient, email_address) in &recipients {
82-
let context = context! {
83-
recipient => recipient,
84-
user => auth_user.gh_login,
85-
krate => crate_name,
86-
repository_owner => config.repository_owner,
87-
repository_name => config.repository_name,
88-
workflow_filename => config.workflow_filename,
89-
environment => config.environment
90-
};
82+
let context = context! { recipient, auth_user, krate, config };
9183

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

src/email/templates/config_deleted/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 }} removed a "Trusted Publishing" configuration for GitHub Actions from a crate that you manage ("{{ krate }}").
6+
crates.io user {{ auth_user.gh_login }} removed a "Trusted Publishing" configuration for GitHub Actions from a crate that you manage ("{{ krate.name }}").
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: {{ config.repository_owner }}
11+
- Repository name: {{ config.repository_name }}
12+
- Workflow filename: {{ config.workflow_filename }}
13+
- Environment: {{ config.environment or "(not set)" }}
1414

1515
If you did not make this change and you think it was made maliciously, you can email [email protected] for assistance.
1616
{% endblock %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
crates.io: Trusted Publishing configuration removed from {{ krate }}
1+
crates.io: Trusted Publishing configuration removed from {{ krate.name }}

0 commit comments

Comments
 (0)