-/// Verify that the actor is a community mod. This check is only run if the community is local,
-/// because in case of remote communities, admins can also perform mod actions. As admin status
-/// is not federated, we cant verify their actions remotely.
-pub(crate) async fn verify_mod_action(
- actor_id: &ObjectId<Person>,
- community_id: ObjectId<Community>,
- context: &LemmyContext,
-) -> Result<(), LemmyError> {
- let community = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, &community_id.into())
- })
- .await??;
-
- if community.local {
- let actor_id: DbUrl = actor_id.clone().into();
- let actor = blocking(context.pool(), move |conn| {
- Person::read_from_apub_id(conn, &actor_id)
- })
- .await??;
-
- // Note: this will also return true for admins in addition to mods, but as we dont know about
- // remote admins, it doesnt make any difference.
- let community_id = community.id;
- let actor_id = actor.id;
- let is_mod_or_admin = blocking(context.pool(), move |conn| {
- CommunityView::is_mod_or_admin(conn, actor_id, community_id)
- })
- .await?;
- if !is_mod_or_admin {
- return Err(anyhow!("Not a mod").into());
- }
+pub(crate) fn verify_community_matches<T>(
+ a: &ObjectId<ApubCommunity>,
+ b: T,
+) -> Result<(), LemmyError>
+where
+ T: Into<ObjectId<ApubCommunity>>,
+{
+ let b: ObjectId<ApubCommunity> = b.into();
+ if a != &b {
+ return Err(LemmyErrorType::InvalidCommunity)?;