|
3 | 3 | use std::collections::HashMap;
|
4 | 4 | use std::sync::Arc;
|
5 | 5 |
|
6 |
| -use chrono::offset::TimeZone; |
7 |
| -use chrono::{DateTime, Utc}; |
8 | 6 | use hex::ToHex;
|
9 | 7 |
|
10 | 8 | use crate::git;
|
@@ -67,14 +65,13 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
|
67 | 65 |
|
68 | 66 | let conn = app.diesel_database.get()?;
|
69 | 67 |
|
70 |
| - let mut other_warnings = vec![]; |
71 | 68 | let verified_email_address = user.verified_email(&conn)?;
|
72 |
| - |
73 |
| - // This function can be inlined (with only the error-returning functionality) and its unit |
74 |
| - // tests deleted after 2019-02-28; it was created to make injecting the date for tests easier. |
75 |
| - // The integration tests in src/tests/krate.rs cover the current production behavior (and will |
76 |
| - // need to be updated at that time) |
77 |
| - verified_email_check(&mut other_warnings, &verified_email_address, Utc::now())?; |
| 69 | + let verified_email_address = verified_email_address.ok_or_else(|| { |
| 70 | + human( |
| 71 | + "A verified email address is required to publish crates to crates.io. \ |
| 72 | + Visit https://crates.io/me to set and verify your email address.", |
| 73 | + ) |
| 74 | + })?; |
78 | 75 |
|
79 | 76 | // Create a transaction on the database, if there are no errors,
|
80 | 77 | // commit the transactions to record a new or updated crate.
|
@@ -150,7 +147,7 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
|
150 | 147 | file_length as i32,
|
151 | 148 | user.id,
|
152 | 149 | )?
|
153 |
| - .save(&conn, &new_crate.authors, verified_email_address)?; |
| 150 | + .save(&conn, &new_crate.authors, &verified_email_address)?; |
154 | 151 |
|
155 | 152 | // Link this new version to all dependencies
|
156 | 153 | let git_deps = dependency::add_dependencies(&conn, &new_crate.deps, version.id)?;
|
@@ -210,10 +207,13 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
|
210 | 207 | crate_bomb.path = None;
|
211 | 208 | readme_bomb.path = None;
|
212 | 209 |
|
| 210 | + // The `other` field on `PublishWarnings` was introduced to handle a temporary warning |
| 211 | + // that is no longer needed. As such, crates.io currently does not return any `other` |
| 212 | + // warnings at this time, but if we need to, the field is available. |
213 | 213 | let warnings = PublishWarnings {
|
214 | 214 | invalid_categories: ignored_invalid_categories,
|
215 | 215 | invalid_badges: ignored_invalid_badges,
|
216 |
| - other: other_warnings, |
| 216 | + other: vec![], |
217 | 217 | };
|
218 | 218 |
|
219 | 219 | Ok(req.json(&GoodCrate {
|
@@ -268,102 +268,3 @@ fn parse_new_headers(req: &mut dyn Request) -> CargoResult<(EncodableCrateUpload
|
268 | 268 | let user = req.user()?;
|
269 | 269 | Ok((new, user.clone()))
|
270 | 270 | }
|
271 |
| - |
272 |
| -lazy_static! { |
273 |
| - static ref VERIFIED_EMAIL_REQUIRED_DATE: DateTime<Utc> = |
274 |
| - { Utc.ymd(2019, 3, 1).and_hms(0, 0, 0) }; |
275 |
| -} |
276 |
| - |
277 |
| -fn verified_email_check( |
278 |
| - other_warnings: &mut Vec<String>, |
279 |
| - verified_email_address: &Option<String>, |
280 |
| - now: DateTime<Utc>, |
281 |
| -) -> CargoResult<()> { |
282 |
| - match verified_email_address { |
283 |
| - Some(_) => Ok(()), |
284 |
| - None => { |
285 |
| - if now < *VERIFIED_EMAIL_REQUIRED_DATE { |
286 |
| - other_warnings.push(String::from( |
287 |
| - "You do not currently have a verified email address associated with your \ |
288 |
| - crates.io account. Starting 2019-02-28, a verified email will be required to \ |
289 |
| - publish crates. Visit https://crates.io/me to set and verify your email \ |
290 |
| - address.", |
291 |
| - )); |
292 |
| - Ok(()) |
293 |
| - } else { |
294 |
| - Err(human( |
295 |
| - "A verified email address is required to publish crates to crates.io. \ |
296 |
| - Visit https://crates.io/me to set and verify your email address.", |
297 |
| - )) |
298 |
| - } |
299 |
| - } |
300 |
| - } |
301 |
| -} |
302 |
| - |
303 |
| -// These tests should be deleted after 2018-02-28; this functionality will then be covered by |
304 |
| -// integration tests in src/tests/krate.rs. |
305 |
| -#[cfg(test)] |
306 |
| -mod tests { |
307 |
| - use super::*; |
308 |
| - use chrono::offset::TimeZone; |
309 |
| - |
310 |
| - #[test] |
311 |
| - fn allow_publish_with_verified_email_without_warning_before_2018_02_28() { |
312 |
| - let mut warnings = vec![]; |
313 |
| - |
314 |
| - let fake_current_date = Utc.ymd(2019, 2, 27).and_hms(0, 0, 0); |
315 |
| - let result = verified_email_check( |
316 |
| - &mut warnings, |
317 |
| - &Some("[email protected]".into()), |
318 |
| - fake_current_date, |
319 |
| - ); |
320 |
| - |
321 |
| - assert!(result.is_ok()); |
322 |
| - assert_eq!(warnings.len(), 0); |
323 |
| - } |
324 |
| - |
325 |
| - #[test] |
326 |
| - fn allow_publish_with_verified_email_without_error_after_2018_02_28() { |
327 |
| - let mut warnings = vec![]; |
328 |
| - |
329 |
| - let fake_current_date = Utc.ymd(2019, 3, 1).and_hms(0, 0, 0); |
330 |
| - let result = verified_email_check( |
331 |
| - &mut warnings, |
332 |
| - &Some("[email protected]".into()), |
333 |
| - fake_current_date, |
334 |
| - ); |
335 |
| - |
336 |
| - assert!(result.is_ok()); |
337 |
| - assert_eq!(warnings.len(), 0); |
338 |
| - } |
339 |
| - |
340 |
| - #[test] |
341 |
| - fn warn_without_verified_email_before_2018_02_28() { |
342 |
| - let mut warnings = vec![]; |
343 |
| - |
344 |
| - let fake_current_date = Utc.ymd(2019, 2, 27).and_hms(0, 0, 0); |
345 |
| - let result = verified_email_check(&mut warnings, &None, fake_current_date); |
346 |
| - |
347 |
| - assert!(result.is_ok()); |
348 |
| - assert_eq!(warnings.len(), 1); |
349 |
| - assert_eq!(warnings[0], "You do not currently have a verified email address associated \ |
350 |
| - with your crates.io account. Starting 2019-02-28, a verified email will be required to \ |
351 |
| - publish crates. Visit https://crates.io/me to set and verify your email address."); |
352 |
| - } |
353 |
| - |
354 |
| - #[test] |
355 |
| - fn error_without_verified_email_after_2018_02_28() { |
356 |
| - let mut warnings = vec![]; |
357 |
| - |
358 |
| - let fake_current_date = Utc.ymd(2019, 3, 1).and_hms(0, 0, 0); |
359 |
| - let result = verified_email_check(&mut warnings, &None, fake_current_date); |
360 |
| - |
361 |
| - assert!(result.is_err()); |
362 |
| - assert_eq!( |
363 |
| - result.err().unwrap().description(), |
364 |
| - "A verified email address is required to \ |
365 |
| - publish crates to crates.io. Visit https://crates.io/me to set and verify your email \ |
366 |
| - address." |
367 |
| - ); |
368 |
| - } |
369 |
| -} |
0 commit comments