|
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,9 @@ 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(|| human("A verified email address is required to publish crates to crates.io. \ |
| 70 | + Visit https://crates.io/me to set and verify your email address."))?; |
78 | 71 |
|
79 | 72 | // Create a transaction on the database, if there are no errors,
|
80 | 73 | // commit the transactions to record a new or updated crate.
|
@@ -150,7 +143,7 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
|
150 | 143 | file_length as i32,
|
151 | 144 | user.id,
|
152 | 145 | )?
|
153 |
| - .save(&conn, &new_crate.authors, verified_email_address)?; |
| 146 | + .save(&conn, &new_crate.authors, &verified_email_address)?; |
154 | 147 |
|
155 | 148 | // Link this new version to all dependencies
|
156 | 149 | let git_deps = dependency::add_dependencies(&conn, &new_crate.deps, version.id)?;
|
@@ -210,10 +203,13 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
|
210 | 203 | crate_bomb.path = None;
|
211 | 204 | readme_bomb.path = None;
|
212 | 205 |
|
| 206 | + // The `other` field on `PublishWarnings` was introduced to handle a temporary warning |
| 207 | + // that is no longer needed. As such, crates.io currently does not return any `other` |
| 208 | + // warnings at this time, but if we need to, the field is available. |
213 | 209 | let warnings = PublishWarnings {
|
214 | 210 | invalid_categories: ignored_invalid_categories,
|
215 | 211 | invalid_badges: ignored_invalid_badges,
|
216 |
| - other: other_warnings, |
| 212 | + other: vec![], |
217 | 213 | };
|
218 | 214 |
|
219 | 215 | Ok(req.json(&GoodCrate {
|
@@ -268,100 +264,3 @@ fn parse_new_headers(req: &mut dyn Request) -> CargoResult<(EncodableCrateUpload
|
268 | 264 | let user = req.user()?;
|
269 | 265 | Ok((new, user.clone()))
|
270 | 266 | }
|
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("A verified email address is required to publish crates to crates.io. \ |
295 |
| - Visit https://crates.io/me to set and verify your email address.")) |
296 |
| - } |
297 |
| - } |
298 |
| - } |
299 |
| -} |
300 |
| - |
301 |
| -// These tests should be deleted after 2018-02-28; this functionality will then be covered by |
302 |
| -// integration tests in src/tests/krate.rs. |
303 |
| -#[cfg(test)] |
304 |
| -mod tests { |
305 |
| - use super::*; |
306 |
| - use chrono::offset::TimeZone; |
307 |
| - |
308 |
| - #[test] |
309 |
| - fn allow_publish_with_verified_email_without_warning_before_2018_02_28() { |
310 |
| - let mut warnings = vec![]; |
311 |
| - |
312 |
| - let fake_current_date = Utc.ymd(2019, 2, 27).and_hms(0, 0, 0); |
313 |
| - let result = verified_email_check( |
314 |
| - &mut warnings, |
315 |
| - &Some("[email protected]".into()), |
316 |
| - fake_current_date, |
317 |
| - ); |
318 |
| - |
319 |
| - assert!(result.is_ok()); |
320 |
| - assert_eq!(warnings.len(), 0); |
321 |
| - } |
322 |
| - |
323 |
| - #[test] |
324 |
| - fn allow_publish_with_verified_email_without_error_after_2018_02_28() { |
325 |
| - let mut warnings = vec![]; |
326 |
| - |
327 |
| - let fake_current_date = Utc.ymd(2019, 3, 1).and_hms(0, 0, 0); |
328 |
| - let result = verified_email_check( |
329 |
| - &mut warnings, |
330 |
| - &Some("[email protected]".into()), |
331 |
| - fake_current_date, |
332 |
| - ); |
333 |
| - |
334 |
| - assert!(result.is_ok()); |
335 |
| - assert_eq!(warnings.len(), 0); |
336 |
| - } |
337 |
| - |
338 |
| - #[test] |
339 |
| - fn warn_without_verified_email_before_2018_02_28() { |
340 |
| - let mut warnings = vec![]; |
341 |
| - |
342 |
| - let fake_current_date = Utc.ymd(2019, 2, 27).and_hms(0, 0, 0); |
343 |
| - let result = verified_email_check(&mut warnings, &None, fake_current_date); |
344 |
| - |
345 |
| - assert!(result.is_ok()); |
346 |
| - assert_eq!(warnings.len(), 1); |
347 |
| - assert_eq!(warnings[0], "You do not currently have a verified email address associated \ |
348 |
| - with your crates.io account. Starting 2019-02-28, a verified email will be required to \ |
349 |
| - publish crates. Visit https://crates.io/me to set and verify your email address."); |
350 |
| - } |
351 |
| - |
352 |
| - #[test] |
353 |
| - fn error_without_verified_email_after_2018_02_28() { |
354 |
| - let mut warnings = vec![]; |
355 |
| - |
356 |
| - let fake_current_date = Utc.ymd(2019, 3, 1).and_hms(0, 0, 0); |
357 |
| - let result = verified_email_check(&mut warnings, &None, fake_current_date); |
358 |
| - |
359 |
| - assert!(result.is_err()); |
360 |
| - assert_eq!( |
361 |
| - result.err().unwrap().description(), |
362 |
| - "A verified email address is required to \ |
363 |
| - publish crates to crates.io. Visit https://crates.io/me to set and verify your email \ |
364 |
| - address." |
365 |
| - ); |
366 |
| - } |
367 |
| -} |
0 commit comments