add: ability to join/leave/be banned from communities
This commit is contained in:
parent
f3c2157dfc
commit
619184d02e
28 changed files with 618 additions and 197 deletions
|
@ -51,13 +51,11 @@ pub async fn avatar_request(
|
|||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
|
||||
let user = match {
|
||||
if req.selector_type == AvatarSelectorType::Id {
|
||||
data.get_user_by_id(selector.parse::<usize>().unwrap())
|
||||
.await
|
||||
} else {
|
||||
data.get_user_by_username(&selector).await
|
||||
}
|
||||
let user = match if req.selector_type == AvatarSelectorType::Id {
|
||||
data.get_user_by_id(selector.parse::<usize>().unwrap())
|
||||
.await
|
||||
} else {
|
||||
data.get_user_by_username(&selector).await
|
||||
} {
|
||||
Ok(ua) => ua,
|
||||
Err(_) => {
|
||||
|
|
|
@ -18,7 +18,7 @@ pub async fn redirect_from_id(
|
|||
Extension(data): Extension<State>,
|
||||
Path(id): Path<String>,
|
||||
) -> impl IntoResponse {
|
||||
match (&(data.read().await).0)
|
||||
match (data.read().await).0
|
||||
.get_user_by_id(match id.parse::<usize>() {
|
||||
Ok(id) => id,
|
||||
Err(_) => return Redirect::to("/"),
|
||||
|
@ -43,10 +43,8 @@ pub async fn update_profile_settings_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.id != id {
|
||||
if !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
if user.id != id && !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
match data.update_user_settings(id, req).await {
|
||||
|
@ -72,10 +70,8 @@ pub async fn update_profile_password_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.id != id {
|
||||
if !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
if user.id != id && !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
match data
|
||||
|
@ -103,10 +99,8 @@ pub async fn update_profile_username_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.id != id {
|
||||
if !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
if user.id != id && !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
if data.get_user_by_username(&req.to).await.is_ok() {
|
||||
|
@ -136,10 +130,8 @@ pub async fn update_profile_tokens_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.id != id {
|
||||
if !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
if user.id != id && !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
match data.update_user_tokens(id, req).await {
|
||||
|
|
|
@ -26,7 +26,7 @@ pub async fn follow_request(
|
|||
message: "User unfollowed".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
} else {
|
||||
// create
|
||||
|
@ -36,7 +36,7 @@ pub async fn follow_request(
|
|||
message: "User followed".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ pub async fn block_request(
|
|||
message: "User unblocked".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
} else {
|
||||
// create
|
||||
|
@ -76,7 +76,7 @@ pub async fn block_request(
|
|||
message: "User unfollowed".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
} else {
|
||||
// not following user, don't do anything else
|
||||
|
@ -87,7 +87,7 @@ pub async fn block_request(
|
|||
})
|
||||
}
|
||||
}
|
||||
Err(e) => return Json(e.into()),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue