Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete team and app #215

Merged
merged 9 commits into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed
dzlk17 committed Oct 14, 2024
commit 54d14928e08d2c1c0ee0058931d43bf006e8eae6
16 changes: 13 additions & 3 deletions server/src/http/cloud/accept_team_invite.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@ use super::{
utils::{custom_validate_team_id, validate_request},
};
use crate::{
middlewares::auth_middleware::UserId, structs::cloud::api_cloud_errors::CloudApiErrors,
env::is_env_production, middlewares::auth_middleware::UserId,
structs::cloud::api_cloud_errors::CloudApiErrors,
};
use axum::{extract::State, http::StatusCode, Extension, Json};
use database::db::Db;
@@ -101,8 +102,17 @@ pub async fn accept_team_invite(
}

// Grafana add user to the team
handle_grafana_add_user_to_team(&grafana_conf, &request.team_id, &user.email).await?;

if is_env_production() {
if let Err(err) =
handle_grafana_add_user_to_team(&grafana_conf, &request.team_id, &user.email).await
{
error!("Failed to add user to the team in grafana: {:?}", err);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
CloudApiErrors::GrafanaError.to_string(),
));
};
}
// Accept invite
let mut tx = match db.connection_pool.begin().await {
Ok(tx) => tx,
15 changes: 6 additions & 9 deletions server/src/http/cloud/delete_app.rs
Original file line number Diff line number Diff line change
@@ -114,15 +114,12 @@ pub async fn delete_app(
// Grafana, delete app
// TODO, fix this by fixing methods for setting up grafana datasource
if is_env_production() {
match handle_grafana_delete_app(&grafana_conf, &request.app_id).await {
Ok(_) => {}
Err(err) => {
error!("Failed to delete app from grafana: {:?}", err);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
CloudApiErrors::GrafanaError.to_string(),
));
}
if let Err(err) = handle_grafana_delete_app(&grafana_conf, &request.app_id).await {
error!("Failed to delete app from grafana: {:?}", err);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
CloudApiErrors::GrafanaError.to_string(),
));
}
}

17 changes: 7 additions & 10 deletions server/src/http/cloud/delete_team.rs
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ pub async fn delete_team(
Ok(None) => {
return Err((
StatusCode::BAD_REQUEST,
CloudApiErrors::AppDoesNotExist.to_string(),
CloudApiErrors::TeamDoesNotExist.to_string(),
));
}
Err(err) => {
@@ -153,15 +153,12 @@ pub async fn delete_team(
// Grafana, delete team
// TODO, fix this by fixing methods for setting up grafana datasource
if is_env_production() {
match handle_grafana_delete_team(&grafana_conf, &request.team_id).await {
Ok(_) => {}
Err(err) => {
error!("Failed to delete team from grafana: {:?}", err);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
CloudApiErrors::GrafanaError.to_string(),
));
}
if let Err(err) = handle_grafana_delete_team(&grafana_conf, &request.team_id).await {
error!("Failed to delete team from grafana: {:?}", err);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
CloudApiErrors::GrafanaError.to_string(),
));
};
}

19 changes: 16 additions & 3 deletions server/src/http/cloud/leave_team.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ use super::{
utils::{custom_validate_team_id, validate_request},
};
use crate::{
env::is_env_production,
mailer::{
mail_requests::{SendEmailRequest, TeamLeavingNotification},
mailer::Mailer,
@@ -104,9 +105,21 @@ pub async fn leave_team(
}

// Grafana, remove user from the team
handle_grafana_remove_user_from_team(&grafana_conf, &request.team_id, &user.email)
.await?;

if is_env_production() {
if let Err(err) = handle_grafana_remove_user_from_team(
&grafana_conf,
&request.team_id,
&user.email,
)
.await
{
error!("Grafana, failed to left the team: {:?}", err);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
CloudApiErrors::GrafanaError.to_string(),
));
};
}
// Remove user from the team
if let Err(err) = db
.remove_user_from_the_team(&user_id, &request.team_id)
11 changes: 9 additions & 2 deletions server/src/http/cloud/register_new_app.rs
Original file line number Diff line number Diff line change
@@ -112,13 +112,20 @@ pub async fn register_new_app(
// Grafana, add new app
// TODO, fix this by fixing methods for setting up grafana datasource
if is_env_production() {
handle_grafana_create_new_app(
if let Err(err) = handle_grafana_create_new_app(
&grafana_conf,
&request.app_name,
&app_id,
&team.team_id,
)
.await?;
.await
{
error!("Failed to create new app in grafana: {:?}", err);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
CloudApiErrors::GrafanaError.to_string(),
));
};
}

// Register a new app under this team
27 changes: 21 additions & 6 deletions server/src/http/cloud/register_new_team.rs
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ use super::{
utils::{custom_validate_name, validate_request},
};
use crate::{
middlewares::auth_middleware::UserId, statics::TEAMS_AMOUNT_LIMIT_PER_USER,
structs::cloud::api_cloud_errors::CloudApiErrors,
env::is_env_production, middlewares::auth_middleware::UserId,
statics::TEAMS_AMOUNT_LIMIT_PER_USER, structs::cloud::api_cloud_errors::CloudApiErrors,
};
use axum::{extract::State, http::StatusCode, Extension, Json};
use database::{
@@ -121,11 +121,26 @@ pub async fn register_new_team(
));
}
};

let mut grafana_team_id: i64 = 0;
// Grafana, add new team
let grafana_team_id =
handle_grafana_create_new_team(&grafana_conf, &admin_email, &request.team_name)
.await?;
if is_env_production() {
grafana_team_id = match handle_grafana_create_new_team(
&grafana_conf,
&admin_email,
&request.team_name,
)
.await
{
Ok(id) => id,
Err(err) => {
error!("Failed to create team in grafana: {:?}", err);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
CloudApiErrors::GrafanaError.to_string(),
));
}
}
}

// Create a new team
let team = Team {
23 changes: 16 additions & 7 deletions server/src/http/cloud/remove_user_from_team.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ use super::{
utils::{custom_validate_team_id, validate_request},
};
use crate::{
env::is_env_production,
mailer::{
mail_requests::{SendEmailRequest, TeamRemovalNotification},
mailer::Mailer,
@@ -106,13 +107,21 @@ pub async fn remove_user_from_team(
}

// Grafana, remove user from the team
handle_grafana_remove_user_from_team(
&grafana_conf,
&request.team_id,
&request.user_email,
)
.await?;

if is_env_production() {
if let Err(err) = handle_grafana_remove_user_from_team(
&grafana_conf,
&request.team_id,
&request.user_email,
)
.await
{
error!("Failed to remove user from the team in grafana: {:?}", err);
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
CloudApiErrors::GrafanaError.to_string(),
));
};
}
// Remove user from the team
if let Err(err) = db
.remove_user_from_the_team(&user.user_id, &request.team_id)