potree_auth/project_asset/application/
error.rs1use std::path::PathBuf;
2
3use super::super::ports::project_asset_store::ProjectAssetStoreError;
4use crate::authorization::domain::action::Action;
5use crate::authorization::domain::error::AuthorizationEngineError;
6use crate::authorization::domain::resource::ResourceIdentifier;
7use crate::authorization::domain::resource::ResourceType;
8use crate::project::domain::ProjectId;
9use crate::project::ports::project_repository::ProjectRepositoryError;
10use crate::user::domain::User;
11
12#[derive(Debug, thiserror::Error)]
13pub enum ProjectAssetsServiceError {
14 #[error("project ({id}) not found")]
15 ProjectNotFound { id: ProjectId },
16
17 #[error("{} is not authorized to {} the {:?}: {:?}", user.name, action, resource_type, resource_identifier)]
18 NotAuthorized {
19 user: Box<User>,
20 action: Action,
21 resource_identifier: Option<ResourceIdentifier>,
22 resource_type: ResourceType,
23 },
24
25 #[error("user is not authenticated")]
26 NotAuthenticated,
27
28 #[error("the asset ({path}) could not be found")]
29 AssetNotFound { path: PathBuf },
30
31 #[error("{message}")]
32 Infrastucture { message: String },
33}
34
35impl From<ProjectRepositoryError> for ProjectAssetsServiceError {
36 fn from(value: ProjectRepositoryError) -> Self {
37 match value {
38 ProjectRepositoryError::ResourceNotFound { id }
39 | ProjectRepositoryError::Parsing { id } => Self::ProjectNotFound { id },
40 ProjectRepositoryError::Infrastucture { message } => Self::Infrastucture { message },
41 }
42 }
43}
44
45impl From<ProjectAssetStoreError> for ProjectAssetsServiceError {
46 fn from(value: ProjectAssetStoreError) -> Self {
47 match value {
48 ProjectAssetStoreError::AssetNotFound { path }
49 | ProjectAssetStoreError::Parsing { path } => Self::AssetNotFound { path },
50 }
51 }
52}
53
54impl From<AuthorizationEngineError> for ProjectAssetsServiceError {
55 fn from(value: AuthorizationEngineError) -> Self {
56 match value {
57 AuthorizationEngineError::NotAuthorized {
58 user,
59 action,
60 resource_identifier,
61 resource_type,
62 } => Self::NotAuthorized {
63 user,
64 action,
65 resource_identifier,
66 resource_type,
67 },
68 AuthorizationEngineError::NotAuthenticated => Self::NotAuthenticated,
69 }
70 }
71}