fix: revoke_api_key sets NONE, remove unused bind, lowercase error msgs

- fix bug where revoke_api_key set literal 'test_string_nullish' instead of NONE
- remove unused table_name bind in update_timezone
- lowercase ~16 error messages across 4 crates
This commit is contained in:
Per Stark
2026-05-27 13:56:32 +02:00
parent 31d585b59f
commit 9609880cff
9 changed files with 18 additions and 19 deletions
+4 -4
View File
@@ -34,7 +34,7 @@ impl Analytics {
let stored: Option<Self> = db.store_item(created_analytics).await?; let stored: Option<Self> = db.store_item(created_analytics).await?;
return stored.ok_or(AppError::Validation( return stored.ok_or(AppError::Validation(
"Failed to initialize analytics".into(), "failed to initialize analytics".into(),
)); ));
} }
@@ -44,7 +44,7 @@ impl Analytics {
} }
pub async fn get_current(db: &SurrealDbClient) -> Result<Self, AppError> { pub async fn get_current(db: &SurrealDbClient) -> Result<Self, AppError> {
let analytics: Option<Self> = db.get_item("current").await?; let analytics: Option<Self> = db.get_item("current").await?;
analytics.ok_or(AppError::NotFound("Analytics not found".into())) analytics.ok_or(AppError::NotFound("analytics not found".into()))
} }
pub async fn increment_visitors(db: &SurrealDbClient) -> Result<Self, AppError> { pub async fn increment_visitors(db: &SurrealDbClient) -> Result<Self, AppError> {
@@ -54,7 +54,7 @@ impl Analytics {
.await? .await?
.take(0)?; .take(0)?;
updated.ok_or(AppError::Validation("Failed to update analytics".into())) updated.ok_or(AppError::Validation("failed to update analytics".into()))
} }
pub async fn increment_page_loads(db: &SurrealDbClient) -> Result<Self, AppError> { pub async fn increment_page_loads(db: &SurrealDbClient) -> Result<Self, AppError> {
@@ -64,7 +64,7 @@ impl Analytics {
.await? .await?
.take(0)?; .take(0)?;
updated.ok_or(AppError::Validation("Failed to update analytics".into())) updated.ok_or(AppError::Validation("failed to update analytics".into()))
} }
pub async fn get_users_amount(db: &SurrealDbClient) -> Result<i64, AppError> { pub async fn get_users_amount(db: &SurrealDbClient) -> Result<i64, AppError> {
+2 -2
View File
@@ -79,7 +79,7 @@ impl Conversation {
let conversation: Conversation = db let conversation: Conversation = db
.get_item(conversation_id) .get_item(conversation_id)
.await? .await?
.ok_or_else(|| AppError::NotFound("Conversation not found".to_string()))?; .ok_or_else(|| AppError::NotFound("conversation not found".to_string()))?;
if conversation.user_id != user_id { if conversation.user_id != user_id {
return Err(AppError::Auth( return Err(AppError::Auth(
@@ -105,7 +105,7 @@ impl Conversation {
// First verify ownership by getting conversation user_id // First verify ownership by getting conversation user_id
let conversation: Option<Conversation> = db.get_item(id).await?; let conversation: Option<Conversation> = db.get_item(id).await?;
let conversation = let conversation =
conversation.ok_or_else(|| AppError::NotFound("Conversation not found".to_string()))?; conversation.ok_or_else(|| AppError::NotFound("conversation not found".to_string()))?;
if conversation.user_id != user_id { if conversation.user_id != user_id {
return Err(AppError::Auth( return Err(AppError::Auth(
+1 -1
View File
@@ -78,7 +78,7 @@ impl Scratchpad {
let scratchpad: Option<Scratchpad> = db.get_item(id).await?; let scratchpad: Option<Scratchpad> = db.get_item(id).await?;
let scratchpad = let scratchpad =
scratchpad.ok_or_else(|| AppError::NotFound("Scratchpad not found".to_string()))?; scratchpad.ok_or_else(|| AppError::NotFound("scratchpad not found".to_string()))?;
if scratchpad.user_id != user_id { if scratchpad.user_id != user_id {
return Err(AppError::Auth( return Err(AppError::Auth(
+2 -2
View File
@@ -36,7 +36,7 @@ impl StoredObject for SystemSettings {
impl SystemSettings { impl SystemSettings {
pub async fn get_current(db: &SurrealDbClient) -> Result<Self, AppError> { pub async fn get_current(db: &SurrealDbClient) -> Result<Self, AppError> {
let settings: Option<Self> = db.get_item("current").await?; let settings: Option<Self> = db.get_item("current").await?;
settings.ok_or(AppError::NotFound("System settings not found".into())) settings.ok_or(AppError::NotFound("system settings not found".into()))
} }
pub async fn update(db: &SurrealDbClient, changes: Self) -> Result<Self, AppError> { pub async fn update(db: &SurrealDbClient, changes: Self) -> Result<Self, AppError> {
@@ -49,7 +49,7 @@ impl SystemSettings {
.take(0)?; .take(0)?;
updated.ok_or(AppError::Validation( updated.ok_or(AppError::Validation(
"Something went wrong updating the settings".into(), "something went wrong updating the settings".into(),
)) ))
} }
+3 -4
View File
@@ -371,7 +371,7 @@ impl User {
.client .client
.query( .query(
"UPDATE type::thing('user', $id) "UPDATE type::thing('user', $id)
SET api_key = test_string_nullish SET api_key = NONE
RETURN AFTER", RETURN AFTER",
) )
.bind(("id", id.to_owned())) .bind(("id", id.to_owned()))
@@ -532,7 +532,6 @@ impl User {
db: &SurrealDbClient, db: &SurrealDbClient,
) -> Result<(), AppError> { ) -> Result<(), AppError> {
db.query("UPDATE type::thing('user', $user_id) SET timezone = $timezone") db.query("UPDATE type::thing('user', $user_id) SET timezone = $timezone")
.bind(("table_name", Self::table_name()))
.bind(("user_id", user_id.to_string())) .bind(("user_id", user_id.to_string()))
.bind(("timezone", timezone.to_string())) .bind(("timezone", timezone.to_string()))
.await?; .await?;
@@ -579,7 +578,7 @@ impl User {
let entity: KnowledgeEntity = db let entity: KnowledgeEntity = db
.get_item(id) .get_item(id)
.await? .await?
.ok_or_else(|| AppError::NotFound("Entity not found".into()))?; .ok_or_else(|| AppError::NotFound("entity not found".into()))?;
if entity.user_id != user_id { if entity.user_id != user_id {
return Err(AppError::Auth("Access denied".into())); return Err(AppError::Auth("Access denied".into()));
@@ -596,7 +595,7 @@ impl User {
let text_content: TextContent = db let text_content: TextContent = db
.get_item(id) .get_item(id)
.await? .await?
.ok_or_else(|| AppError::NotFound("Content not found".into()))?; .ok_or_else(|| AppError::NotFound("content not found".into()))?;
if text_content.user_id != user_id { if text_content.user_id != user_id {
return Err(AppError::Auth("Access denied".into())); return Err(AppError::Auth("Access denied".into()));
+3 -3
View File
@@ -148,7 +148,7 @@ pub async fn new_user_message(
.db .db
.get_item(&conversation_id) .get_item(&conversation_id)
.await? .await?
.ok_or_else(|| AppError::NotFound("Conversation was not found".into()))?; .ok_or_else(|| AppError::NotFound("conversation was not found".into()))?;
if conversation.user_id != user.id { if conversation.user_id != user.id {
return Ok(TemplateResponse::unauthorized().into_response()); return Ok(TemplateResponse::unauthorized().into_response());
@@ -235,7 +235,7 @@ pub async fn show_conversation_editing_title(
.db .db
.get_item(&conversation_id) .get_item(&conversation_id)
.await? .await?
.ok_or_else(|| AppError::NotFound("Conversation not found".to_string()))?; .ok_or_else(|| AppError::NotFound("conversation not found".to_string()))?;
if conversation.user_id != user.id { if conversation.user_id != user.id {
return Ok(TemplateResponse::unauthorized().into_response()); return Ok(TemplateResponse::unauthorized().into_response());
@@ -277,7 +277,7 @@ pub async fn delete_conversation(
.db .db
.get_item(&conversation_id) .get_item(&conversation_id)
.await? .await?
.ok_or_else(|| AppError::NotFound("Conversation not found".to_string()))?; .ok_or_else(|| AppError::NotFound("conversation not found".to_string()))?;
if conversation.user_id != user.id { if conversation.user_id != user.id {
return Ok(TemplateResponse::unauthorized().into_response()); return Ok(TemplateResponse::unauthorized().into_response());
+1 -1
View File
@@ -113,7 +113,7 @@ async fn get_and_validate_text_content(
.db .db
.get_item::<TextContent>(id) .get_item::<TextContent>(id)
.await? .await?
.ok_or_else(|| AppError::NotFound("Item was not found".to_string()))?; .ok_or_else(|| AppError::NotFound("item was not found".to_string()))?;
if text_content.user_id != user.id { if text_content.user_id != user.id {
return Err(AppError::Auth( return Err(AppError::Auth(
+1 -1
View File
@@ -173,7 +173,7 @@ pub async fn create_knowledge_entity(
) -> Result<impl IntoResponse, HtmlError> { ) -> Result<impl IntoResponse, HtmlError> {
let name = form.name.trim().to_string(); let name = form.name.trim().to_string();
if name.is_empty() { if name.is_empty() {
return Err(AppError::Validation("Name is required".into()).into()); return Err(AppError::Validation("name is required".into()).into());
} }
let description = form.description.trim().to_string(); let description = form.description.trim().to_string();
@@ -75,7 +75,7 @@ pub async fn extract_text_from_url(
} }
let parsed_url = let parsed_url =
url::Url::parse(url).map_err(|_| AppError::Validation("Invalid URL".to_string()))?; url::Url::parse(url).map_err(|_| AppError::Validation("invalid URL".to_string()))?;
let domain = ensure_ingestion_url_allowed(&parsed_url)?; let domain = ensure_ingestion_url_allowed(&parsed_url)?;
let timestamp = Utc::now().format("%Y%m%d%H%M%S"); let timestamp = Utc::now().format("%Y%m%d%H%M%S");