mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 22:31:20 +00:00
More overwriteable fields (#1155)
* Adding more overwriteable fields for user. Fixes #1154 * Adding a note for bio.
This commit is contained in:
parent
4772cbd23f
commit
0ebd830814
4 changed files with 25 additions and 29 deletions
|
@ -335,31 +335,24 @@ impl Perform for SaveUserSettings {
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
let read_user = blocking(context.pool(), move |conn| User_::read(conn, user_id)).await??;
|
let read_user = blocking(context.pool(), move |conn| User_::read(conn, user_id)).await??;
|
||||||
|
|
||||||
let bio = match &data.bio {
|
|
||||||
Some(bio) => {
|
|
||||||
if bio.chars().count() <= 300 {
|
|
||||||
Some(bio.to_owned())
|
|
||||||
} else {
|
|
||||||
return Err(APIError::err("bio_length_overflow").into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => read_user.bio,
|
|
||||||
};
|
|
||||||
|
|
||||||
let avatar = diesel_option_overwrite(&data.avatar);
|
let avatar = diesel_option_overwrite(&data.avatar);
|
||||||
let banner = diesel_option_overwrite(&data.banner);
|
let banner = diesel_option_overwrite(&data.banner);
|
||||||
let email = diesel_option_overwrite(&data.email);
|
let email = diesel_option_overwrite(&data.email);
|
||||||
|
let bio = diesel_option_overwrite(&data.bio);
|
||||||
|
let preferred_username = diesel_option_overwrite(&data.preferred_username);
|
||||||
|
let matrix_user_id = diesel_option_overwrite(&data.matrix_user_id);
|
||||||
|
|
||||||
// The DB constraint should stop too many characters
|
if let Some(Some(bio)) = &bio {
|
||||||
let preferred_username = match &data.preferred_username {
|
if bio.chars().count() > 300 {
|
||||||
Some(preferred_username) => {
|
return Err(APIError::err("bio_length_overflow").into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(Some(preferred_username)) = &preferred_username {
|
||||||
if !is_valid_preferred_username(preferred_username.trim()) {
|
if !is_valid_preferred_username(preferred_username.trim()) {
|
||||||
return Err(APIError::err("invalid_username").into());
|
return Err(APIError::err("invalid_username").into());
|
||||||
}
|
}
|
||||||
Some(preferred_username.trim().to_string())
|
|
||||||
}
|
}
|
||||||
None => read_user.preferred_username,
|
|
||||||
};
|
|
||||||
|
|
||||||
let password_encrypted = match &data.new_password {
|
let password_encrypted = match &data.new_password {
|
||||||
Some(new_password) => {
|
Some(new_password) => {
|
||||||
|
@ -397,7 +390,7 @@ impl Perform for SaveUserSettings {
|
||||||
let user_form = UserForm {
|
let user_form = UserForm {
|
||||||
name: read_user.name,
|
name: read_user.name,
|
||||||
email,
|
email,
|
||||||
matrix_user_id: data.matrix_user_id.to_owned(),
|
matrix_user_id,
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
password_encrypted,
|
password_encrypted,
|
||||||
|
|
|
@ -241,6 +241,9 @@ impl FromApub for UserForm {
|
||||||
.context(location_info!())?
|
.context(location_info!())?
|
||||||
.to_string();
|
.to_string();
|
||||||
let preferred_username = person.inner.preferred_username().map(|u| u.to_string());
|
let preferred_username = person.inner.preferred_username().map(|u| u.to_string());
|
||||||
|
|
||||||
|
// TODO a limit check (like the API does) might need to be done
|
||||||
|
// here when we federate to other platforms. Same for preferred_username
|
||||||
let bio = person
|
let bio = person
|
||||||
.inner
|
.inner
|
||||||
.summary()
|
.summary()
|
||||||
|
@ -253,7 +256,7 @@ impl FromApub for UserForm {
|
||||||
|
|
||||||
Ok(UserForm {
|
Ok(UserForm {
|
||||||
name,
|
name,
|
||||||
preferred_username,
|
preferred_username: Some(preferred_username),
|
||||||
password_encrypted: "".to_string(),
|
password_encrypted: "".to_string(),
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: false,
|
||||||
|
@ -271,7 +274,7 @@ impl FromApub for UserForm {
|
||||||
send_notifications_to_email: false,
|
send_notifications_to_email: false,
|
||||||
matrix_user_id: None,
|
matrix_user_id: None,
|
||||||
actor_id: Some(check_actor_domain(person, expected_domain)?),
|
actor_id: Some(check_actor_domain(person, expected_domain)?),
|
||||||
bio,
|
bio: Some(bio),
|
||||||
local: false,
|
local: false,
|
||||||
private_key: None,
|
private_key: None,
|
||||||
public_key: Some(person.ext_one.public_key.to_owned().public_key_pem),
|
public_key: Some(person.ext_one.public_key.to_owned().public_key_pem),
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub struct User_ {
|
||||||
#[table_name = "user_"]
|
#[table_name = "user_"]
|
||||||
pub struct UserForm {
|
pub struct UserForm {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub preferred_username: Option<String>,
|
pub preferred_username: Option<Option<String>>,
|
||||||
pub password_encrypted: String,
|
pub password_encrypted: String,
|
||||||
pub admin: bool,
|
pub admin: bool,
|
||||||
pub banned: bool,
|
pub banned: bool,
|
||||||
|
@ -58,9 +58,9 @@ pub struct UserForm {
|
||||||
pub lang: String,
|
pub lang: String,
|
||||||
pub show_avatars: bool,
|
pub show_avatars: bool,
|
||||||
pub send_notifications_to_email: bool,
|
pub send_notifications_to_email: bool,
|
||||||
pub matrix_user_id: Option<String>,
|
pub matrix_user_id: Option<Option<String>>,
|
||||||
pub actor_id: Option<String>,
|
pub actor_id: Option<String>,
|
||||||
pub bio: Option<String>,
|
pub bio: Option<Option<String>>,
|
||||||
pub local: bool,
|
pub local: bool,
|
||||||
pub private_key: Option<String>,
|
pub private_key: Option<String>,
|
||||||
pub public_key: Option<String>,
|
pub public_key: Option<String>,
|
||||||
|
|
|
@ -49,11 +49,11 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
let form = UserForm {
|
let form = UserForm {
|
||||||
name: cuser.name.to_owned(),
|
name: cuser.name.to_owned(),
|
||||||
email: Some(cuser.email.to_owned()),
|
email: Some(cuser.email.to_owned()),
|
||||||
matrix_user_id: cuser.matrix_user_id.to_owned(),
|
matrix_user_id: Some(cuser.matrix_user_id.to_owned()),
|
||||||
avatar: Some(cuser.avatar.to_owned()),
|
avatar: Some(cuser.avatar.to_owned()),
|
||||||
banner: Some(cuser.banner.to_owned()),
|
banner: Some(cuser.banner.to_owned()),
|
||||||
password_encrypted: cuser.password_encrypted.to_owned(),
|
password_encrypted: cuser.password_encrypted.to_owned(),
|
||||||
preferred_username: cuser.preferred_username.to_owned(),
|
preferred_username: Some(cuser.preferred_username.to_owned()),
|
||||||
published: Some(cuser.published),
|
published: Some(cuser.published),
|
||||||
updated: None,
|
updated: None,
|
||||||
admin: cuser.admin,
|
admin: cuser.admin,
|
||||||
|
@ -66,7 +66,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
show_avatars: cuser.show_avatars,
|
show_avatars: cuser.show_avatars,
|
||||||
send_notifications_to_email: cuser.send_notifications_to_email,
|
send_notifications_to_email: cuser.send_notifications_to_email,
|
||||||
actor_id: Some(make_apub_endpoint(EndpointType::User, &cuser.name).to_string()),
|
actor_id: Some(make_apub_endpoint(EndpointType::User, &cuser.name).to_string()),
|
||||||
bio: cuser.bio.to_owned(),
|
bio: Some(cuser.bio.to_owned()),
|
||||||
local: cuser.local,
|
local: cuser.local,
|
||||||
private_key: Some(keypair.private_key),
|
private_key: Some(keypair.private_key),
|
||||||
public_key: Some(keypair.public_key),
|
public_key: Some(keypair.public_key),
|
||||||
|
|
Loading…
Reference in a new issue