mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 14:21:19 +00:00
Dont throw error on empty LocalUser::update
This commit is contained in:
parent
6cefdaee49
commit
8862d61d40
5 changed files with 22 additions and 20 deletions
|
@ -29,7 +29,7 @@ pub async fn add_admin(
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::ObjectNotLocal)?;
|
.ok_or(LemmyErrorType::ObjectNotLocal)?;
|
||||||
|
|
||||||
let added_admin = LocalUser::update(
|
LocalUser::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
added_local_user.local_user.id,
|
added_local_user.local_user.id,
|
||||||
&LocalUserUpdateForm {
|
&LocalUserUpdateForm {
|
||||||
|
@ -43,7 +43,7 @@ pub async fn add_admin(
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModAddForm {
|
let form = ModAddForm {
|
||||||
mod_person_id: local_user_view.person.id,
|
mod_person_id: local_user_view.person.id,
|
||||||
other_person_id: added_admin.person_id,
|
other_person_id: added_local_user.person.id,
|
||||||
removed: Some(!data.added),
|
removed: Some(!data.added),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -141,11 +141,7 @@ pub async fn save_user_settings(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ignore errors, because 'no fields updated' will return an error.
|
LocalUser::update(&mut context.pool(), local_user_id, &local_user_form).await?;
|
||||||
// https://github.com/LemmyNet/lemmy/issues/4076
|
|
||||||
LocalUser::update(&mut context.pool(), local_user_id, &local_user_form)
|
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
// Update the vote display modes
|
// Update the vote display modes
|
||||||
let vote_display_modes_form = LocalUserVoteDisplayModeUpdateForm {
|
let vote_display_modes_form = LocalUserVoteDisplayModeUpdateForm {
|
||||||
|
|
|
@ -9,12 +9,10 @@ use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
email_verification::EmailVerification,
|
email_verification::EmailVerification,
|
||||||
local_user::{LocalUser, LocalUserUpdateForm},
|
local_user::{LocalUser, LocalUserUpdateForm},
|
||||||
person::Person,
|
|
||||||
},
|
},
|
||||||
traits::Crud,
|
|
||||||
RegistrationMode,
|
RegistrationMode,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
||||||
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
||||||
|
|
||||||
pub async fn verify_email(
|
pub async fn verify_email(
|
||||||
|
@ -38,7 +36,7 @@ pub async fn verify_email(
|
||||||
};
|
};
|
||||||
let local_user_id = verification.local_user_id;
|
let local_user_id = verification.local_user_id;
|
||||||
|
|
||||||
let local_user = LocalUser::update(&mut context.pool(), local_user_id, &form).await?;
|
LocalUser::update(&mut context.pool(), local_user_id, &form).await?;
|
||||||
|
|
||||||
EmailVerification::delete_old_tokens_for_local_user(&mut context.pool(), local_user_id).await?;
|
EmailVerification::delete_old_tokens_for_local_user(&mut context.pool(), local_user_id).await?;
|
||||||
|
|
||||||
|
@ -46,12 +44,16 @@ pub async fn verify_email(
|
||||||
if site_view.local_site.registration_mode == RegistrationMode::RequireApplication
|
if site_view.local_site.registration_mode == RegistrationMode::RequireApplication
|
||||||
&& site_view.local_site.application_email_admins
|
&& site_view.local_site.application_email_admins
|
||||||
{
|
{
|
||||||
let person = Person::read(&mut context.pool(), local_user.person_id)
|
let local_user = LocalUserView::read(&mut context.pool(), local_user_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
||||||
|
|
||||||
send_new_applicant_email_to_admins(&person.name, &mut context.pool(), context.settings())
|
send_new_applicant_email_to_admins(
|
||||||
.await?;
|
&local_user.person.name,
|
||||||
|
&mut context.pool(),
|
||||||
|
context.settings(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Json(SuccessResponse::default()))
|
Ok(Json(SuccessResponse::default()))
|
||||||
|
|
|
@ -133,8 +133,7 @@ pub async fn import_settings(
|
||||||
local_user_view.local_user.id,
|
local_user_view.local_user.id,
|
||||||
&local_user_form,
|
&local_user_form,
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.ok();
|
|
||||||
|
|
||||||
// Update the vote display mode settings
|
// Update the vote display mode settings
|
||||||
let vote_display_mode_form = LocalUserVoteDisplayModeUpdateForm {
|
let vote_display_mode_form = LocalUserVoteDisplayModeUpdateForm {
|
||||||
|
|
|
@ -55,12 +55,17 @@ impl LocalUser {
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
local_user_id: LocalUserId,
|
local_user_id: LocalUserId,
|
||||||
form: &LocalUserUpdateForm,
|
form: &LocalUserUpdateForm,
|
||||||
) -> Result<LocalUser, Error> {
|
) -> Result<usize, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(local_user::table.find(local_user_id))
|
let res = diesel::update(local_user::table.find(local_user_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.execute(conn)
|
||||||
.await
|
.await;
|
||||||
|
// Diesel will throw an error if the query is all Nones (not updating anything), ignore this.
|
||||||
|
match res {
|
||||||
|
Err(Error::QueryBuilderError(_)) => Ok(0),
|
||||||
|
other => other,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(pool: &mut DbPool<'_>, id: LocalUserId) -> Result<usize, Error> {
|
pub async fn delete(pool: &mut DbPool<'_>, id: LocalUserId) -> Result<usize, Error> {
|
||||||
|
|
Loading…
Reference in a new issue