fix: delete memberships when community is deleted from account deletion
This commit is contained in:
parent
3706764437
commit
9ce1161361
4 changed files with 28 additions and 13 deletions
|
@ -226,7 +226,7 @@
|
|||
</button>
|
||||
</div>
|
||||
|
||||
<div class="w-full flex flex-col gap-2" data-tab="account/security">
|
||||
<div class="w-full flex flex-col gap-2 hidden" data-tab="account/security">
|
||||
<div class="card tertiary flex flex-col gap-2">
|
||||
<a href="#/account" class="button secondary">
|
||||
{{ icon "arrow-left" }}
|
||||
|
@ -352,7 +352,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-full flex flex-col gap-2" data-tab="account/blocks">
|
||||
<div class="w-full flex flex-col gap-2 hidden" data-tab="account/blocks">
|
||||
<div class="card tertiary flex flex-col gap-2">
|
||||
<a href="#/account" class="button secondary">
|
||||
{{ icon "arrow-left" }}
|
||||
|
@ -391,7 +391,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-full flex flex-col gap-2" data-tab="account/billing">
|
||||
<div class="w-full flex flex-col gap-2 hidden" data-tab="account/billing">
|
||||
<div class="card tertiary flex flex-col gap-2">
|
||||
<a href="#/account" class="button secondary">
|
||||
{{ icon "arrow-left" }}
|
||||
|
|
|
@ -73,7 +73,7 @@ pub async fn delete_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.delete_community(id, user).await {
|
||||
match data.delete_community(id, &user).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Community deleted".to_string(),
|
||||
|
|
|
@ -208,14 +208,8 @@ impl DataManager {
|
|||
self.cache_clear_user(&user).await;
|
||||
|
||||
// delete communities
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"DELETE FROM communities WHERE owner = $1",
|
||||
&[&(id as i64)]
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
for community in self.get_communities_by_owner(user.id).await? {
|
||||
self.delete_community(community.id, &user).await?;
|
||||
}
|
||||
|
||||
// delete memberships
|
||||
|
|
|
@ -176,6 +176,27 @@ impl DataManager {
|
|||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all communities by their owner.
|
||||
pub async fn get_communities_by_owner(&self, id: usize) -> Result<Vec<Community>> {
|
||||
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 communities WHERE owner = $1",
|
||||
params![&(id as i64)],
|
||||
|x| { Self::get_community_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("communities".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Create a new community in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
|
@ -287,7 +308,7 @@ impl DataManager {
|
|||
.await;
|
||||
}
|
||||
|
||||
pub async fn delete_community(&self, id: usize, user: User) -> Result<()> {
|
||||
pub async fn delete_community(&self, id: usize, user: &User) -> Result<()> {
|
||||
let y = self.get_community_by_id(id).await?;
|
||||
|
||||
if user.id != y.owner {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue