add: delete uploads and polls when user is deleted
This commit is contained in:
parent
f6eb46e7e8
commit
40fce4bc77
6 changed files with 66 additions and 5 deletions
|
@ -1 +1,2 @@
|
|||
* me@trisua.com
|
||||
# * me@trisua.com
|
||||
* @t
|
||||
|
|
|
@ -416,6 +416,16 @@ impl DataManager {
|
|||
remove_file(banner).unwrap();
|
||||
}
|
||||
|
||||
// delete uploads
|
||||
for upload in self.get_uploads_by_owner_all(user.id).await? {
|
||||
self.delete_upload(upload.id).await?;
|
||||
}
|
||||
|
||||
// delete polls
|
||||
for poll in self.get_polls_by_owner_all(user.id).await? {
|
||||
self.delete_poll(poll.id, &user).await?;
|
||||
}
|
||||
|
||||
// ...
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -129,7 +129,9 @@ impl DataManager {
|
|||
}
|
||||
|
||||
// incr notification count
|
||||
self.incr_user_notifications(data.owner).await.unwrap();
|
||||
if let Err(e) = self.incr_user_notifications(data.owner).await {
|
||||
return Err(e);
|
||||
};
|
||||
|
||||
// post event
|
||||
let mut con = self.2.get_con().await;
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::cache::Cache;
|
|||
use crate::model::communities::Poll;
|
||||
use crate::model::moderation::AuditLogEntry;
|
||||
use crate::model::{Error, Result, auth::User, permissions::FinePermission};
|
||||
use crate::{auto_method, execute, get, query_row, params};
|
||||
use crate::{auto_method, execute, get, params, query_row, query_rows};
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
use rusqlite::Row;
|
||||
|
@ -35,6 +35,30 @@ impl DataManager {
|
|||
|
||||
auto_method!(get_poll_by_id()@get_poll_from_row -> "SELECT * FROM polls WHERE id = $1" --name="poll" --returns=Poll --cache-key-tmpl="atto.poll:{}");
|
||||
|
||||
/// Get all polls by their owner.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `owner` - the ID of the owner of the polls
|
||||
pub async fn get_polls_by_owner_all(&self, owner: usize) -> Result<Vec<Poll>> {
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM polls WHERE owner = $1 ORDER BY created DESC",
|
||||
&[&(owner as i64)],
|
||||
|x| { Self::get_poll_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("poll".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Create a new poll in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
|
@ -93,7 +117,7 @@ impl DataManager {
|
|||
Ok(data.id)
|
||||
}
|
||||
|
||||
pub async fn delete_poll(&self, id: usize, user: User) -> Result<()> {
|
||||
pub async fn delete_poll(&self, id: usize, user: &User) -> Result<()> {
|
||||
let y = self.get_poll_by_id(id).await?;
|
||||
|
||||
if user.id != y.owner {
|
||||
|
|
|
@ -1547,7 +1547,7 @@ impl DataManager {
|
|||
|
||||
// remove poll
|
||||
if y.poll_id != 0 {
|
||||
self.delete_poll(y.poll_id, user).await?;
|
||||
self.delete_poll(y.poll_id, &user).await?;
|
||||
}
|
||||
|
||||
// return
|
||||
|
|
|
@ -83,6 +83,30 @@ impl DataManager {
|
|||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all uploads by their owner.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `owner` - the ID of the owner of the upload
|
||||
pub async fn get_uploads_by_owner_all(&self, owner: usize) -> Result<Vec<MediaUpload>> {
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM uploads WHERE owner = $1 ORDER BY created DESC",
|
||||
&[&(owner as i64)],
|
||||
|x| { Self::get_upload_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("upload".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Create a new upload in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue