Wrap Context with Autentication enum

Context should contain information which is required to get
the information if the service call is authenticated.  Context
could be the username for example.  But services call other
services internally and for this, authentication must not be
checked.  In this case, they can now pass Authentication::Full
which always successfully authenticates.
This commit is contained in:
Simon Goller 2024-05-09 14:58:19 +02:00
parent bf94ec33de
commit b0000c0117
18 changed files with 252 additions and 217 deletions

View file

@ -70,7 +70,7 @@ pub async fn get_all_bookings<RestState: RestStateDef>(rest_state: State<RestSta
(async {
let bookings: Arc<[BookingTO]> = rest_state
.booking_service()
.get_all(())
.get_all(().into())
.await?
.iter()
.map(BookingTO::from)
@ -90,7 +90,7 @@ pub async fn get_booking<RestState: RestStateDef>(
) -> Response {
error_handler(
(async {
let booking = rest_state.booking_service().get(booking_id, ()).await?;
let booking = rest_state.booking_service().get(booking_id, ().into()).await?;
Ok(Response::builder()
.status(200)
.body(Body::new(
@ -110,7 +110,7 @@ pub async fn create_booking<RestState: RestStateDef>(
(async {
let booking = rest_state
.booking_service()
.create(&Booking::from(&booking), ())
.create(&Booking::from(&booking), ().into())
.await?;
Ok(Response::builder()
.status(200)
@ -129,7 +129,7 @@ pub async fn delete_booking<RestState: RestStateDef>(
) -> Response {
error_handler(
(async {
rest_state.booking_service().delete(booking_id, ()).await?;
rest_state.booking_service().delete(booking_id, ().into()).await?;
Ok(Response::builder().status(200).body(Body::empty()).unwrap())
})
.await,

View file

@ -87,7 +87,7 @@ pub async fn add_user<RestState: RestStateDef>(
(async {
rest_state
.permission_service()
.create_user(user.name.as_str(), ())
.create_user(user.name.as_str(), ().into())
.await?;
Ok(Response::builder()
.status(201)
@ -107,7 +107,7 @@ pub async fn remove_user<RestState: RestStateDef>(
(async {
rest_state
.permission_service()
.delete_user(&user, ())
.delete_user(&user, ().into())
.await?;
Ok(Response::builder()
.status(200)
@ -126,7 +126,7 @@ pub async fn add_role<RestState: RestStateDef>(
(async {
rest_state
.permission_service()
.create_role(role.name.as_str(), ())
.create_role(role.name.as_str(), ().into())
.await?;
Ok(Response::builder()
.status(200)
@ -145,7 +145,7 @@ pub async fn delete_role<RestState: RestStateDef>(
(async {
rest_state
.permission_service()
.delete_role(role.as_str(), ())
.delete_role(role.as_str(), ().into())
.await?;
Ok(Response::builder()
.status(200)
@ -164,7 +164,7 @@ pub async fn add_user_role<RestState: RestStateDef>(
(async {
rest_state
.permission_service()
.add_user_role(user_role.user.as_str(), user_role.role.as_str(), ())
.add_user_role(user_role.user.as_str(), user_role.role.as_str(), ().into())
.await?;
Ok(Response::builder()
.status(201)
@ -183,7 +183,7 @@ pub async fn remove_user_role<RestState: RestStateDef>(
(async {
rest_state
.permission_service()
.delete_user_role(user_role.user.as_str(), user_role.role.as_str(), ())
.delete_user_role(user_role.user.as_str(), user_role.role.as_str(), ().into())
.await?;
Ok(Response::builder()
.status(200)
@ -205,7 +205,7 @@ pub async fn add_role_privilege<RestState: RestStateDef>(
.add_role_privilege(
role_privilege.role.as_str(),
role_privilege.privilege.as_str(),
(),
().into(),
)
.await?;
Ok(Response::builder()
@ -228,7 +228,7 @@ pub async fn remove_role_privilege<RestState: RestStateDef>(
.delete_role_privilege(
role_privilege.role.as_str(),
role_privilege.privilege.as_str(),
(),
().into(),
)
.await?;
Ok(Response::builder()
@ -245,7 +245,7 @@ pub async fn get_all_users<RestState: RestStateDef>(rest_state: State<RestState>
(async {
let users: Arc<[UserTO]> = rest_state
.permission_service()
.get_all_users(())
.get_all_users(().into())
.await?
.iter()
.map(UserTO::from)
@ -264,7 +264,7 @@ pub async fn get_all_roles<RestState: RestStateDef>(rest_state: State<RestState>
(async {
let roles: Arc<[RoleTO]> = rest_state
.permission_service()
.get_all_roles(())
.get_all_roles(().into())
.await?
.iter()
.map(RoleTO::from)
@ -283,7 +283,7 @@ pub async fn get_all_privileges<RestState: RestStateDef>(rest_state: State<RestS
(async {
let privileges: Arc<[PrivilegeTO]> = rest_state
.permission_service()
.get_all_privileges(())
.get_all_privileges(().into())
.await?
.iter()
.map(PrivilegeTO::from)

View file

@ -67,7 +67,7 @@ pub async fn get_all_sales_persons<RestState: RestStateDef>(
(async {
let sales_persons: Arc<[SalesPersonTO]> = rest_state
.sales_person_service()
.get_all(())
.get_all(().into())
.await?
.iter()
.map(SalesPersonTO::from)
@ -90,7 +90,7 @@ pub async fn get_sales_person<RestState: RestStateDef>(
let sales_person = SalesPersonTO::from(
&rest_state
.sales_person_service()
.get(sales_person_id, ())
.get(sales_person_id, ().into())
.await?,
);
Ok(Response::builder()
@ -111,7 +111,7 @@ pub async fn create_sales_person<RestState: RestStateDef>(
let sales_person = SalesPersonTO::from(
&rest_state
.sales_person_service()
.create(&(&sales_person).into(), ())
.create(&(&sales_person).into(), ().into())
.await?,
);
Ok(Response::builder()
@ -135,7 +135,7 @@ pub async fn update_sales_person<RestState: RestStateDef>(
}
rest_state
.sales_person_service()
.update(&(&sales_person).into(), ())
.update(&(&sales_person).into(), ().into())
.await?;
Ok(Response::builder()
.status(200)
@ -154,7 +154,7 @@ pub async fn delete_sales_person<RestState: RestStateDef>(
(async {
rest_state
.sales_person_service()
.delete(sales_person_id, ())
.delete(sales_person_id, ().into())
.await?;
Ok(Response::builder().status(204).body(Body::empty()).unwrap())
})
@ -171,7 +171,7 @@ pub async fn get_sales_person_user<RestState: RestStateDef>(
(async {
let user = rest_state
.sales_person_service()
.get_assigned_user(sales_person_id, ())
.get_assigned_user(sales_person_id, ().into())
.await?;
Ok(Response::builder()
.status(200)
@ -191,7 +191,7 @@ pub async fn set_sales_person_user<RestState: RestStateDef>(
(async {
rest_state
.sales_person_service()
.set_user(sales_person_id, user.into(), ())
.set_user(sales_person_id, user.into(), ().into())
.await?;
Ok(Response::builder().status(204).body(Body::empty()).unwrap())
})
@ -207,7 +207,7 @@ pub async fn delete_sales_person_user<RestState: RestStateDef>(
(async {
rest_state
.sales_person_service()
.set_user(sales_person_id, None, ())
.set_user(sales_person_id, None, ().into())
.await?;
Ok(Response::builder().status(204).body(Body::empty()).unwrap())
})

View file

@ -107,7 +107,7 @@ pub async fn get_all_slots<RestState: RestStateDef>(rest_state: State<RestState>
(async {
let slots: Arc<[SlotTO]> = rest_state
.slot_service()
.get_slots(())
.get_slots(().into())
.await?
.iter()
.map(SlotTO::from)
@ -127,7 +127,7 @@ pub async fn get_slot<RestState: RestStateDef>(
) -> Response {
error_handler(
(async {
let slot = SlotTO::from(&rest_state.slot_service().get_slot(&slot_id, ()).await?);
let slot = SlotTO::from(&rest_state.slot_service().get_slot(&slot_id, ().into()).await?);
Ok(Response::builder()
.status(200)
.body(Body::new(serde_json::to_string(&slot).unwrap()))
@ -146,7 +146,7 @@ pub async fn create_slot<RestState: RestStateDef>(
let slot = SlotTO::from(
&rest_state
.slot_service()
.create_slot(&(&slot).into(), ())
.create_slot(&(&slot).into(), ().into())
.await?,
);
Ok(Response::builder()
@ -170,7 +170,7 @@ pub async fn update_slot<RestState: RestStateDef>(
}
rest_state
.slot_service()
.update_slot(&(&slot).into(), ())
.update_slot(&(&slot).into(), ().into())
.await?;
Ok(Response::builder()
.status(200)