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:
parent
bf94ec33de
commit
b0000c0117
18 changed files with 252 additions and 217 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use service::{slot::Slot, ServiceError, ValidationFailureItem};
|
||||
use service::{permission::Authentication, slot::Slot, ServiceError, ValidationFailureItem};
|
||||
use tokio::join;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ where
|
|||
{
|
||||
type Context = PermissionService::Context;
|
||||
|
||||
async fn get_slots(&self, context: Self::Context) -> Result<Arc<[Slot]>, ServiceError> {
|
||||
async fn get_slots(&self, context: Authentication<Self::Context>) -> Result<Arc<[Slot]>, ServiceError> {
|
||||
let (hr_permission, sales_permission) = join!(
|
||||
self.permission_service
|
||||
.check_permission("hr", context.clone()),
|
||||
|
|
@ -76,7 +76,7 @@ where
|
|||
.map(Slot::from)
|
||||
.collect())
|
||||
}
|
||||
async fn get_slot(&self, id: &Uuid, context: Self::Context) -> Result<Slot, ServiceError> {
|
||||
async fn get_slot(&self, id: &Uuid, context: Authentication<Self::Context>) -> Result<Slot, ServiceError> {
|
||||
let (hr_permission, sales_permission) = join!(
|
||||
self.permission_service
|
||||
.check_permission("hr", context.clone()),
|
||||
|
|
@ -92,11 +92,11 @@ where
|
|||
Ok(slot)
|
||||
}
|
||||
|
||||
async fn exists(&self, id: Uuid, _context: Self::Context) -> Result<bool, ServiceError> {
|
||||
async fn exists(&self, id: Uuid, _context: Authentication<Self::Context>) -> Result<bool, ServiceError> {
|
||||
Ok(self.slot_dao.get_slot(&id).await.map(|s| s.is_some())?)
|
||||
}
|
||||
|
||||
async fn create_slot(&self, slot: &Slot, context: Self::Context) -> Result<Slot, ServiceError> {
|
||||
async fn create_slot(&self, slot: &Slot, context: Authentication<Self::Context>) -> Result<Slot, ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context.clone())
|
||||
.await?;
|
||||
|
|
@ -137,7 +137,7 @@ where
|
|||
Ok(slot)
|
||||
}
|
||||
|
||||
async fn delete_slot(&self, id: &Uuid, context: Self::Context) -> Result<(), ServiceError> {
|
||||
async fn delete_slot(&self, id: &Uuid, context: Authentication<Self::Context>) -> Result<(), ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
|
|
@ -152,7 +152,7 @@ where
|
|||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
async fn update_slot(&self, slot: &Slot, context: Self::Context) -> Result<(), ServiceError> {
|
||||
async fn update_slot(&self, slot: &Slot, context: Authentication<Self::Context>) -> Result<(), ServiceError> {
|
||||
self.permission_service
|
||||
.check_permission("hr", context)
|
||||
.await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue