diff --git a/src/authentication.rs b/src/authentication.rs index 2ae8003..f0f682c 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -107,7 +107,9 @@ impl AuthenticationTokenGranter { ) .unwrap(); - Ok(AuthenticationTokenResponse { token: UserAuthenticationToken::from(token) }) + Ok(AuthenticationTokenResponse { + token: UserAuthenticationToken::from(token), + }) } pub async fn extension_request( diff --git a/src/backend/git.rs b/src/backend/git.rs index a95b312..e83bfd1 100644 --- a/src/backend/git.rs +++ b/src/backend/git.rs @@ -262,8 +262,7 @@ impl RepositoryBackend for GitBackend { error!("Failed creating repository on disk!? {:?}", err); // Delete repository from database - self - .delete_by_owner_user_name(&request.owner, request.name.as_str()) + self.delete_by_owner_user_name(&request.owner, request.name.as_str()) .await?; // ??? @@ -441,6 +440,7 @@ impl RepositoryBackend for GitBackend { async fn repositories_for_user( &mut self, + requester: Option<&User>, user: &User, ) -> Result, Error> { let mut repositories = sqlx::query_as!( @@ -453,18 +453,25 @@ impl RepositoryBackend for GitBackend { let mut result = vec![]; while let Some(Ok(Either::Right(repository))) = repositories.next().await { - result.push(RepositorySummary { - repository: Repository { + // Check if the requesting user is allowed to see the repository + if matches!( + repository.visibility, + RepositoryVisibility::Unlisted | RepositoryVisibility::Private + ) && Some(&repository.owner_user.clone()) != requester + { + result.push(RepositorySummary { + repository: Repository { + owner: repository.owner_user.clone(), + name: repository.name, + instance: self.instance.clone(), + }, owner: repository.owner_user.clone(), - name: repository.name, - instance: self.instance.clone(), - }, - owner: repository.owner_user.clone(), - visibility: repository.visibility, - description: repository.description, - // TODO - last_commit: None, - }); + visibility: repository.visibility, + description: repository.description, + // TODO + last_commit: None, + }); + } } Ok(result) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index a1f0199..44c8a1d 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -6,6 +6,7 @@ pub mod user; use anyhow::Error; use async_trait::async_trait; +use crate::backend::git::GitBackendError; use crate::{ messages::{ authentication::{ @@ -28,7 +29,6 @@ use crate::{ user::User, }, }; -use crate::backend::git::GitBackendError; #[async_trait] pub trait RepositoryBackend: IssuesBackend { @@ -47,8 +47,11 @@ pub trait RepositoryBackend: IssuesBackend { requester: Option<&User>, request: &RepositoryFileInspectRequest, ) -> Result; - async fn repositories_for_user(&mut self, user: &User) - -> Result, Error>; + async fn repositories_for_user( + &mut self, + requester: Option<&User>, + user: &User, + ) -> Result, Error>; } pub trait IssuesBackend { diff --git a/src/connection/repository.rs b/src/connection/repository.rs index 4cbe206..ce4532f 100644 --- a/src/connection/repository.rs +++ b/src/connection/repository.rs @@ -1,5 +1,6 @@ use anyhow::Error; +use crate::backend::git::GitBackendError; use crate::{ messages::repository::{ RepositoryCreateRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, @@ -7,7 +8,6 @@ use crate::{ }, model::authenticated::{AuthenticatedUser, Message, MessageHandler, NetworkMessage, State}, }; -use crate::backend::git::GitBackendError; use super::{wrapper::ConnectionState, HandlerUnhandled}; diff --git a/src/model/authenticated.rs b/src/model/authenticated.rs index 3e0077f..f5f8b5f 100644 --- a/src/model/authenticated.rs +++ b/src/model/authenticated.rs @@ -243,7 +243,11 @@ impl FromMessage for AuthenticatedInstance { .source .iter() .filter_map(|auth| { - if let AuthenticationSource::Instance { instance, signature } = auth { + if let AuthenticationSource::Instance { + instance, + signature, + } = auth + { Some((instance, signature)) } else { None