@@ -5,13 +5,11 @@ use diesel::prelude::*;
55use diesel:: sql_types:: Integer ;
66use diesel:: upsert:: excluded;
77use diesel_async:: { AsyncPgConnection , RunQueryDsl } ;
8- use oauth2:: AccessToken ;
9- use secrecy:: { ExposeSecret , SecretString } ;
8+ use secrecy:: SecretString ;
109
11- use crate :: models:: { Crate , CrateOwner , Email , Owner , OwnerKind , Rights } ;
10+ use crate :: models:: { Crate , CrateOwner , Email , Owner , OwnerKind } ;
1211use crate :: schema:: { crate_owners, emails, users} ;
1312use crates_io_diesel_helpers:: lower;
14- use crates_io_github:: { GitHubClient , GitHubError } ;
1513
1614/// The model representing a row in the `users` database table.
1715#[ derive( Clone , Debug , Queryable , Identifiable , Selectable ) ]
@@ -56,48 +54,6 @@ impl User {
5654 Ok ( users. collect ( ) )
5755 }
5856
59- /// Given this set of owners, determines the strongest rights the
60- /// user has.
61- ///
62- /// Shortcircuits on `Full` because you can't beat it. In practice we'll always
63- /// see `[user, user, user, ..., team, team, team]`, so we could shortcircuit on
64- /// `Publish` as well, but this is a non-obvious invariant so we don't bother.
65- /// Sweet free optimization if teams are proving burdensome to check.
66- /// More than one team isn't really expected, though.
67- pub async fn rights (
68- & self ,
69- gh_client : & dyn GitHubClient ,
70- owners : & [ Owner ] ,
71- ) -> Result < Rights , GitHubError > {
72- let token = AccessToken :: new ( self . gh_access_token . expose_secret ( ) . to_string ( ) ) ;
73-
74- let mut best = Rights :: None ;
75- for owner in owners {
76- match * owner {
77- Owner :: User ( ref other_user) => {
78- if other_user. id == self . id {
79- return Ok ( Rights :: Full ) ;
80- }
81- }
82- Owner :: Team ( ref team) => {
83- // Phones home to GitHub to ask if this User is a member of the given team.
84- // Note that we're assuming that the given user is the one interested in
85- // the answer. If this is not the case, then we could accidentally leak
86- // private membership information here.
87- let is_team_member = gh_client
88- . team_membership ( team. org_id , team. github_id , & self . gh_login , & token)
89- . await ?
90- . is_some_and ( |m| m. is_active ( ) ) ;
91-
92- if is_team_member {
93- best = Rights :: Publish ;
94- }
95- }
96- }
97- }
98- Ok ( best)
99- }
100-
10157 /// Queries the database for the verified emails
10258 /// belonging to a given user
10359 pub async fn verified_email (
0 commit comments