mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-08 09:24:17 +00:00
Making sure there's at least one admin. Fixing unit tests
This commit is contained in:
parent
60e352bb51
commit
4fa0a3ae08
|
@ -477,6 +477,12 @@ impl Perform for LeaveAdmin {
|
|||
|
||||
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;
|
||||
blocking(context.pool(), move |conn| {
|
||||
Person::leave_admin(conn, person_id)
|
||||
|
|
|
@ -132,7 +132,12 @@ mod tests {
|
|||
let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
|
||||
assert_eq!(1, community_num_deleted);
|
||||
|
||||
let after_delete = SiteAggregates::read(&conn);
|
||||
assert!(after_delete.is_err());
|
||||
// Site should still exist, it can without a site creator.
|
||||
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 a new issue