1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Add chat command to clear CRF id in database; close #124

This commit is contained in:
NG (Graham)
2026-06-20 19:27:53 -04:00
parent 777ba327cc
commit f58bfa06d2
5 changed files with 68 additions and 0 deletions

View File

@@ -14519,6 +14519,15 @@
}, },
"permission": "Developer" "permission": "Developer"
}, },
{
"regex": "\\?nofactory",
"op": {
"type": "BuiltIn",
"built_in": "System",
"system": "ClearGarageFactoryFlag"
},
"permission": "Administrator"
},
{ {
"regex": "\\?help", "regex": "\\?help",
"op": { "op": {

View File

@@ -325,6 +325,7 @@ impl Intercom {
enum System { enum System {
Permissions, Permissions,
ClearGarageFactoryFlag,
} }
enum SystemPermission { enum SystemPermission {
@@ -383,6 +384,7 @@ impl System {
fn from_persist(sys: oj_rc_core::persist::SystemChatOperation) -> Self { fn from_persist(sys: oj_rc_core::persist::SystemChatOperation) -> Self {
match sys { match sys {
oj_rc_core::persist::SystemChatOperation::Permissions => Self::Permissions, oj_rc_core::persist::SystemChatOperation::Permissions => Self::Permissions,
oj_rc_core::persist::SystemChatOperation::ClearGarageFactoryFlag => Self::ClearGarageFactoryFlag,
} }
} }
@@ -410,6 +412,24 @@ impl System {
format!("Granted {} to {} (they should re-log)", perm.display(), &params[2]) format!("Granted {} to {} (they should re-log)", perm.display(), &params[2])
} }
}, },
Self::ClearGarageFactoryFlag => {
match ctx.user.clear_factory_flag().await {
Err(e) => {
if let Some(msg) = e.error_msg() {
format!("Failed to clear flag: {}", msg)
} else {
format!("Failed to clear flag (code {})", e.error_code())
}
},
Ok(is_changed) => {
if is_changed {
"Cleared flag from selected garage".to_owned()
} else {
"Cleared flag from selected garage (but it already was?)".to_owned()
}
}
}
}
} }
} }
@@ -417,6 +437,7 @@ impl System {
fn do_help(&self) -> String { fn do_help(&self) -> String {
match self { match self {
Self::Permissions => "Grant permissions to an account".to_owned(), Self::Permissions => "Grant permissions to an account".to_owned(),
Self::ClearGarageFactoryFlag => "Clear crf_id on currently-selected garage".to_owned(),
} }
} }
} }

View File

@@ -138,6 +138,7 @@ pub enum IntercomChatOperation {
#[serde(tag = "system")] #[serde(tag = "system")]
pub enum SystemChatOperation { pub enum SystemChatOperation {
Permissions, Permissions,
ClearGarageFactoryFlag,
} }

View File

@@ -216,4 +216,40 @@ impl super::ChatUser for UserData {
)) ))
} }
} }
async fn clear_factory_flag(&self) -> Result<bool, polariton_server::operations::SimpleOpError> {
let selected_garage_opt = self.db.garage_selected(self.account.id).await
.map_err(|e| {
log::error!("Failed to retrieve selected garage for user {}: {}", self.account.id, e);
polariton_server::operations::SimpleOpError::with_message(
crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16,
format!("Failed to retrieve selected garage: {}", e),
)
})?;
match selected_garage_opt {
Some(selected_garage) => {
self.db.update_garage(oj_rc_database::schema::garage::ActiveModel {
id: oj_rc_database::sea_orm::ActiveValue::Set(selected_garage.id),
user_id: oj_rc_database::sea_orm::ActiveValue::Set(self.account.id),
crf_id: oj_rc_database::sea_orm::ActiveValue::Set(None),
..Default::default()
}).await
.map_err(|e| {
log::error!("Failed to clear garage {} factory flag for user {}: {}", selected_garage.id, self.account.id, e);
polariton_server::operations::SimpleOpError::with_message(
crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16,
format!("Failed to clear garage {} factory flag: {}", selected_garage.id, e),
)
})?;
Ok(selected_garage.crf_id.is_some())
},
None => {
log::error!("Failed to find selected garage for user {}", self.account.id);
return Err(polariton_server::operations::SimpleOpError::with_message(
crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16,
format!("Failed to find selected garage"),
));
}
}
}
} }

View File

@@ -240,6 +240,7 @@ pub trait ChatUser: CommonUser + IntercomUser {
async fn set_sanction(&self, sanction: SetSanction) -> Result<(), i16>; async fn set_sanction(&self, sanction: SetSanction) -> Result<(), i16>;
async fn get_total_registered_users(&self) -> Result<u64, polariton_server::operations::SimpleOpError>; async fn get_total_registered_users(&self) -> Result<u64, polariton_server::operations::SimpleOpError>;
async fn set_permission(&self, username: String, permission: UserRole, value: bool) -> Result<(), polariton_server::operations::SimpleOpError>; async fn set_permission(&self, username: String, permission: UserRole, value: bool) -> Result<(), polariton_server::operations::SimpleOpError>;
async fn clear_factory_flag(&self) -> Result<bool, polariton_server::operations::SimpleOpError>;
} }
pub struct SetSanction { pub struct SetSanction {