@@ -89,7 +89,7 @@ impl QueryProject {
8989 . map_err ( resource_not_found_err ! ( Project , slug. clone( ) ) )
9090 }
9191
92- pub async fn get_or_create (
92+ pub async fn get_or_create_from_project (
9393 log : & Logger ,
9494 context : & ApiContext ,
9595 auth_user : & AuthUser ,
@@ -110,7 +110,8 @@ impl QueryProject {
110110 ResourceIdKind :: Slug ( slug) => slug,
111111 } ;
112112
113- let query_organization = QueryOrganization :: get_or_create ( context, auth_user) . await ?;
113+ let query_organization =
114+ QueryOrganization :: get_or_create_from_user ( context, auth_user) . await ?;
114115 let json_project = JsonNewProject {
115116 name : slug. clone ( ) . into ( ) ,
116117 slug : Some ( slug. clone ( ) ) ,
@@ -131,7 +132,8 @@ impl QueryProject {
131132 return Ok ( query_project) ;
132133 }
133134
134- let query_organization = QueryOrganization :: get_or_create ( context, auth_user) . await ?;
135+ let query_organization =
136+ QueryOrganization :: get_or_create_from_user ( context, auth_user) . await ?;
135137 let name = Self :: unique_name ( context, & query_organization, project_name) . await ?;
136138 let json_project = JsonNewProject {
137139 name,
@@ -226,29 +228,18 @@ impl QueryProject {
226228 query_organization : & QueryOrganization ,
227229 json_project : JsonNewProject ,
228230 ) -> Result < Self , HttpError > {
229- let insert_project =
230- InsertProject :: from_json ( conn_lock ! ( context) , query_organization, json_project) ?;
231-
232231 // Check to see if user has permission to create a project within the organization
233232 context
234233 . rbac
235234 . is_allowed_organization (
236235 auth_user,
237236 bencher_rbac:: organization:: Permission :: Create ,
238- & insert_project ,
237+ query_organization ,
239238 )
240239 . map_err ( forbidden_error) ?;
241240
242- diesel:: insert_into ( project_table:: table)
243- . values ( & insert_project)
244- . execute ( conn_lock ! ( context) )
245- . map_err ( resource_conflict_err ! ( Project , & insert_project) ) ?;
246- let query_project = Self :: from_uuid (
247- conn_lock ! ( context) ,
248- query_organization. id ,
249- insert_project. uuid ,
250- ) ?;
251- slog:: debug!( log, "Created project: {query_project:?}" ) ;
241+ let query_project =
242+ Self :: create_inner ( log, context, query_organization, json_project) . await ?;
252243
253244 let timestamp = DateTime :: now ( ) ;
254245 // Connect the user to the project as a `Maintainer`
@@ -265,6 +256,28 @@ impl QueryProject {
265256 . map_err ( resource_conflict_err ! ( ProjectRole , insert_proj_role) ) ?;
266257 slog:: debug!( log, "Added project role: {insert_proj_role:?}" ) ;
267258
259+ Ok ( query_project)
260+ }
261+
262+ async fn create_inner (
263+ log : & Logger ,
264+ context : & ApiContext ,
265+ query_organization : & QueryOrganization ,
266+ json_project : JsonNewProject ,
267+ ) -> Result < Self , HttpError > {
268+ let insert_project =
269+ InsertProject :: from_json ( conn_lock ! ( context) , query_organization, json_project) ?;
270+ diesel:: insert_into ( project_table:: table)
271+ . values ( & insert_project)
272+ . execute ( conn_lock ! ( context) )
273+ . map_err ( resource_conflict_err ! ( Project , & insert_project) ) ?;
274+ let query_project = Self :: from_uuid (
275+ conn_lock ! ( context) ,
276+ query_organization. id ,
277+ insert_project. uuid ,
278+ ) ?;
279+ slog:: debug!( log, "Created project: {query_project:?}" ) ;
280+
268281 #[ cfg( feature = "plus" ) ]
269282 context. update_index ( log, & query_project) . await ;
270283
0 commit comments