mirror of https://github.com/LemmyNet/lemmy.git
Making sure there's at least one admin. Fixing unit tests
parent
60e352bb51
commit
4fa0a3ae08
|
@ -477,6 +477,12 @@ impl Perform for LeaveAdmin {
|
||||||
|
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
|
// Make sure there isn't just one admin (so if one leaves, there will still be one left)
|
||||||
|
let admins = blocking(context.pool(), PersonViewSafe::admins).await??;
|
||||||
|
if admins.len() == 1 {
|
||||||
|
return Err(LemmyError::from_message("cannot_leave_admin"));
|
||||||
|
}
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
Person::leave_admin(conn, person_id)
|
Person::leave_admin(conn, person_id)
|
||||||
|
|
|
@ -132,7 +132,12 @@ mod tests {
|
||||||
let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
|
let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
let after_delete = SiteAggregates::read(&conn);
|
// Site should still exist, it can without a site creator.
|
||||||
assert!(after_delete.is_err());
|
let after_delete_creator = SiteAggregates::read(&conn);
|
||||||
|
assert!(after_delete_creator.is_ok());
|
||||||
|
|
||||||
|
Site::delete(&conn, 1).unwrap();
|
||||||
|
let after_delete_site = SiteAggregates::read(&conn);
|
||||||
|
assert!(after_delete_site.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue