Skip to content

Commit 241d8df

Browse files
committed
Auto merge of #1630 - integer32llc:after-2019-02-28, r=carols10cents
DO NOT MERGE until after 2019-03-01; Remove date checks for verified email requirement This removes the date checks added in #1629 so that an email address is always required. The integration tests will start failing after 2019-03-01 00:00:00 UTC; this is the cure.
2 parents c754c10 + dacafbc commit 241d8df

9 files changed

+68
-326
lines changed

src/bin/update-downloads.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ mod test {
149149
user_id,
150150
)
151151
.unwrap();
152-
let version = version
153-
.save(conn, &[], Some("[email protected]".into()))
154-
.unwrap();
152+
let version = version.save(conn, &[], "[email protected]").unwrap();
155153
(krate, version)
156154
}
157155

src/controllers/krate/publish.rs

+11-105
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
use std::collections::HashMap;
44
use std::sync::Arc;
55

6-
use chrono::offset::TimeZone;
7-
use chrono::{DateTime, Utc};
86
use hex::ToHex;
97

108
use crate::git;
@@ -67,14 +65,13 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
6765

6866
let conn = app.diesel_database.get()?;
6967

70-
let mut other_warnings = vec![];
7168
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+
})?;
7875

7976
// Create a transaction on the database, if there are no errors,
8077
// commit the transactions to record a new or updated crate.
@@ -150,7 +147,7 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
150147
file_length as i32,
151148
user.id,
152149
)?
153-
.save(&conn, &new_crate.authors, verified_email_address)?;
150+
.save(&conn, &new_crate.authors, &verified_email_address)?;
154151

155152
// Link this new version to all dependencies
156153
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> {
210207
crate_bomb.path = None;
211208
readme_bomb.path = None;
212209

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.
213213
let warnings = PublishWarnings {
214214
invalid_categories: ignored_invalid_categories,
215215
invalid_badges: ignored_invalid_badges,
216-
other: other_warnings,
216+
other: vec![],
217217
};
218218

219219
Ok(req.json(&GoodCrate {
@@ -268,97 +268,3 @@ fn parse_new_headers(req: &mut dyn Request) -> CargoResult<(EncodableCrateUpload
268268
let user = req.user()?;
269269
Ok((new, user.clone()))
270270
}
271-
272-
fn verified_email_check(
273-
other_warnings: &mut Vec<String>,
274-
verified_email_address: &Option<String>,
275-
now: DateTime<Utc>,
276-
) -> CargoResult<()> {
277-
match verified_email_address {
278-
Some(_) => Ok(()),
279-
None => {
280-
if now < Utc.ymd(2019, 3, 1).and_hms(0, 0, 0) {
281-
other_warnings.push(String::from(
282-
"You do not currently have a verified email address associated with your \
283-
crates.io account. Starting 2019-02-28, a verified email will be required to \
284-
publish crates. Visit https://crates.io/me to set and verify your email \
285-
address.",
286-
));
287-
Ok(())
288-
} else {
289-
Err(human(
290-
"A verified email address is required to publish crates to crates.io. \
291-
Visit https://crates.io/me to set and verify your email address.",
292-
))
293-
}
294-
}
295-
}
296-
}
297-
298-
// These tests should be deleted after 2018-02-28; this functionality will then be covered by
299-
// integration tests in src/tests/krate.rs.
300-
#[cfg(test)]
301-
mod tests {
302-
use super::*;
303-
use chrono::offset::TimeZone;
304-
305-
#[test]
306-
fn allow_publish_with_verified_email_without_warning_before_2018_02_28() {
307-
let mut warnings = vec![];
308-
309-
let fake_current_date = Utc.ymd(2019, 2, 27).and_hms(0, 0, 0);
310-
let result = verified_email_check(
311-
&mut warnings,
312-
&Some("[email protected]".into()),
313-
fake_current_date,
314-
);
315-
316-
assert!(result.is_ok());
317-
assert_eq!(warnings.len(), 0);
318-
}
319-
320-
#[test]
321-
fn allow_publish_with_verified_email_without_error_after_2018_02_28() {
322-
let mut warnings = vec![];
323-
324-
let fake_current_date = Utc.ymd(2019, 3, 1).and_hms(0, 0, 0);
325-
let result = verified_email_check(
326-
&mut warnings,
327-
&Some("[email protected]".into()),
328-
fake_current_date,
329-
);
330-
331-
assert!(result.is_ok());
332-
assert_eq!(warnings.len(), 0);
333-
}
334-
335-
#[test]
336-
fn warn_without_verified_email_before_2018_02_28() {
337-
let mut warnings = vec![];
338-
339-
let fake_current_date = Utc.ymd(2019, 2, 27).and_hms(0, 0, 0);
340-
let result = verified_email_check(&mut warnings, &None, fake_current_date);
341-
342-
assert!(result.is_ok());
343-
assert_eq!(warnings.len(), 1);
344-
assert_eq!(warnings[0], "You do not currently have a verified email address associated \
345-
with your crates.io account. Starting 2019-02-28, a verified email will be required to \
346-
publish crates. Visit https://crates.io/me to set and verify your email address.");
347-
}
348-
349-
#[test]
350-
fn error_without_verified_email_after_2018_02_28() {
351-
let mut warnings = vec![];
352-
353-
let fake_current_date = Utc.ymd(2019, 3, 1).and_hms(0, 0, 0);
354-
let result = verified_email_check(&mut warnings, &None, fake_current_date);
355-
356-
assert!(result.is_err());
357-
assert_eq!(
358-
result.err().unwrap().description(),
359-
"A verified email address is required to \
360-
publish crates to crates.io. Visit https://crates.io/me to set and verify your email \
361-
address."
362-
);
363-
}
364-
}

src/models/version.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,11 @@ impl NewVersion {
148148
Ok(new_version)
149149
}
150150

151-
// TODO: change `published_by_email` to be `String` after 2019-02-28
152151
pub fn save(
153152
&self,
154153
conn: &PgConnection,
155154
authors: &[String],
156-
published_by_email: Option<String>,
155+
published_by_email: &str,
157156
) -> CargoResult<Version> {
158157
use crate::schema::version_authors::{name, version_id};
159158
use crate::schema::versions::dsl::*;
@@ -176,15 +175,12 @@ impl NewVersion {
176175
.values(self)
177176
.get_result::<Version>(conn)?;
178177

179-
// TODO: Remove the `if` around this insert after 2019-02-28
180-
if let Some(published_by_email) = published_by_email {
181-
insert_into(versions_published_by::table)
182-
.values((
183-
versions_published_by::version_id.eq(version.id),
184-
versions_published_by::email.eq(published_by_email),
185-
))
186-
.execute(conn)?;
187-
}
178+
insert_into(versions_published_by::table)
179+
.values((
180+
versions_published_by::version_id.eq(version.id),
181+
versions_published_by::email.eq(published_by_email),
182+
))
183+
.execute(conn)?;
188184

189185
let new_authors = authors
190186
.iter()

src/tests/builders.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'a> VersionBuilder<'a> {
9090
self.size,
9191
published_by,
9292
)?
93-
.save(connection, &[], Some("[email protected]".into()))?;
93+
.save(connection, &[], "[email protected]")?;
9494

9595
if self.yanked {
9696
vers = update(&vers)

src/tests/http-data/krate_new_krate_with_unverified_email_warns

-73
This file was deleted.

src/tests/http-data/krate_new_krate_without_any_email_warns

-73
This file was deleted.

0 commit comments

Comments
 (0)