From 4b4b99aa78b78326835b4b7f50b291ced6be5df7 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:47:28 +0000 Subject: [PATCH] Allow community mods to see votes in addition to admins (#4392) * Allow community mods to see votes in addition to admins * Use Post instead of PostView --------- Co-authored-by: SleeplessOne1917 --- crates/api/src/comment/list_comment_likes.rs | 18 ++++++++++++++---- crates/api/src/post/list_post_likes.rs | 12 +++++++++--- crates/federate/src/worker.rs | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/crates/api/src/comment/list_comment_likes.rs b/crates/api/src/comment/list_comment_likes.rs index cb487c9f1..b442cce23 100644 --- a/crates/api/src/comment/list_comment_likes.rs +++ b/crates/api/src/comment/list_comment_likes.rs @@ -2,9 +2,9 @@ use actix_web::web::{Data, Json, Query}; use lemmy_api_common::{ comment::{ListCommentLikes, ListCommentLikesResponse}, context::LemmyContext, - utils::is_admin, + utils::is_mod_or_admin, }; -use lemmy_db_views::structs::{LocalUserView, VoteView}; +use lemmy_db_views::structs::{CommentView, LocalUserView, VoteView}; use lemmy_utils::error::LemmyError; /// Lists likes for a comment @@ -14,8 +14,18 @@ pub async fn list_comment_likes( context: Data, local_user_view: LocalUserView, ) -> Result, LemmyError> { - // Make sure user is an admin - is_admin(&local_user_view)?; + let comment_view = CommentView::read( + &mut context.pool(), + data.comment_id, + Some(local_user_view.person.id), + ) + .await?; + is_mod_or_admin( + &mut context.pool(), + &local_user_view.person, + comment_view.community.id, + ) + .await?; let comment_likes = VoteView::list_for_comment(&mut context.pool(), data.comment_id, data.page, data.limit).await?; diff --git a/crates/api/src/post/list_post_likes.rs b/crates/api/src/post/list_post_likes.rs index 0e52052df..84690a41b 100644 --- a/crates/api/src/post/list_post_likes.rs +++ b/crates/api/src/post/list_post_likes.rs @@ -2,8 +2,9 @@ use actix_web::web::{Data, Json, Query}; use lemmy_api_common::{ context::LemmyContext, post::{ListPostLikes, ListPostLikesResponse}, - utils::is_admin, + utils::is_mod_or_admin, }; +use lemmy_db_schema::{source::post::Post, traits::Crud}; use lemmy_db_views::structs::{LocalUserView, VoteView}; use lemmy_utils::error::LemmyError; @@ -14,8 +15,13 @@ pub async fn list_post_likes( context: Data, local_user_view: LocalUserView, ) -> Result, LemmyError> { - // Make sure user is an admin - is_admin(&local_user_view)?; + let post = Post::read(&mut context.pool(), data.post_id).await?; + is_mod_or_admin( + &mut context.pool(), + &local_user_view.person, + post.community_id, + ) + .await?; let post_likes = VoteView::list_for_post(&mut context.pool(), data.post_id, data.page, data.limit).await?; diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index b57c5e8ae..0155ecd9b 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -296,7 +296,7 @@ impl InstanceWorker { } if let Some(t) = &activity.send_community_followers_of { if let Some(urls) = self.followed_communities.get(t) { - inbox_urls.extend(urls.iter().map(std::clone::Clone::clone)); + inbox_urls.extend(urls.iter().cloned()); } } inbox_urls.extend(