mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-04 16:37:46 +08:00
Redesign sensitive info protection settings
This commit is contained in:
@@ -275,6 +275,7 @@ impl<'a> AdminAppState<'a> {
|
||||
"rate_limit": user.rate_limit,
|
||||
"rate_limit_mode": user.rate_limit_mode.clone(),
|
||||
"model_capability_settings": user.model_capability_settings.clone(),
|
||||
"feature_settings": user.feature_settings.clone(),
|
||||
"group_ids": group_ids,
|
||||
"group_names": group_names,
|
||||
"unlimited": wallet
|
||||
@@ -334,6 +335,10 @@ impl<'a> AdminAppState<'a> {
|
||||
"force_capabilities".to_string(),
|
||||
json!(key.force_capabilities.clone()),
|
||||
),
|
||||
(
|
||||
"feature_settings".to_string(),
|
||||
json!(key.feature_settings.clone()),
|
||||
),
|
||||
("is_active".to_string(), json!(key.is_active)),
|
||||
(
|
||||
"expires_at".to_string(),
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::handlers::admin::shared::{
|
||||
};
|
||||
use crate::handlers::admin::system::shared::configs::apply_admin_system_config_update;
|
||||
use crate::handlers::admin::users::{
|
||||
hash_admin_user_api_key, normalize_admin_list_policy_mode,
|
||||
hash_admin_user_api_key, normalize_admin_feature_settings, normalize_admin_list_policy_mode,
|
||||
normalize_admin_rate_limit_policy_mode, normalize_admin_user_api_formats,
|
||||
normalize_admin_user_string_list,
|
||||
};
|
||||
@@ -2104,6 +2104,11 @@ impl<'a> AdminAppState<'a> {
|
||||
user.get("model_capability_settings"),
|
||||
"model_capability_settings"
|
||||
));
|
||||
let feature_settings = invalid_value!(imported_optional_json_object(
|
||||
user.get("feature_settings"),
|
||||
"feature_settings"
|
||||
)
|
||||
.and_then(normalize_admin_feature_settings));
|
||||
let wallet_payload = match user.get("wallet") {
|
||||
Some(Value::Object(map)) => Some(map),
|
||||
Some(Value::Null) | None => None,
|
||||
@@ -2221,6 +2226,14 @@ impl<'a> AdminAppState<'a> {
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
if user.contains_key("feature_settings") {
|
||||
let _ = self
|
||||
.update_user_feature_settings(
|
||||
&existing.id,
|
||||
feature_settings.clone(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
if allowed_providers_mode.is_some()
|
||||
|| allowed_api_formats_mode.is_some()
|
||||
|| allowed_models_mode.is_some()
|
||||
@@ -2284,6 +2297,11 @@ impl<'a> AdminAppState<'a> {
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
if user.contains_key("feature_settings") {
|
||||
let _ = self
|
||||
.update_user_feature_settings(&created.id, feature_settings.clone())
|
||||
.await?;
|
||||
}
|
||||
let created = if allowed_providers_mode.is_some()
|
||||
|| allowed_api_formats_mode.is_some()
|
||||
|| allowed_models_mode.is_some()
|
||||
@@ -2402,6 +2420,11 @@ impl<'a> AdminAppState<'a> {
|
||||
"total_cost_usd"
|
||||
))
|
||||
.unwrap_or(0.0);
|
||||
let feature_settings = invalid_value!(imported_optional_json_object(
|
||||
key.get("feature_settings"),
|
||||
"feature_settings"
|
||||
)
|
||||
.and_then(normalize_admin_feature_settings));
|
||||
|
||||
if let Some(existing_key) = existing_api_keys_by_hash.get(&key_hash).cloned() {
|
||||
match merge_mode {
|
||||
@@ -2450,6 +2473,15 @@ impl<'a> AdminAppState<'a> {
|
||||
force_capabilities.clone(),
|
||||
)
|
||||
.await?;
|
||||
if key.contains_key("feature_settings") {
|
||||
let _ = self
|
||||
.set_user_api_key_feature_settings(
|
||||
&user_id,
|
||||
&existing_key.api_key_id,
|
||||
feature_settings.clone(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
let _ = self
|
||||
.set_user_api_key_active(
|
||||
&user_id,
|
||||
@@ -2503,6 +2535,15 @@ impl<'a> AdminAppState<'a> {
|
||||
json!({ "detail": "Admin system data unavailable" }),
|
||||
)));
|
||||
};
|
||||
if key.contains_key("feature_settings") {
|
||||
let _ = self
|
||||
.set_user_api_key_feature_settings(
|
||||
&user_id,
|
||||
&created.api_key_id,
|
||||
feature_settings.clone(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
existing_api_keys_by_hash.insert(key_hash, created);
|
||||
stats.api_keys.created += 1;
|
||||
}
|
||||
@@ -2596,6 +2637,11 @@ impl<'a> AdminAppState<'a> {
|
||||
"total_cost_usd"
|
||||
))
|
||||
.unwrap_or(0.0);
|
||||
let feature_settings = invalid_value!(imported_optional_json_object(
|
||||
key.get("feature_settings"),
|
||||
"feature_settings"
|
||||
)
|
||||
.and_then(normalize_admin_feature_settings));
|
||||
let wallet_payload = match key.get("wallet") {
|
||||
Some(Value::Object(map)) => Some(map),
|
||||
Some(Value::Null) | None => None,
|
||||
@@ -2643,6 +2689,14 @@ impl<'a> AdminAppState<'a> {
|
||||
let _ = self
|
||||
.set_standalone_api_key_active(&existing_key.api_key_id, is_active)
|
||||
.await?;
|
||||
if key.contains_key("feature_settings") {
|
||||
let _ = self
|
||||
.set_standalone_api_key_feature_settings(
|
||||
&existing_key.api_key_id,
|
||||
feature_settings.clone(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
if key.contains_key("expires_at")
|
||||
|| key.contains_key("auto_delete_on_expiry")
|
||||
|| key.contains_key("force_capabilities")
|
||||
@@ -2697,6 +2751,14 @@ impl<'a> AdminAppState<'a> {
|
||||
json!({ "detail": "Admin system data unavailable" }),
|
||||
)));
|
||||
};
|
||||
if key.contains_key("feature_settings") {
|
||||
let _ = self
|
||||
.set_standalone_api_key_feature_settings(
|
||||
&created.api_key_id,
|
||||
feature_settings.clone(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
self.sync_imported_api_key_wallet(
|
||||
&created.api_key_id,
|
||||
&wallet_target,
|
||||
|
||||
@@ -421,6 +421,16 @@ impl<'a> AdminAppState<'a> {
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn update_user_feature_settings(
|
||||
&self,
|
||||
user_id: &str,
|
||||
settings: Option<serde_json::Value>,
|
||||
) -> Result<Option<serde_json::Value>, GatewayError> {
|
||||
self.app
|
||||
.update_user_feature_settings(user_id, settings)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn count_user_pending_refunds(
|
||||
&self,
|
||||
user_id: &str,
|
||||
@@ -619,6 +629,17 @@ impl<'a> AdminAppState<'a> {
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn set_standalone_api_key_feature_settings(
|
||||
&self,
|
||||
api_key_id: &str,
|
||||
feature_settings: Option<serde_json::Value>,
|
||||
) -> Result<Option<aether_data::repository::auth::StoredAuthApiKeyExportRecord>, GatewayError>
|
||||
{
|
||||
self.app
|
||||
.set_standalone_api_key_feature_settings(api_key_id, feature_settings)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn set_user_api_key_active(
|
||||
&self,
|
||||
user_id: &str,
|
||||
@@ -666,6 +687,18 @@ impl<'a> AdminAppState<'a> {
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn set_user_api_key_feature_settings(
|
||||
&self,
|
||||
user_id: &str,
|
||||
api_key_id: &str,
|
||||
feature_settings: Option<serde_json::Value>,
|
||||
) -> Result<Option<aether_data::repository::auth::StoredAuthApiKeyExportRecord>, GatewayError>
|
||||
{
|
||||
self.app
|
||||
.set_user_api_key_feature_settings(user_id, api_key_id, feature_settings)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn delete_user_api_key(
|
||||
&self,
|
||||
user_id: &str,
|
||||
|
||||
Reference in New Issue
Block a user