Skip to content

Commit 188e033

Browse files
committed
views: Prepare to expose the yanked field on the API
The `yanked` state is based on the `default_version`. The `default_version` can only be yanked if all other versions are also yanked. A crate should only be yanked if all of its versions are yanked.
1 parent c6011c7 commit 188e033

File tree

5 files changed

+11
-0
lines changed

5 files changed

+11
-0
lines changed

src/controllers/krate/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ pub async fn show(app: AppState, Path(name): Path<String>, req: Parts) -> AppRes
126126
let encodable_crate = EncodableCrate::from(
127127
krate.clone(),
128128
default_version.as_deref(),
129+
None,
129130
top_versions.as_ref(),
130131
ids,
131132
kws.as_deref(),

src/controllers/krate/publish.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
519519
krate: EncodableCrate::from_minimal(
520520
krate,
521521
default_version.or(Some(version_string)).as_deref(),
522+
None,
522523
Some(&top_versions),
523524
false,
524525
downloads,

src/controllers/krate/search.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ pub async fn search(app: AppState, req: Parts) -> AppResult<Json<Value>> {
235235
EncodableCrate::from_minimal(
236236
krate,
237237
default_version.as_deref(),
238+
None,
238239
Some(&max_version),
239240
perfect_match,
240241
total,

src/controllers/summary.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub async fn summary(state: AppState) -> AppResult<Json<Value>> {
4747
Ok(EncodableCrate::from_minimal(
4848
krate,
4949
default_version.as_deref(),
50+
None,
5051
Some(&top_versions),
5152
false,
5253
total,

src/views.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ pub struct EncodableCrate {
209209
pub downloads: i64,
210210
pub recent_downloads: Option<i64>,
211211
pub default_version: Option<String>,
212+
#[serde(skip_serializing_if = "Option::is_none")]
213+
pub yanked: Option<bool>,
212214
// NOTE: Used by shields.io, altering `max_version` requires a PR with shields.io
213215
pub max_version: String,
214216
pub newest_version: String, // Most recently updated version, which may not be max
@@ -226,6 +228,7 @@ impl EncodableCrate {
226228
pub fn from(
227229
krate: Crate,
228230
default_version: Option<&str>,
231+
yanked: Option<bool>,
229232
top_versions: Option<&TopVersions>,
230233
versions: Option<Vec<i32>>,
231234
keywords: Option<&[Keyword]>,
@@ -296,6 +299,7 @@ impl EncodableCrate {
296299
categories: category_ids,
297300
badges: [],
298301
default_version,
302+
yanked,
299303
max_version,
300304
newest_version,
301305
max_stable_version,
@@ -318,6 +322,7 @@ impl EncodableCrate {
318322
pub fn from_minimal(
319323
krate: Crate,
320324
default_version: Option<&str>,
325+
yanked: Option<bool>,
321326
top_versions: Option<&TopVersions>,
322327
exact_match: bool,
323328
downloads: i64,
@@ -326,6 +331,7 @@ impl EncodableCrate {
326331
Self::from(
327332
krate,
328333
default_version,
334+
yanked,
329335
top_versions,
330336
None,
331337
None,
@@ -808,6 +814,7 @@ mod tests {
808814
downloads: 0,
809815
recent_downloads: None,
810816
default_version: None,
817+
yanked: None,
811818
max_version: "".to_string(),
812819
newest_version: "".to_string(),
813820
max_stable_version: None,

0 commit comments

Comments
 (0)