@@ -10,20 +10,15 @@ use crate::controllers::helpers::pagination::*;
10
10
use crate :: email;
11
11
use crate :: models:: version:: TopVersions ;
12
12
use crate :: models:: {
13
- Badge , Category , CrateOwner , CrateOwnerInvitation , Keyword , NewCrateOwnerInvitation , Owner ,
14
- OwnerKind , ReverseDependency , User , Version ,
13
+ Badge , CrateOwner , CrateOwnerInvitation , NewCrateOwnerInvitation , Owner , OwnerKind ,
14
+ ReverseDependency , User , Version ,
15
15
} ;
16
16
use crate :: util:: errors:: { cargo_err, AppResult } ;
17
- use crate :: views:: { EncodableCrate , EncodableCrateLinks } ;
18
17
19
18
use crate :: models:: helpers:: with_count:: * ;
20
19
use crate :: publish_rate_limit:: PublishRateLimit ;
21
20
use crate :: schema:: * ;
22
21
23
- /// Hosts in this list are known to not be hosting documentation,
24
- /// and are possibly of malicious intent e.g. ad tracking networks, etc.
25
- const DOCUMENTATION_BLOCKLIST : [ & str ; 2 ] = [ "rust-ci.org" , "rustless.org" ] ;
26
-
27
22
#[ derive( Debug , Queryable , Identifiable , Associations , Clone , Copy ) ]
28
23
#[ belongs_to( Crate ) ]
29
24
#[ primary_key( crate_id) ]
@@ -296,109 +291,6 @@ impl Crate {
296
291
&& prefix_part. map_or ( true , Crate :: valid_feature_prefix)
297
292
}
298
293
299
- #[ allow( clippy:: too_many_arguments) ]
300
- pub fn encodable (
301
- self ,
302
- top_versions : & TopVersions ,
303
- versions : Option < Vec < i32 > > ,
304
- keywords : Option < & [ Keyword ] > ,
305
- categories : Option < & [ Category ] > ,
306
- badges : Option < Vec < Badge > > ,
307
- exact_match : bool ,
308
- recent_downloads : Option < i64 > ,
309
- ) -> EncodableCrate {
310
- let Crate {
311
- name,
312
- created_at,
313
- updated_at,
314
- downloads,
315
- description,
316
- homepage,
317
- documentation,
318
- repository,
319
- ..
320
- } = self ;
321
- let versions_link = match versions {
322
- Some ( ..) => None ,
323
- None => Some ( format ! ( "/api/v1/crates/{}/versions" , name) ) ,
324
- } ;
325
- let keyword_ids = keywords. map ( |kws| kws. iter ( ) . map ( |kw| kw. keyword . clone ( ) ) . collect ( ) ) ;
326
- let category_ids = categories. map ( |cats| cats. iter ( ) . map ( |cat| cat. slug . clone ( ) ) . collect ( ) ) ;
327
- let badges = badges. map ( |bs| bs. into_iter ( ) . map ( Badge :: into) . collect ( ) ) ;
328
- let documentation = Crate :: remove_blocked_documentation_urls ( documentation) ;
329
-
330
- let max_version = top_versions
331
- . highest
332
- . as_ref ( )
333
- . map ( |v| v. to_string ( ) )
334
- . unwrap_or_else ( || "0.0.0" . to_string ( ) ) ;
335
-
336
- let newest_version = top_versions
337
- . newest
338
- . as_ref ( )
339
- . map ( |v| v. to_string ( ) )
340
- . unwrap_or_else ( || "0.0.0" . to_string ( ) ) ;
341
-
342
- let max_stable_version = top_versions. highest_stable . as_ref ( ) . map ( |v| v. to_string ( ) ) ;
343
-
344
- EncodableCrate {
345
- id : name. clone ( ) ,
346
- name : name. clone ( ) ,
347
- updated_at,
348
- created_at,
349
- downloads,
350
- recent_downloads,
351
- versions,
352
- keywords : keyword_ids,
353
- categories : category_ids,
354
- badges,
355
- max_version,
356
- newest_version,
357
- max_stable_version,
358
- documentation,
359
- homepage,
360
- exact_match,
361
- description,
362
- repository,
363
- links : EncodableCrateLinks {
364
- version_downloads : format ! ( "/api/v1/crates/{}/downloads" , name) ,
365
- versions : versions_link,
366
- owners : Some ( format ! ( "/api/v1/crates/{}/owners" , name) ) ,
367
- owner_team : Some ( format ! ( "/api/v1/crates/{}/owner_team" , name) ) ,
368
- owner_user : Some ( format ! ( "/api/v1/crates/{}/owner_user" , name) ) ,
369
- reverse_dependencies : format ! ( "/api/v1/crates/{}/reverse_dependencies" , name) ,
370
- } ,
371
- }
372
- }
373
-
374
- /// Return `None` if the documentation URL host matches a blocked host
375
- fn remove_blocked_documentation_urls ( url : Option < String > ) -> Option < String > {
376
- // Handles if documentation URL is None
377
- let url = match url {
378
- Some ( url) => url,
379
- None => return None ,
380
- } ;
381
-
382
- // Handles unsuccessful parsing of documentation URL
383
- let parsed_url = match Url :: parse ( & url) {
384
- Ok ( parsed_url) => parsed_url,
385
- Err ( _) => return None ,
386
- } ;
387
-
388
- // Extract host string from documentation URL
389
- let url_host = match parsed_url. host_str ( ) {
390
- Some ( url_host) => url_host,
391
- None => return None ,
392
- } ;
393
-
394
- // Match documentation URL host against blocked host array elements
395
- if DOCUMENTATION_BLOCKLIST . contains ( & url_host) {
396
- None
397
- } else {
398
- Some ( url)
399
- }
400
- }
401
-
402
294
/// Return both the newest (most recently updated) and
403
295
/// highest version (in semver order) for the current crate.
404
296
pub fn top_versions ( & self , conn : & PgConnection ) -> QueryResult < TopVersions > {
@@ -558,39 +450,6 @@ mod tests {
558
450
assert_err ! ( krate. validate( ) ) ;
559
451
}
560
452
561
- #[ test]
562
- fn documentation_blocked_no_url_provided ( ) {
563
- assert_eq ! ( Crate :: remove_blocked_documentation_urls( None ) , None ) ;
564
- }
565
-
566
- #[ test]
567
- fn documentation_blocked_invalid_url ( ) {
568
- assert_eq ! (
569
- Crate :: remove_blocked_documentation_urls( Some ( String :: from( "not a url" ) ) ) ,
570
- None
571
- ) ;
572
- }
573
-
574
- #[ test]
575
- fn documentation_blocked_url_contains_partial_match ( ) {
576
- assert_eq ! (
577
- Crate :: remove_blocked_documentation_urls( Some ( String :: from(
578
- "http://rust-ci.organists.com"
579
- ) ) , ) ,
580
- Some ( String :: from( "http://rust-ci.organists.com" ) )
581
- ) ;
582
- }
583
-
584
- #[ test]
585
- fn documentation_blocked_url ( ) {
586
- assert_eq ! (
587
- Crate :: remove_blocked_documentation_urls( Some ( String :: from(
588
- "http://rust-ci.org/crate/crate-0.1/doc/crate-0.1" ,
589
- ) , ) , ) ,
590
- None
591
- ) ;
592
- }
593
-
594
453
#[ test]
595
454
fn valid_name ( ) {
596
455
assert ! ( Crate :: valid_name( "foo" ) ) ;
0 commit comments