mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 18:19:03 +08:00
修复理由命令权限校验误用固定 sender 导致管理员被拒绝
This commit is contained in:
@@ -39,10 +39,14 @@ pub struct DeleteResult {
|
|||||||
pub changes: i32,
|
pub changes: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_admin_permission(state: &Arc<RwLock<AppState>>) -> bool {
|
fn check_admin_permission(state: &Arc<RwLock<AppState>>, sender_id: Option<u32>) -> bool {
|
||||||
let state_guard = state.read();
|
let state_guard = state.read();
|
||||||
let mut permissions = state_guard.permissions.write();
|
let mut permissions = state_guard.permissions.write();
|
||||||
permissions.require_permission(0, PermissionLevel::Admin)
|
if let Some(id) = sender_id {
|
||||||
|
permissions.require_permission(id, PermissionLevel::Admin)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -87,9 +91,10 @@ pub async fn reason_query(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn reason_create(
|
pub async fn reason_create(
|
||||||
state: State<'_, Arc<RwLock<AppState>>>,
|
state: State<'_, Arc<RwLock<AppState>>>,
|
||||||
|
sender_id: Option<u32>,
|
||||||
data: CreateReason,
|
data: CreateReason,
|
||||||
) -> Result<IpcResponse<i32>, String> {
|
) -> Result<IpcResponse<i32>, String> {
|
||||||
if !check_admin_permission(&state) {
|
if !check_admin_permission(&state, sender_id) {
|
||||||
return Ok(IpcResponse::error("Permission denied: admin required"));
|
return Ok(IpcResponse::error("Permission denied: admin required"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,10 +134,11 @@ pub async fn reason_create(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn reason_update(
|
pub async fn reason_update(
|
||||||
state: State<'_, Arc<RwLock<AppState>>>,
|
state: State<'_, Arc<RwLock<AppState>>>,
|
||||||
|
sender_id: Option<u32>,
|
||||||
id: i32,
|
id: i32,
|
||||||
data: UpdateReason,
|
data: UpdateReason,
|
||||||
) -> Result<IpcResponse<()>, String> {
|
) -> Result<IpcResponse<()>, String> {
|
||||||
if !check_admin_permission(&state) {
|
if !check_admin_permission(&state, sender_id) {
|
||||||
return Ok(IpcResponse::error("Permission denied: admin required"));
|
return Ok(IpcResponse::error("Permission denied: admin required"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,9 +186,10 @@ pub async fn reason_update(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn reason_delete(
|
pub async fn reason_delete(
|
||||||
state: State<'_, Arc<RwLock<AppState>>>,
|
state: State<'_, Arc<RwLock<AppState>>>,
|
||||||
|
sender_id: Option<u32>,
|
||||||
id: i32,
|
id: i32,
|
||||||
) -> Result<IpcResponse<DeleteResult>, String> {
|
) -> Result<IpcResponse<DeleteResult>, String> {
|
||||||
if !check_admin_permission(&state) {
|
if !check_admin_permission(&state, sender_id) {
|
||||||
return Ok(IpcResponse::error("Permission denied: admin required"));
|
return Ok(IpcResponse::error("Permission denied: admin required"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user