@@ -7,65 +7,6 @@ use ariadne::ids::UserId;
77use eyre:: eyre;
88use sqlx:: PgPool ;
99
10- /// Fetches ownership information for a single project.
11- pub async fn get_project_ownership (
12- project_id : crate :: models:: ids:: ProjectId ,
13- team_id : crate :: models:: ids:: TeamId ,
14- organization : Option < OrganizationId > ,
15- pool : & PgPool ,
16- redis : & RedisPool ,
17- ) -> Result < Ownership , crate :: routes:: ApiError > {
18- if let Some ( org_id) = organization {
19- let org = DBOrganization :: get ( & org_id. to_string ( ) , pool, redis)
20- . await
21- . wrap_internal_err ( "failed to fetch organization" ) ?
22- . ok_or_else ( || {
23- crate :: routes:: ApiError :: Internal (
24- eyre ! ( "project {project_id} is owned by an invalid organization {org_id}" )
25- )
26- } ) ?;
27-
28- Ok ( Ownership :: Organization {
29- id : OrganizationId :: from ( org. id ) ,
30- name : org. name . clone ( ) ,
31- icon_url : org. icon_url ,
32- } )
33- } else {
34- let team_members = DBTeamMember :: get_from_team_full (
35- DBTeamId :: from ( team_id) ,
36- pool,
37- redis,
38- )
39- . await
40- . wrap_internal_err ( "failed to fetch team members" ) ?;
41-
42- let team_owner = team_members
43- . iter ( )
44- . find ( |member| member. is_owner )
45- . ok_or_else ( || {
46- crate :: routes:: ApiError :: Internal ( eyre ! (
47- "project {project_id} is owned by a team {team_id} which has no valid owner"
48- ) )
49- } ) ?;
50-
51- let user = DBUser :: get ( & team_owner. user_id . 0 . to_string ( ) , pool, redis)
52- . await
53- . wrap_internal_err ( "failed to fetch user data" ) ?
54- . ok_or_else ( || {
55- crate :: routes:: ApiError :: Internal ( eyre ! (
56- "project {project_id} is owned by a team {team_id} which has owner {} which does not exist" ,
57- ariadne:: ids:: UserId :: from( team_owner. user_id)
58- ) )
59- } ) ?;
60-
61- Ok ( Ownership :: User {
62- id : ariadne:: ids:: UserId :: from ( user. id ) ,
63- name : user. username . clone ( ) ,
64- icon_url : user. avatar_url ,
65- } )
66- }
67- }
68-
6910/// Fetches ownership information for multiple projects efficiently
7011pub async fn get_projects_ownership (
7112 projects : & [ crate :: models:: projects:: Project ] ,
0 commit comments