Skip to content

Commit

Permalink
refactor: implement permission dal when behind an arc (#1784)
Browse files Browse the repository at this point in the history
  • Loading branch information
chesedo authored May 24, 2024
1 parent e5b20d7 commit 5d2311b
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions backends/src/client/permit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
fmt::{Debug, Display},
str::FromStr,
sync::Arc,
};

use async_trait::async_trait;
Expand Down Expand Up @@ -131,6 +132,123 @@ pub trait PermissionsDal {
async fn get_project_owner(&self, user_id: &str, project_id: &str) -> Result<Owner>;
}

#[async_trait]
impl<T> PermissionsDal for Arc<T>
where
T: PermissionsDal + Send + Sync,
{
async fn get_user(&self, user_id: &str) -> Result<UserRead> {
self.get_user(user_id).await
}

async fn delete_user(&self, user_id: &str) -> Result<()> {
self.delete_user(user_id).await
}

async fn new_user(&self, user_id: &str) -> Result<UserRead> {
self.new_user(user_id).await
}

async fn make_pro(&self, user_id: &str) -> Result<()> {
self.make_pro(user_id).await
}

async fn make_basic(&self, user_id: &str) -> Result<()> {
self.make_basic(user_id).await
}

async fn create_project(&self, user_id: &str, project_id: &str) -> Result<()> {
self.create_project(user_id, project_id).await
}

async fn delete_project(&self, project_id: &str) -> Result<()> {
self.delete_project(project_id).await
}

async fn get_personal_projects(&self, user_id: &str) -> Result<Vec<String>> {
self.get_personal_projects(user_id).await
}

async fn create_team(&self, user_id: &str, team: &Team) -> Result<()> {
self.create_team(user_id, team).await
}

async fn delete_team(&self, user_id: &str, team_id: &str) -> Result<()> {
self.delete_team(user_id, team_id).await
}

async fn get_team(&self, user_id: &str, team_id: &str) -> Result<team::Response> {
self.get_team(user_id, team_id).await
}

async fn get_teams(&self, user_id: &str) -> Result<Vec<team::Response>> {
self.get_teams(user_id).await
}

async fn get_team_projects(&self, user_id: &str, team_id: &str) -> Result<Vec<String>> {
self.get_team_projects(user_id, team_id).await
}

async fn transfer_project_to_user(
&self,
user_id: &str,
project_id: &str,
new_user_id: &str,
) -> Result<()> {
self.transfer_project_to_user(user_id, project_id, new_user_id)
.await
}

async fn transfer_project_to_team(
&self,
user_id: &str,
project_id: &str,
team_id: &str,
) -> Result<()> {
self.transfer_project_to_team(user_id, project_id, team_id)
.await
}

async fn transfer_project_from_team(
&self,
user_id: &str,
project_id: &str,
team_id: &str,
) -> Result<()> {
self.transfer_project_from_team(user_id, project_id, team_id)
.await
}

async fn add_team_member(&self, admin_user: &str, team_id: &str, user_id: &str) -> Result<()> {
self.add_team_member(admin_user, team_id, user_id).await
}

async fn remove_team_member(
&self,
admin_user: &str,
team_id: &str,
user_id: &str,
) -> Result<()> {
self.remove_team_member(admin_user, team_id, user_id).await
}

async fn get_team_members(
&self,
user_id: &str,
team_id: &str,
) -> Result<Vec<team::MemberResponse>> {
self.get_team_members(user_id, team_id).await
}

async fn allowed(&self, user_id: &str, project_id: &str, action: &str) -> Result<bool> {
self.allowed(user_id, project_id, action).await
}

async fn get_project_owner(&self, user_id: &str, project_id: &str) -> Result<Owner> {
self.get_project_owner(user_id, project_id).await
}
}

/// Simple details of a team to create
#[derive(Debug, PartialEq)]
pub struct Team {
Expand Down

0 comments on commit 5d2311b

Please sign in to comment.