fix(admin): prevent permission denied error from blocking user editing in 0.0.8

This commit is contained in:
Nikita 2026-10-27 13:48:24 +05:00
parent 429b81e6ad
commit e7b926fd48
5 changed files with 41 additions and 15 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "has", "name": "has",
"private": true, "private": true,
"version": "0.0.7", "version": "0.0.8",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

2
src-tauri/Cargo.lock generated
View file

@ -1581,7 +1581,7 @@ dependencies = [
[[package]] [[package]]
name = "has" name = "has"
version = "0.0.6" version = "0.0.8"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"bcrypt", "bcrypt",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "has" name = "has"
version = "0.0.7" version = "0.0.8"
description = "has" description = "has"
authors = ["autli"] authors = ["autli"]
edition = "2024" edition = "2024"

View file

@ -85,16 +85,17 @@ pub async fn init_admin_security_table(client: &tokio_postgres::Client) -> Resul
VALUES (1, false, false) VALUES (1, false, false)
ON CONFLICT (id) DO NOTHING; ON CONFLICT (id) DO NOTHING;
"; ";
client // If has_app lacks DDL permissions on public schema, do not fail admin updates
.batch_execute(sql) if let Err(e) = client.batch_execute(sql).await {
.await eprintln!("[admin] admin_security_config table creation skipped: {}", e);
.map_err(|e| format!("Ошибка создания таблицы безопасности: {}", e)) }
Ok(())
} }
pub async fn get_admin_security_info(admin_email: &str) -> Result<DeviceSecurityInfo, String> { pub async fn get_admin_security_info(admin_email: &str) -> Result<DeviceSecurityInfo, String> {
let config = get_db_config(); let config = get_db_config();
let client = connect_to_db(&config).await?; let client = connect_to_db(&config).await?;
init_admin_security_table(&client).await?; let _ = init_admin_security_table(&client).await;
let clean_email = admin_email.trim().to_lowercase(); let clean_email = admin_email.trim().to_lowercase();
let user_row = client let user_row = client
@ -119,17 +120,18 @@ pub async fn get_admin_security_info(admin_email: &str) -> Result<DeviceSecurity
}; };
let cfg_row = client let cfg_row = client
.query_one( .query_opt(
"SELECT device_binding_enabled, trusted_device_name, ip_binding_enabled, trusted_ip FROM admin_security_config WHERE id = 1", "SELECT device_binding_enabled, trusted_device_name, ip_binding_enabled, trusted_ip FROM admin_security_config WHERE id = 1",
&[], &[],
) )
.await .await
.map_err(|e| format!("Ошибка чтения параметров безопасности: {}", e))?; .ok()
.flatten();
let device_binding_enabled: bool = cfg_row.get(0); let (device_binding_enabled, trusted_device_name, ip_binding_enabled, trusted_ip): (bool, Option<String>, bool, Option<String>) = match cfg_row {
let trusted_device_name: Option<String> = cfg_row.get(1); Some(row) => (row.get(0), row.get(1), row.get(2), row.get(3)),
let ip_binding_enabled: bool = cfg_row.get(2); None => (false, None, false, None),
let trusted_ip: Option<String> = cfg_row.get(3); };
let current_device = get_current_device_name(); let current_device = get_current_device_name();
let current_ip = get_current_local_ip(); let current_ip = get_current_local_ip();
@ -310,3 +312,27 @@ pub async fn admin_delete_user(
Ok("Пользователь успешно удален".to_string()) Ok("Пользователь успешно удален".to_string())
} }
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_init_admin_security() {
let config = get_db_config();
if let Ok(client) = connect_to_db(&config).await {
let res = init_admin_security_table(&client).await;
assert!(res.is_ok());
}
}
#[tokio::test]
async fn test_get_admin_security_info() {
let config = get_db_config();
if let Ok(_) = connect_to_db(&config).await {
let res = get_admin_security_info("dimatyilickiy0511@gmail.com").await;
println!("get_admin_security_info result: {:?}", res);
assert!(res.is_ok());
}
}
}

View file

@ -1,7 +1,7 @@
{ {
"$schema": "https://schema.tauri.app/config/2", "$schema": "https://schema.tauri.app/config/2",
"productName": "has", "productName": "has",
"version": "0.0.7", "version": "0.0.8",
"identifier": "com.has.tauri-app", "identifier": "com.has.tauri-app",
"build": { "build": {
"beforeDevCommand": "npm run dev", "beforeDevCommand": "npm run dev",