4028f0d943
- Reordered actix-web imports to standardize import order - Reordered crate module imports to follow alphabetical ordering - Updated function calls to use multi-line formatting for better readability - Standardized blank lines around documentation comments - Applied consistent formatting to response handling methods - Normalized import organization across all repository-related API files - Improved code consistency and maintainability through standardized formatting - Applied formatting updates to all repository endpoint implementations
56 lines
1.8 KiB
Rust
56 lines
1.8 KiB
Rust
use actix_web::{HttpResponse, web};
|
|
use serde::Deserialize;
|
|
use utoipa::IntoParams;
|
|
|
|
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
|
use crate::error::AppError;
|
|
use crate::service::AppService;
|
|
use crate::session::Session;
|
|
|
|
#[derive(Debug, Deserialize, IntoParams)]
|
|
pub struct PathParams {
|
|
/// Token ID (UUID)
|
|
pub token_id: uuid::Uuid,
|
|
}
|
|
|
|
/// Revoke a personal access token
|
|
///
|
|
/// Immediately revokes a personal access token belonging to the authenticated user.
|
|
/// Requires authentication.
|
|
///
|
|
/// Effects:
|
|
/// - Token is marked as revoked and can no longer be used
|
|
/// - All API calls using this token will fail with 401 Unauthorized
|
|
/// - Revoked tokens remain visible in token list for audit purposes
|
|
///
|
|
/// Returns success message on completion.
|
|
#[utoipa::path(
|
|
delete,
|
|
path = "/api/v1/user/security/tokens/{token_id}",
|
|
tag = "User",
|
|
operation_id = "userRevokeToken",
|
|
params(PathParams),
|
|
responses(
|
|
(status = 200, description = "Personal access token revoked successfully.", body = ApiResponse<String>),
|
|
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
|
(status = 404, description = "Token not found or already revoked", body = ApiErrorResponse),
|
|
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
|
),
|
|
security(
|
|
("session_cookie" = [])
|
|
)
|
|
)]
|
|
pub async fn revoke_token(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<PathParams>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
service
|
|
.user
|
|
.user_revoke_personal_access_token(&session, path.token_id)
|
|
.await?;
|
|
Ok(HttpResponse::Ok().json(ApiResponse::new(
|
|
"Personal access token revoked successfully".to_string(),
|
|
)))
|
|
}
|