Merge branch 'fix/add-check-to-create-site-endpoint' of https://github.com/eiknat/lemmy into eiknat-fix/add-check-to-create-site-endpoint

pull/1141/head
Dessalines 2020-09-16 08:13:19 -05:00
commit dd93ac49a3
1 changed files with 8 additions and 0 deletions

View File

@ -142,6 +142,12 @@ impl Perform for CreateSite {
) -> Result<SiteResponse, LemmyError> { ) -> Result<SiteResponse, LemmyError> {
let data: &CreateSite = &self; 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?; let user = get_user_from_jwt(&data.auth, context.pool()).await?;
check_slurs(&data.name)?; check_slurs(&data.name)?;
@ -490,6 +496,8 @@ impl Perform for TransferSite {
let data: &TransferSite = &self; let data: &TransferSite = &self;
let mut user = get_user_from_jwt(&data.auth, context.pool()).await?; 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. // TODO add a User_::read_safe() for this.
user.password_encrypted = "".to_string(); user.password_encrypted = "".to_string();
user.private_key = None; user.private_key = None;