@@ -10,7 +10,7 @@ use time::Duration;
10
10
use time:: Timespec ;
11
11
use url;
12
12
13
- use { Model , Crate , User } ;
13
+ use { Model , Crate } ;
14
14
use app:: RequestApp ;
15
15
use db:: RequestTransaction ;
16
16
use dependency:: { Dependency , EncodableDependency , Kind } ;
@@ -33,9 +33,8 @@ pub struct Version {
33
33
pub yanked : bool ,
34
34
}
35
35
36
- pub enum Author {
37
- User ( User ) ,
38
- Name ( String ) ,
36
+ pub struct Author {
37
+ pub name : String
39
38
}
40
39
41
40
#[ derive( RustcEncodable , RustcDecodable ) ]
@@ -168,23 +167,17 @@ impl Version {
168
167
169
168
pub fn authors ( & self , conn : & GenericConnection ) -> CargoResult < Vec < Author > > {
170
169
let stmt = conn. prepare ( "SELECT * FROM version_authors
171
- WHERE version_id = $1" ) ?;
170
+ WHERE version_id = $1
171
+ ORDER BY name ASC" ) ?;
172
172
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 ( ) )
181
176
}
182
177
183
178
pub fn add_author ( & self ,
184
179
conn : & GenericConnection ,
185
180
name : & str ) -> CargoResult < ( ) > {
186
- println ! ( "add author: {}" , name) ;
187
- // TODO: at least try to link `name` to a pre-existing user
188
181
conn. execute ( "INSERT INTO version_authors (version_id, name)
189
182
VALUES ($1, $2)" , & [ & self . id , & name] ) ?;
190
183
Ok ( ( ) )
@@ -329,19 +322,16 @@ pub fn downloads(req: &mut Request) -> CargoResult<Response> {
329
322
pub fn authors ( req : & mut Request ) -> CargoResult < Response > {
330
323
let ( version, _) = version_and_crate ( req) ?;
331
324
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 ( ) ;
339
326
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.
340
330
#[ derive( RustcEncodable ) ]
341
331
struct R { users : Vec < :: user:: EncodableUser > , meta : Meta }
342
332
#[ derive( RustcEncodable ) ]
343
333
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 } } ) )
345
335
}
346
336
347
337
/// Handles the `DELETE /crates/:crate_id/:version/yank` route.
0 commit comments