Skip to content

Commit 84aed12

Browse files
committed
controllers/site_metadata: Add banner_message field
1 parent 6b9ed9f commit 84aed12

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/controllers/site_metadata.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub struct MetadataResponse<'a> {
1515

1616
/// Whether the crates.io service is in read-only mode.
1717
pub read_only: bool,
18+
19+
/// Optional banner message to display on all pages.
20+
pub banner_message: Option<&'a str>,
1821
}
1922

2023
/// Get crates.io metadata.
@@ -37,6 +40,7 @@ pub async fn get_site_metadata(state: AppState) -> impl IntoResponse {
3740
deployed_sha,
3841
commit: deployed_sha,
3942
read_only,
43+
banner_message: state.config.banner_message.as_deref(),
4044
})
4145
.into_response()
4246
}

src/tests/routes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ pub mod me;
1919
pub mod metrics;
2020
mod private;
2121
pub mod session;
22+
mod site_metadata;
2223
pub mod summary;
2324
pub mod users;

src/tests/routes/site_metadata.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use crate::tests::util::{RequestHelper, TestApp};
2+
use insta::{assert_json_snapshot, assert_snapshot};
3+
4+
#[tokio::test(flavor = "multi_thread")]
5+
async fn site_metadata_includes_banner_message() {
6+
let (_app, anon) = TestApp::init()
7+
.with_config(|config| {
8+
config.db.primary.read_only_mode = true;
9+
config.banner_message = Some("Test banner message".to_string());
10+
})
11+
.empty()
12+
.await;
13+
14+
let response = anon.get::<()>("/api/v1/site_metadata").await;
15+
assert_snapshot!(response.status(), @"200 OK");
16+
assert_json_snapshot!(response.json());
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: src/tests/routes/site_metadata.rs
3+
expression: response.json()
4+
---
5+
{
6+
"banner_message": "Test banner message",
7+
"commit": "unknown",
8+
"deployed_sha": "unknown",
9+
"read_only": true
10+
}

0 commit comments

Comments
 (0)