feat: add pronouns to users
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/push/publish-docs Pipeline was successful

This commit is contained in:
Radical 2025-06-01 15:58:07 +02:00
parent 2f7fac8db5
commit ee8211a321
5 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE users DROP COLUMN pronouns;

View file

@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE users ADD COLUMN pronouns VARCHAR(32) DEFAULT NULL;

View file

@ -40,6 +40,7 @@ struct NewInfo {
display_name: Option<String>, display_name: Option<String>,
//password: Option<String>, will probably be handled through a reset password link //password: Option<String>, will probably be handled through a reset password link
email: Option<String>, email: Option<String>,
pronouns: Option<String>,
} }
#[derive(Debug, MultipartForm)] #[derive(Debug, MultipartForm)]
@ -97,5 +98,9 @@ pub async fn update(
me.set_email(&data, email.clone()).await?; me.set_email(&data, email.clone()).await?;
} }
if let Some(pronouns) = &form.json.pronouns {
me.set_pronouns(&data, pronouns.clone()).await?;
}
Ok(HttpResponse::Ok().finish()) Ok(HttpResponse::Ok().finish())
} }

View file

@ -144,6 +144,8 @@ diesel::table! {
deleted_at -> Nullable<Int8>, deleted_at -> Nullable<Int8>,
#[max_length = 100] #[max_length = 100]
avatar -> Nullable<Varchar>, avatar -> Nullable<Varchar>,
#[max_length = 32]
pronouns -> Nullable<Varchar>,
} }
} }

View file

@ -865,6 +865,7 @@ pub struct User {
username: String, username: String,
display_name: Option<String>, display_name: Option<String>,
avatar: Option<String>, avatar: Option<String>,
pronouns: Option<String>,
} }
impl User { impl User {
@ -915,6 +916,7 @@ pub struct Me {
username: String, username: String,
display_name: Option<String>, display_name: Option<String>,
avatar: Option<String>, avatar: Option<String>,
pronouns: Option<String>,
email: String, email: String,
pub email_verified: bool, pub email_verified: bool,
} }
@ -1090,6 +1092,25 @@ impl Me {
Ok(()) Ok(())
} }
pub async fn set_pronouns(&mut self, data: &Data, new_pronouns: String) -> Result<(), Error> {
let mut conn = data.pool.get().await?;
use users::dsl;
update(users::table)
.filter(dsl::uuid.eq(self.uuid))
.set((
dsl::pronouns.eq(new_pronouns.as_str()),
))
.execute(&mut conn)
.await?;
if data.get_cache_key(self.uuid.to_string()).await.is_ok() {
data.del_cache_key(self.uuid.to_string()).await?
}
Ok(())
}
} }
#[derive(Deserialize)] #[derive(Deserialize)]