Merge pull request #1399 from LemmyNet/dont_let_banned_users_follow

Make sure banned users cant subscribe, and the ban unsubs them. Fixes…
This commit is contained in:
Nutomic 2021-02-01 12:19:41 +00:00 committed by GitHub
commit c8254dc0a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
use crate::{ use crate::{
check_community_ban,
check_optional_url, check_optional_url,
get_user_from_jwt, get_user_from_jwt,
get_user_from_jwt_opt, get_user_from_jwt_opt,
@ -495,6 +496,8 @@ impl Perform for FollowCommunity {
if community.local { if community.local {
if data.follow { if data.follow {
check_community_ban(user.id, community_id, context.pool()).await?;
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form); let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
if blocking(context.pool(), follow).await?.is_err() { if blocking(context.pool(), follow).await?.is_err() {
return Err(APIError::err("community_follower_already_exists").into()); return Err(APIError::err("community_follower_already_exists").into());
@ -591,6 +594,18 @@ impl Perform for BanFromCommunity {
if blocking(context.pool(), ban).await?.is_err() { if blocking(context.pool(), ban).await?.is_err() {
return Err(APIError::err("community_user_already_banned").into()); return Err(APIError::err("community_user_already_banned").into());
} }
// Also unsubscribe them from the community, if they are subscribed
let community_follower_form = CommunityFollowerForm {
community_id: data.community_id,
user_id: banned_user_id,
pending: false,
};
blocking(context.pool(), move |conn: &'_ _| {
CommunityFollower::unfollow(conn, &community_follower_form)
})
.await?
.ok();
} else { } else {
let unban = move |conn: &'_ _| CommunityUserBan::unban(conn, &community_user_ban_form); let unban = move |conn: &'_ _| CommunityUserBan::unban(conn, &community_user_ban_form);
if blocking(context.pool(), unban).await?.is_err() { if blocking(context.pool(), unban).await?.is_err() {