Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
65 changes: 33 additions & 32 deletions src/routes/groups/{group_id}/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

use std::sync::Arc;
use axum::{Extension, Json, Router, extract::{Path, State}};
use reqwest::StatusCode;
use crate::{
AppState,
HTTPError,
middleware::{authentication_middleware, http_request_middleware},
resources::{
access_policy::{AccessPolicyResourceType, ActionPermissionLevel}, action_log_entry::{ActionLogEntry, ActionLogEntryActorType, ActionLogEntryTargetResourceType, InitialActionLogEntryProperties}, app::App, app_authorization::AppAuthorization, group::Group, http_transaction::HTTPTransaction, server_log_entry::ServerLogEntry, user::User
},
utilities::route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_group_by_id, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}
utilities::{reusable_route_handlers::delete_resource, route_handler_utilities::{AuthenticatedPrincipal, get_action_by_name, get_action_log_entry_expiration_timestamp, get_authenticated_principal, get_group_by_id, get_resource_hierarchy, get_uuid_from_string, verify_delegate_permissions, verify_principal_permissions}}
};

// #[path = "./access-policies/mod.rs"]
Expand Down Expand Up @@ -66,37 +67,37 @@ async fn handle_get_group_request(

}

// /// DELETE /groups/{group_id}
// ///
// /// Deletes an app by its ID.
// #[axum::debug_handler]
// async fn handle_delete_app_request(
// Path(group_id): Path<String>,
// State(state): State<AppState>,
// Extension(http_transaction): Extension<Arc<HTTPTransaction>>,
// Extension(authenticated_user): Extension<Option<Arc<User>>>,
// Extension(authenticated_app): Extension<Option<Arc<App>>>,
// Extension(authenticated_app_authorization): Extension<Option<Arc<AppAuthorization>>>
// ) -> Result<StatusCode, HTTPError> {

// let group_id = get_uuid_from_string(&group_id, "app", &http_transaction, &state.database_pool).await?;
// let response = delete_resource(
// State(state),
// Extension(http_transaction),
// Extension(authenticated_user),
// Extension(authenticated_app),
// Extension(authenticated_app_authorization),
// Some(&AccessPolicyResourceType::App),
// &group_id,
// "apps.delete",
// "app",
// &ActionLogEntryTargetResourceType::App,
// |group_id, database_pool| Box::new(App::get_by_id(group_id, database_pool))
// ).await;

// return response;
/// DELETE /groups/{group_id}
///
/// Deletes a group by its ID.
#[axum::debug_handler]
async fn handle_delete_group_request(
Path(group_id): Path<String>,
State(state): State<AppState>,
Extension(http_transaction): Extension<Arc<HTTPTransaction>>,
Extension(authenticated_user): Extension<Option<Arc<User>>>,
Extension(authenticated_app): Extension<Option<Arc<App>>>,
Extension(authenticated_app_authorization): Extension<Option<Arc<AppAuthorization>>>
) -> Result<StatusCode, HTTPError> {

// }
let group_id = get_uuid_from_string(&group_id, "group", &http_transaction, &state.database_pool).await?;
let response = delete_resource(
State(state),
Extension(http_transaction),
Extension(authenticated_user),
Extension(authenticated_app),
Extension(authenticated_app_authorization),
Some(&AccessPolicyResourceType::Group),
&group_id,
"groups.delete",
"group",
&ActionLogEntryTargetResourceType::Group,
|group_id, database_pool| Box::new(Group::get_by_id(group_id, database_pool))
).await;

return response;

}

// /// PATCH /groups/{group_id}
// ///
Expand Down Expand Up @@ -184,7 +185,7 @@ pub fn get_router(state: AppState) -> Router<AppState> {

let router = Router::<AppState>::new()
.route("/groups/{group_id}", axum::routing::get(handle_get_group_request))
// .route("/groups/{group_id}", axum::routing::delete(handle_delete_app_request))
.route("/groups/{group_id}", axum::routing::delete(handle_delete_group_request))
// .route("/groups/{group_id}", axum::routing::patch(handle_patch_app_request))
.layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_user))
.layer(axum::middleware::from_fn_with_state(state.clone(), authentication_middleware::authenticate_app))
Expand Down
Loading