Reworked telegram notifications
Build and Publish / Build and Publish Docker Image (push) Successful in 1m50s
Build and Publish / Build and Publish Docker Image (push) Successful in 1m50s
This commit is contained in:
+34
-2
@@ -401,6 +401,8 @@ async fn setup_submit(request: Request, session: Session, db: Database) -> cot::
|
||||
login: form.login,
|
||||
password_hash: password_auth::generate_hash(&form.password),
|
||||
display_name: display,
|
||||
telegram_chat_id: None,
|
||||
telegram_notifications: Some(false),
|
||||
status: "active".to_string(),
|
||||
created_at: now_utc(),
|
||||
updated_at: now_utc(),
|
||||
@@ -760,6 +762,8 @@ async fn add_user(request: Request, session: Session, db: Database) -> cot::Resu
|
||||
login: form.login,
|
||||
password_hash: password_auth::generate_hash(&form.password),
|
||||
display_name: display,
|
||||
telegram_chat_id: None,
|
||||
telegram_notifications: Some(false),
|
||||
status: "active".to_string(),
|
||||
created_at: now_utc(),
|
||||
updated_at: now_utc(),
|
||||
@@ -788,7 +792,6 @@ async fn add_user(request: Request, session: Session, db: Database) -> cot::Resu
|
||||
#[derive(Deserialize)]
|
||||
struct SettingsForm {
|
||||
telegram_bot_token: String,
|
||||
telegram_chat_id: String,
|
||||
contact_info: String,
|
||||
pricing_info: String,
|
||||
timezone: String,
|
||||
@@ -804,7 +807,6 @@ async fn save_settings(request: Request, session: Session, db: Database) -> cot:
|
||||
|
||||
for (key, value) in [
|
||||
("telegram_bot_token", form.telegram_bot_token),
|
||||
("telegram_chat_id", form.telegram_chat_id),
|
||||
("contact_info", form.contact_info),
|
||||
("pricing_info", form.pricing_info),
|
||||
("timezone", form.timezone),
|
||||
@@ -975,6 +977,31 @@ async fn user_activate(
|
||||
Redirect::new(format!("/admin/users?lang={}", lang.code())).into_response()
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct UserTelegramForm {
|
||||
telegram_chat_id: Option<String>,
|
||||
telegram_notifications: Option<String>,
|
||||
}
|
||||
|
||||
async fn user_update_telegram(
|
||||
request: Request,
|
||||
session: Session,
|
||||
db: Database,
|
||||
Path(user_id): Path<i64>,
|
||||
) -> cot::Result<Response> {
|
||||
let (lang, form): (_, UserTelegramForm) = parse_form_from_request(request).await?;
|
||||
if let Err(resp) = require_auth(&session, lang).await {
|
||||
return Ok(resp);
|
||||
}
|
||||
if let Some(mut user) = query!(User, $id == user_id).get(&db).await? {
|
||||
user.telegram_chat_id = form.telegram_chat_id.filter(|s| !s.trim().is_empty());
|
||||
user.telegram_notifications = Some(form.telegram_notifications.as_deref() == Some("true"));
|
||||
user.updated_at = now_utc();
|
||||
user.save(&db).await?;
|
||||
}
|
||||
Redirect::new(format!("/admin/users?lang={}", lang.code())).into_response()
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct AddLeadForm {
|
||||
name: String,
|
||||
@@ -2077,6 +2104,11 @@ pub fn admin_router() -> Router {
|
||||
user_activate,
|
||||
"admin-user-activate",
|
||||
),
|
||||
Route::with_handler_and_name(
|
||||
"/users/{user_id}/telegram",
|
||||
user_update_telegram,
|
||||
"admin-user-telegram",
|
||||
),
|
||||
Route::with_handler_and_name("/media", media_page, "admin-media"),
|
||||
Route::with_handler_and_name(
|
||||
"/media/{visit_id}/upload",
|
||||
|
||||
Reference in New Issue
Block a user