Skip to content

Commit 9cb919f

Browse files
Merge pull request #571 from Eh2406/fix467
Fix #467 - Author ordering
2 parents 4074d59 + ccc7a40 commit 9cb919f

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

src/version.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use time::Duration;
1010
use time::Timespec;
1111
use url;
1212

13-
use {Model, Crate, User};
13+
use {Model, Crate};
1414
use app::RequestApp;
1515
use db::RequestTransaction;
1616
use dependency::{Dependency, EncodableDependency, Kind};
@@ -33,9 +33,8 @@ pub struct Version {
3333
pub yanked: bool,
3434
}
3535

36-
pub enum Author {
37-
User(User),
38-
Name(String),
36+
pub struct Author {
37+
pub name: String
3938
}
4039

4140
#[derive(RustcEncodable, RustcDecodable)]
@@ -168,23 +167,17 @@ impl Version {
168167

169168
pub fn authors(&self, conn: &GenericConnection) -> CargoResult<Vec<Author>> {
170169
let stmt = conn.prepare("SELECT * FROM version_authors
171-
WHERE version_id = $1")?;
170+
WHERE version_id = $1
171+
ORDER BY name ASC")?;
172172
let rows = stmt.query(&[&self.id])?;
173-
rows.into_iter().map(|row| {
174-
let user_id: Option<i32> = row.get("user_id");
175-
let name: String = row.get("name");
176-
Ok(match user_id {
177-
Some(id) => Author::User(User::find(conn, id)?),
178-
None => Author::Name(name),
179-
})
180-
}).collect()
173+
Ok(rows.into_iter().map(|row| {
174+
Author { name: row.get("name") }
175+
}).collect())
181176
}
182177

183178
pub fn add_author(&self,
184179
conn: &GenericConnection,
185180
name: &str) -> CargoResult<()> {
186-
println!("add author: {}", name);
187-
// TODO: at least try to link `name` to a pre-existing user
188181
conn.execute("INSERT INTO version_authors (version_id, name)
189182
VALUES ($1, $2)", &[&self.id, &name])?;
190183
Ok(())
@@ -329,19 +322,16 @@ pub fn downloads(req: &mut Request) -> CargoResult<Response> {
329322
pub fn authors(req: &mut Request) -> CargoResult<Response> {
330323
let (version, _) = version_and_crate(req)?;
331324
let tx = req.tx()?;
332-
let (mut users, mut names) = (Vec::new(), Vec::new());
333-
for author in version.authors(tx)?.into_iter() {
334-
match author {
335-
Author::User(u) => users.push(u.encodable()),
336-
Author::Name(n) => names.push(n),
337-
}
338-
}
325+
let names = version.authors(tx)?.into_iter().map(|a| a.name).collect();
339326

327+
// It was imagined that we wold associate authors with users.
328+
// This was never implemented. This complicated return struct
329+
// is all that is left, hear for backwards compatibility.
340330
#[derive(RustcEncodable)]
341331
struct R { users: Vec<::user::EncodableUser>, meta: Meta }
342332
#[derive(RustcEncodable)]
343333
struct Meta { names: Vec<String> }
344-
Ok(req.json(&R{ users: users, meta: Meta { names: names } }))
334+
Ok(req.json(&R{ users: vec![], meta: Meta { names: names } }))
345335
}
346336

347337
/// Handles the `DELETE /crates/:crate_id/:version/yank` route.

0 commit comments

Comments
 (0)