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)
}
};
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)
}
};
pub public_key: Option<String>,
pub last_refreshed_at: chrono::NaiveDateTime,
pub banner: Option<String>,
+ pub deleted: bool,
}
#[derive(Insertable, AsChangeset, Clone)]
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)
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)
}
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(
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)
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)
.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)]