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

ambee/giterated

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

Check if requesting user is allowed to see the repository

Type: Fix

emilia - ⁨2⁩ years ago

parent: tbd commit: ⁨1b40c1d

⁨src/backend/mod.rs⁩ - ⁨3161⁩ bytes
Raw
1 pub mod discovery;
2 pub mod git;
3 pub mod github;
4 pub mod user;
5
6 use anyhow::Error;
7 use async_trait::async_trait;
8
9 use crate::backend::git::GitBackendError;
10 use crate::{
11 messages::{
12 authentication::{
13 AuthenticationTokenRequest, AuthenticationTokenResponse, RegisterAccountRequest,
14 RegisterAccountResponse,
15 },
16 repository::{
17 RepositoryCreateRequest, RepositoryCreateResponse, RepositoryFileInspectRequest,
18 RepositoryFileInspectionResponse, RepositoryInfoRequest, RepositoryIssueLabelsRequest,
19 RepositoryIssueLabelsResponse, RepositoryIssuesCountRequest,
20 RepositoryIssuesCountResponse, RepositoryIssuesRequest, RepositoryIssuesResponse,
21 },
22 user::{
23 UserBioRequest, UserBioResponse, UserDisplayImageRequest, UserDisplayImageResponse,
24 UserDisplayNameRequest, UserDisplayNameResponse,
25 },
26 },
27 model::{
28 repository::{RepositorySummary, RepositoryView},
29 user::User,
30 },
31 };
32
33 #[async_trait]
34 pub trait RepositoryBackend: IssuesBackend {
35 async fn create_repository(
36 &mut self,
37 user: &User,
38 request: &RepositoryCreateRequest,
39 ) -> Result<RepositoryCreateResponse, GitBackendError>;
40 async fn repository_info(
41 &mut self,
42 requester: Option<&User>,
43 request: &RepositoryInfoRequest,
44 ) -> Result<RepositoryView, Error>;
45 async fn repository_file_inspect(
46 &mut self,
47 requester: Option<&User>,
48 request: &RepositoryFileInspectRequest,
49 ) -> Result<RepositoryFileInspectionResponse, Error>;
50 async fn repositories_for_user(
51 &mut self,
52 requester: Option<&User>,
53 user: &User,
54 ) -> Result<Vec<RepositorySummary>, Error>;
55 }
56
57 pub trait IssuesBackend {
58 fn issues_count(
59 &mut self,
60 requester: Option<&User>,
61 request: &RepositoryIssuesCountRequest,
62 ) -> Result<RepositoryIssuesCountResponse, Error>;
63 fn issue_labels(
64 &mut self,
65 requester: Option<&User>,
66 request: &RepositoryIssueLabelsRequest,
67 ) -> Result<RepositoryIssueLabelsResponse, Error>;
68 fn issues(
69 &mut self,
70 requester: Option<&User>,
71 request: &RepositoryIssuesRequest,
72 ) -> Result<RepositoryIssuesResponse, Error>;
73 }
74
75 #[async_trait::async_trait]
76 pub trait AuthBackend {
77 async fn register(
78 &mut self,
79 request: RegisterAccountRequest,
80 ) -> Result<RegisterAccountResponse, Error>;
81
82 async fn login(
83 &mut self,
84 request: AuthenticationTokenRequest,
85 ) -> Result<AuthenticationTokenResponse, Error>;
86 }
87
88 #[async_trait::async_trait]
89 pub trait UserBackend: AuthBackend {
90 async fn display_name(
91 &mut self,
92 request: UserDisplayNameRequest,
93 ) -> Result<UserDisplayNameResponse, Error>;
94
95 async fn display_image(
96 &mut self,
97 request: UserDisplayImageRequest,
98 ) -> Result<UserDisplayImageResponse, Error>;
99
100 async fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Error>;
101 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
102 }
103