From: eiknat Date: Wed, 16 Sep 2020 01:36:11 +0000 (-0400) Subject: api.site: check for existing site before creating X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/sneer-club-logo.svg?a=commitdiff_plain;h=d0fefca6f98c1b6b055a0c855823e913353af4a5;p=lemmy.git api.site: check for existing site before creating --- diff --git a/src/api/site.rs b/src/api/site.rs index 727078e2..1d17822e 100644 --- a/src/api/site.rs +++ b/src/api/site.rs @@ -141,6 +141,12 @@ impl Perform for CreateSite { ) -> Result { let data: &CreateSite = &self; + match blocking(context.pool(), move |conn| { Site::read(conn, 1)}).await? + { + Ok(_site) => return Err(APIError::err("site_already_exists").into()), + Err(_e) => (), + }; + let user = get_user_from_jwt(&data.auth, context.pool()).await?; check_slurs(&data.name)?; @@ -489,6 +495,8 @@ impl Perform for TransferSite { let data: &TransferSite = &self; let mut user = get_user_from_jwt(&data.auth, context.pool()).await?; + is_admin(context.pool(), user.id).await?; + // TODO add a User_::read_safe() for this. user.password_encrypted = "".to_string(); user.private_key = None;