diff --git a/crates/app/src/public/html/profile/settings.html b/crates/app/src/public/html/profile/settings.html
index 94872d1..de323d0 100644
--- a/crates/app/src/public/html/profile/settings.html
+++ b/crates/app/src/public/html/profile/settings.html
@@ -226,7 +226,7 @@
-
+
-
+
-
+
{{ icon "arrow-left" }}
diff --git a/crates/app/src/routes/api/v1/communities/communities.rs b/crates/app/src/routes/api/v1/communities/communities.rs
index 10bf691..6baa276 100644
--- a/crates/app/src/routes/api/v1/communities/communities.rs
+++ b/crates/app/src/routes/api/v1/communities/communities.rs
@@ -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(),
diff --git a/crates/core/src/database/auth.rs b/crates/core/src/database/auth.rs
index 1f7abb1..0a919da 100644
--- a/crates/core/src/database/auth.rs
+++ b/crates/core/src/database/auth.rs
@@ -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
diff --git a/crates/core/src/database/communities.rs b/crates/core/src/database/communities.rs
index 2b2087e..542d1c4 100644
--- a/crates/core/src/database/communities.rs
+++ b/crates/core/src/database/communities.rs
@@ -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> {
+ 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 {