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

ambee/giterated

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

Implement `FromOperationState` for `AuthenticatedUser` and `AuthenticatedInstance`

Use `AuthenticatedUser` on repository requests so we can filter by privacy. Woohoo! Attempt to filter `UserRepositoriesRequest` responses by visibility to the requester.

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨75dcac3

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨5168⁩ bytes
Raw
1 pub mod discovery;
2 pub mod git;
3 pub mod github;
4 pub mod settings;
5 pub mod user;
6
7 use anyhow::Error;
8 use async_trait::async_trait;
9 use giterated_stack::AuthenticatedUser;
10 use serde_json::Value;
11
12 use crate::backend::git::GitBackendError;
13 use giterated_models::authenticated::UserAuthenticationToken;
14
15 use giterated_models::instance::{
16 AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest,
17 };
18
19 use giterated_models::repository::{
20 Commit, IssueLabel, Repository, RepositoryCommitBeforeRequest, RepositoryDiff,
21 RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest,
22 RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryIssue,
23 RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest,
24 RepositorySummary, RepositoryTreeEntry,
25 };
26 use giterated_models::settings::AnySetting;
27 use giterated_models::user::User;
28 use giterated_models::value::AnyValue;
29
30 #[async_trait]
31 pub trait RepositoryBackend {
32 async fn create_repository(
33 &mut self,
34 user: &AuthenticatedUser,
35 request: &RepositoryCreateRequest,
36 ) -> Result<Repository, GitBackendError>;
37 async fn repository_file_inspect(
38 &mut self,
39 requester: &Option<AuthenticatedUser>,
40 repository: &Repository,
41 request: &RepositoryFileInspectRequest,
42 ) -> Result<Vec<RepositoryTreeEntry>, Error>;
43 async fn repository_file_from_id(
44 &mut self,
45 requester: &Option<AuthenticatedUser>,
46 repository: &Repository,
47 request: &RepositoryFileFromIdRequest,
48 ) -> Result<RepositoryFile, Error>;
49 async fn repository_file_from_path(
50 &mut self,
51 requester: &Option<AuthenticatedUser>,
52 repository: &Repository,
53 request: &RepositoryFileFromPathRequest,
54 ) -> Result<RepositoryFile, Error>;
55 async fn repository_diff(
56 &mut self,
57 requester: &Option<AuthenticatedUser>,
58 repository: &Repository,
59 request: &RepositoryDiffRequest,
60 ) -> Result<RepositoryDiff, Error>;
61 async fn repository_diff_patch(
62 &mut self,
63 requester: &Option<AuthenticatedUser>,
64 repository: &Repository,
65 request: &RepositoryDiffPatchRequest,
66 ) -> Result<String, Error>;
67 async fn repository_commit_before(
68 &mut self,
69 requester: &Option<AuthenticatedUser>,
70 repository: &Repository,
71 request: &RepositoryCommitBeforeRequest,
72 ) -> Result<Commit, Error>;
73 async fn get_value(
74 &mut self,
75 user: &Repository,
76 name: &str,
77 ) -> Result<AnyValue<Repository>, Error>;
78 async fn get_setting(&mut self, user: &Repository, name: &str) -> Result<AnySetting, Error>;
79 async fn write_setting(
80 &mut self,
81 user: &Repository,
82 name: &str,
83 setting: &Value,
84 ) -> Result<(), Error>;
85 async fn exists(
86 &mut self,
87 requester: &Option<AuthenticatedUser>,
88 repository: &Repository,
89 ) -> Result<bool, Error>;
90 }
91
92 pub trait IssuesBackend {
93 fn issues_count(
94 &mut self,
95 requester: &Option<AuthenticatedUser>,
96 request: &RepositoryIssuesCountRequest,
97 ) -> Result<u64, Error>;
98 fn issue_labels(
99 &mut self,
100 requester: &Option<AuthenticatedUser>,
101 request: &RepositoryIssueLabelsRequest,
102 ) -> Result<Vec<IssueLabel>, Error>;
103 fn issues(
104 &mut self,
105 requester: &Option<AuthenticatedUser>,
106 request: &RepositoryIssuesRequest,
107 ) -> Result<Vec<RepositoryIssue>, Error>;
108 }
109
110 #[async_trait::async_trait]
111 pub trait AuthBackend {
112 async fn register(
113 &mut self,
114 request: RegisterAccountRequest,
115 ) -> Result<UserAuthenticationToken, Error>;
116
117 async fn login(
118 &mut self,
119 source: &Instance,
120 request: AuthenticationTokenRequest,
121 ) -> Result<UserAuthenticationToken, Error>;
122 }
123
124 #[async_trait::async_trait]
125 pub trait UserBackend: AuthBackend {
126 async fn get_value(&mut self, user: &User, name: &str) -> Result<AnyValue<User>, Error>;
127 async fn get_setting(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
128 async fn write_setting(
129 &mut self,
130 user: &User,
131 name: &str,
132 setting: &Value,
133 ) -> Result<(), Error>;
134 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
135 async fn repositories_for_user(
136 &mut self,
137 requester: &Option<AuthenticatedUser>,
138 user: &User,
139 ) -> Result<Vec<RepositorySummary>, Error>;
140 }
141
142 #[async_trait::async_trait]
143 pub trait MetadataBackend {
144 async fn user_get(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
145 async fn user_write(
146 &mut self,
147 user: &User,
148 name: &str,
149 setting: AnySetting,
150 ) -> Result<(), Error>;
151 async fn repository_get(
152 &mut self,
153 repository: &Repository,
154 name: &str,
155 ) -> Result<AnySetting, Error>;
156 async fn repository_write(
157 &mut self,
158 repository: &Repository,
159 name: &str,
160 setting: AnySetting,
161 ) -> Result<(), Error>;
162 }
163