mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-21 22:27:08 +00:00
Also clear bio Better account deletion (fixes #730) Co-authored-by: Felix Ableitner <me@nutomic.com> Reviewed-on: https://yerbamate.ml/LemmyNet/lemmy/pulls/143
This commit is contained in:
parent
050ca88085
commit
3ceeecc63e
|
@ -782,9 +782,9 @@ impl Perform for ResolveCommentReport {
|
|||
let resolved = data.resolved;
|
||||
let resolve_fun = move |conn: &'_ _| {
|
||||
if resolved {
|
||||
CommentReport::resolve(conn, report_id.clone(), user_id)
|
||||
CommentReport::resolve(conn, report_id, user_id)
|
||||
} else {
|
||||
CommentReport::unresolve(conn, report_id.clone(), user_id)
|
||||
CommentReport::unresolve(conn, report_id, user_id)
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -839,9 +839,9 @@ impl Perform for ResolvePostReport {
|
|||
let resolved = data.resolved;
|
||||
let resolve_fun = move |conn: &'_ _| {
|
||||
if resolved {
|
||||
PostReport::resolve(conn, report_id.clone(), user_id)
|
||||
PostReport::resolve(conn, report_id, user_id)
|
||||
} else {
|
||||
PostReport::unresolve(conn, report_id.clone(), user_id)
|
||||
PostReport::unresolve(conn, report_id, user_id)
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -890,6 +890,11 @@ impl Perform for DeleteAccount {
|
|||
return Err(APIError::err("couldnt_update_post").into());
|
||||
}
|
||||
|
||||
blocking(context.pool(), move |conn| {
|
||||
User_::delete_account(conn, user_id)
|
||||
})
|
||||
.await??;
|
||||
|
||||
Ok(LoginResponse {
|
||||
jwt: data.auth.to_owned(),
|
||||
})
|
||||
|
|
|
@ -467,6 +467,7 @@ table! {
|
|||
public_key -> Nullable<Text>,
|
||||
last_refreshed_at -> Timestamp,
|
||||
banner -> Nullable<Text>,
|
||||
deleted -> Bool,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ pub struct User_ {
|
|||
pub public_key: Option<String>,
|
||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||
pub banner: Option<String>,
|
||||
pub deleted: bool,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
|
@ -70,7 +71,10 @@ pub struct UserForm {
|
|||
|
||||
impl Crud<UserForm> for User_ {
|
||||
fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
|
||||
user_.find(user_id).first::<Self>(conn)
|
||||
user_
|
||||
.filter(deleted.eq(false))
|
||||
.find(user_id)
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
fn delete(conn: &PgConnection, user_id: i32) -> Result<usize, Error> {
|
||||
diesel::delete(user_.find(user_id)).execute(conn)
|
||||
|
@ -114,6 +118,7 @@ impl User_ {
|
|||
pub fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<Self, Error> {
|
||||
user_
|
||||
.filter(local.eq(true))
|
||||
.filter(deleted.eq(false))
|
||||
.filter(name.eq(from_user_name))
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
@ -132,7 +137,10 @@ impl User_ {
|
|||
|
||||
pub fn read_from_actor_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
|
||||
use crate::schema::user_::dsl::*;
|
||||
user_.filter(actor_id.eq(object_id)).first::<Self>(conn)
|
||||
user_
|
||||
.filter(deleted.eq(false))
|
||||
.filter(actor_id.eq(object_id))
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
pub fn find_by_email_or_username(
|
||||
|
@ -148,6 +156,7 @@ impl User_ {
|
|||
|
||||
pub fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
|
||||
user_
|
||||
.filter(deleted.eq(false))
|
||||
.filter(local.eq(true))
|
||||
.filter(name.ilike(username))
|
||||
.first::<User_>(conn)
|
||||
|
@ -155,6 +164,7 @@ impl User_ {
|
|||
|
||||
pub fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
|
||||
user_
|
||||
.filter(deleted.eq(false))
|
||||
.filter(local.eq(true))
|
||||
.filter(email.eq(from_email))
|
||||
.first::<User_>(conn)
|
||||
|
@ -177,6 +187,19 @@ impl User_ {
|
|||
.set(user_form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
pub fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
|
||||
diesel::update(user_.find(user_id))
|
||||
.set((
|
||||
preferred_username.eq::<Option<String>>(None),
|
||||
email.eq::<Option<String>>(None),
|
||||
matrix_user_id.eq::<Option<String>>(None),
|
||||
bio.eq::<Option<String>>(None),
|
||||
deleted.eq(true),
|
||||
updated.eq(naive_now()),
|
||||
))
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
1
migrations/2020-11-26-134531_delete_user/down.sql
Normal file
1
migrations/2020-11-26-134531_delete_user/down.sql
Normal file
|
@ -0,0 +1 @@
|
|||
ALTER TABLE user_ DROP COLUMN deleted;
|
1
migrations/2020-11-26-134531_delete_user/up.sql
Normal file
1
migrations/2020-11-26-134531_delete_user/up.sql
Normal file
|
@ -0,0 +1 @@
|
|||
ALTER TABLE user_ ADD COLUMN deleted BOOLEAN DEFAULT FALSE NOT NULL;
|
Loading…
Reference in a new issue