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

ambee/giterated

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

Unified stack refactor clean up

Clean up obsolete code and some warnings

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨356f714

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