@@ -14,7 +14,8 @@ use crate::{
1414 app:: models:: { Entity , Project , UserRole } ,
1515 utils:: validate:: can_access_project,
1616 web:: {
17- MaybeExtract , RouterState , SessionUser ,
17+ RouterState ,
18+ session:: { Auth , MaybeAuth } ,
1819 webext:: { ApiResult , AxumErrExt , empty_response, http_bail} ,
1920 } ,
2021} ;
@@ -152,7 +153,7 @@ struct EntitiesResponse {
152153
153154async fn get_users (
154155 app : State < RouterState > ,
155- SessionUser ( user) : SessionUser ,
156+ Auth ( user) : Auth ,
156157) -> ApiResult < UseApi < impl IntoApiResponse , Json < UsersResponse > > > {
157158 if user. role != UserRole :: Admin {
158159 http_bail ! ( StatusCode :: FORBIDDEN , "Forbidden" )
@@ -172,7 +173,7 @@ async fn get_users(
172173async fn update_user (
173174 app : State < RouterState > ,
174175 Path ( username) : Path < String > ,
175- SessionUser ( session_user) : SessionUser ,
176+ Auth ( session_user) : Auth ,
176177 user : Json < UpdateUserRequest > ,
177178) -> ApiResult < impl IntoApiResponse > {
178179 if session_user. role != UserRole :: Admin {
@@ -193,7 +194,7 @@ async fn update_user(
193194async fn update_user_password (
194195 app : State < RouterState > ,
195196 Path ( username) : Path < String > ,
196- SessionUser ( session_user) : SessionUser ,
197+ Auth ( session_user) : Auth ,
197198 password : Json < UpdatePasswordRequest > ,
198199) -> ApiResult < impl IntoApiResponse > {
199200 if session_user. role != UserRole :: Admin || username != session_user. username {
@@ -210,7 +211,7 @@ async fn update_user_password(
210211async fn remove_user (
211212 app : State < RouterState > ,
212213 Path ( username) : Path < String > ,
213- SessionUser ( session_user) : SessionUser ,
214+ Auth ( session_user) : Auth ,
214215) -> ApiResult < impl IntoApiResponse > {
215216 if session_user. role != UserRole :: Admin {
216217 http_bail ! ( StatusCode :: FORBIDDEN , "Forbidden" )
@@ -227,7 +228,7 @@ async fn remove_user(
227228
228229async fn create_user (
229230 app : State < RouterState > ,
230- SessionUser ( session_user) : SessionUser ,
231+ Auth ( session_user) : Auth ,
231232 user : Json < CreateUserRequest > ,
232233) -> ApiResult < impl IntoApiResponse > {
233234 if session_user. role != UserRole :: Admin {
@@ -246,7 +247,7 @@ async fn create_user(
246247async fn project_create_handler (
247248 app : State < RouterState > ,
248249 Path ( project_id) : Path < String > ,
249- SessionUser ( user) : SessionUser ,
250+ Auth ( user) : Auth ,
250251 Json ( project) : Json < CreateProjectRequest > ,
251252) -> ApiResult < impl IntoApiResponse > {
252253 if user. role != UserRole :: Admin {
@@ -271,7 +272,7 @@ async fn project_create_handler(
271272async fn project_update_handler (
272273 app : State < RouterState > ,
273274 Path ( project_id) : Path < String > ,
274- SessionUser ( user) : SessionUser ,
275+ Auth ( user) : Auth ,
275276 Json ( req) : Json < UpdateProjectRequest > ,
276277) -> ApiResult < impl IntoApiResponse > {
277278 if user. role != UserRole :: Admin {
@@ -300,7 +301,7 @@ async fn project_update_handler(
300301
301302async fn projects_handler (
302303 app : State < RouterState > ,
303- MaybeExtract ( user) : MaybeExtract < SessionUser > ,
304+ MaybeAuth ( user) : MaybeAuth ,
304305) -> ApiResult < UseApi < impl IntoApiResponse , Json < ProjectsResponse > > > {
305306 let projects = app. projects . all ( ) . http_err ( "Failed to get projects" , StatusCode :: INTERNAL_SERVER_ERROR ) ?;
306307 let projects: Vec < Project > = projects. into_iter ( ) . filter ( |p| can_access_project ( p, user. as_ref ( ) ) ) . collect ( ) ;
@@ -326,7 +327,7 @@ async fn projects_handler(
326327
327328async fn project_handler (
328329 app : State < RouterState > ,
329- MaybeExtract ( user) : MaybeExtract < SessionUser > ,
330+ MaybeAuth ( user) : MaybeAuth ,
330331 Path ( project_id) : Path < String > ,
331332) -> ApiResult < UseApi < impl IntoApiResponse , Json < ProjectResponse > > > {
332333 let project = app. projects . get ( & project_id) . http_status ( StatusCode :: NOT_FOUND ) ?;
@@ -353,7 +354,7 @@ async fn project_handler(
353354async fn project_delete_handler (
354355 app : State < RouterState > ,
355356 Path ( project_id) : Path < String > ,
356- SessionUser ( user) : SessionUser ,
357+ Auth ( user) : Auth ,
357358) -> ApiResult < impl IntoApiResponse > {
358359 let project = app. projects . get ( & project_id) . http_status ( StatusCode :: NOT_FOUND ) ?;
359360 if user. role != UserRole :: Admin {
@@ -366,7 +367,7 @@ async fn project_delete_handler(
366367
367368async fn entities_handler (
368369 app : State < RouterState > ,
369- SessionUser ( user) : SessionUser ,
370+ Auth ( user) : Auth ,
370371) -> ApiResult < UseApi < impl IntoApiResponse , Json < EntitiesResponse > > > {
371372 if user. role != UserRole :: Admin {
372373 http_bail ! ( StatusCode :: FORBIDDEN , "Forbidden" )
@@ -398,7 +399,7 @@ async fn entities_handler(
398399
399400async fn entity_create_handler (
400401 app : State < RouterState > ,
401- SessionUser ( user) : SessionUser ,
402+ Auth ( user) : Auth ,
402403 Json ( entity) : Json < CreateEntityRequest > ,
403404) -> ApiResult < Json < EntityResponse > > {
404405 if user. role != UserRole :: Admin {
@@ -418,7 +419,7 @@ async fn entity_create_handler(
418419async fn entity_update_handler (
419420 app : State < RouterState > ,
420421 Path ( entity_id) : Path < String > ,
421- SessionUser ( user) : SessionUser ,
422+ Auth ( user) : Auth ,
422423 Json ( entity) : Json < UpdateEntityRequest > ,
423424) -> ApiResult < impl IntoApiResponse > {
424425 if user. role != UserRole :: Admin {
@@ -443,7 +444,7 @@ async fn entity_update_handler(
443444async fn entity_delete_handler (
444445 app : State < RouterState > ,
445446 Path ( entity_id) : Path < String > ,
446- SessionUser ( user) : SessionUser ,
447+ Auth ( user) : Auth ,
447448) -> ApiResult < impl IntoApiResponse > {
448449 if user. role != UserRole :: Admin {
449450 http_bail ! ( StatusCode :: FORBIDDEN , "Forbidden" )
0 commit comments