JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Unified stack `GetValue` implementation

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨325f5af

⁨giterated-daemon/src/authorization.rs⁩ - ⁨3687⁩ bytes
Raw
1 use std::fmt::Debug;
2
3 use crate::connection::wrapper::ConnectionState;
4 use giterated_models::error::OperationError;
5
6 use giterated_models::object::GiteratedObject;
7
8 use giterated_models::repository::{
9 Repository, RepositoryFileInspectRequest, RepositoryIssueLabelsRequest,
10 RepositoryIssuesCountRequest, RepositoryIssuesRequest,
11 };
12
13 use giterated_models::user::User;
14
15 use giterated_models::value::GetValueTyped;
16 use giterated_models::{object::ObjectRequest, settings::SetSetting, value::GiteratedObjectValue};
17 #[async_trait::async_trait]
18 pub trait AuthorizedOperation<O: GiteratedObject, S> {
19 /// Authorizes the operation, returning whether the operation was
20 /// authorized or not.
21 async fn authorize(
22 &self,
23 authenticating_user: Option<&User>,
24 object: &O,
25 state: &mut S,
26 ) -> Result<bool, OperationError<()>>;
27 }
28
29 #[async_trait::async_trait]
30 impl AuthorizedOperation<User, ConnectionState> for SetSetting {
31 async fn authorize(
32 &self,
33 _authenticating_user: Option<&User>,
34 _object: &User,
35 _state: &mut ConnectionState,
36 ) -> Result<bool, OperationError<()>> {
37 // TODO
38 Ok(true)
39 }
40 }
41
42 #[async_trait::async_trait]
43 impl AuthorizedOperation<Repository, ConnectionState> for SetSetting {
44 async fn authorize(
45 &self,
46 _authenticating_user: Option<&User>,
47 _object: &Repository,
48 _state: &mut ConnectionState,
49 ) -> Result<bool, OperationError<()>> {
50 // TODO
51 Ok(true)
52 }
53 }
54
55 #[async_trait::async_trait]
56 impl<V: GiteratedObjectValue + Send + Sync + Debug + Clone>
57 AuthorizedOperation<Repository, ConnectionState> for GetValueTyped<V>
58 {
59 async fn authorize(
60 &self,
61 _authenticating_user: Option<&User>,
62 _object: &Repository,
63 _state: &mut ConnectionState,
64 ) -> Result<bool, OperationError<()>> {
65 // TODO
66 Ok(true)
67 }
68 }
69
70 #[async_trait::async_trait]
71 impl AuthorizedOperation<Repository, ConnectionState> for ObjectRequest {
72 async fn authorize(
73 &self,
74 _authenticating_user: Option<&User>,
75 _object: &Repository,
76 _state: &mut ConnectionState,
77 ) -> Result<bool, OperationError<()>> {
78 // TODO
79 Ok(true)
80 }
81 }
82
83 #[async_trait::async_trait]
84 impl AuthorizedOperation<Repository, ConnectionState> for RepositoryFileInspectRequest {
85 async fn authorize(
86 &self,
87 _authenticating_user: Option<&User>,
88 _object: &Repository,
89 _state: &mut ConnectionState,
90 ) -> Result<bool, OperationError<()>> {
91 // TODO
92 Ok(true)
93 }
94 }
95
96 #[async_trait::async_trait]
97 impl AuthorizedOperation<Repository, ConnectionState> for RepositoryIssuesRequest {
98 async fn authorize(
99 &self,
100 _authenticating_user: Option<&User>,
101 _object: &Repository,
102 _state: &mut ConnectionState,
103 ) -> Result<bool, OperationError<()>> {
104 // TODO
105 Ok(true)
106 }
107 }
108
109 #[async_trait::async_trait]
110 impl AuthorizedOperation<Repository, ConnectionState> for RepositoryIssueLabelsRequest {
111 async fn authorize(
112 &self,
113 _authenticating_user: Option<&User>,
114 _object: &Repository,
115 _state: &mut ConnectionState,
116 ) -> Result<bool, OperationError<()>> {
117 // TODO
118 Ok(true)
119 }
120 }
121
122 #[async_trait::async_trait]
123 impl AuthorizedOperation<Repository, ConnectionState> for RepositoryIssuesCountRequest {
124 async fn authorize(
125 &self,
126 _authenticating_user: Option<&User>,
127 _object: &Repository,
128 _state: &mut ConnectionState,
129 ) -> Result<bool, OperationError<()>> {
130 // TODO
131 Ok(true)
132 }
133 }
134