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

ambee/giterated

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

Add repository setings

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨3b20354

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