From c506d8e63c7f150348c19e0387d90d248647fd91 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:35:22 -0500 Subject: [PATCH] Touch up communities --- crates/api/src/community/add_mod.rs | 16 ++- crates/api/src/community/ban.rs | 28 ++-- crates/api/src/community/follow.rs | 13 +- crates/api/src/community/hide.rs | 8 +- .../api/src/community/pending_follows/list.rs | 5 +- crates/api/src/community/transfer.rs | 15 +- crates/api_crud/src/community/delete.rs | 10 +- crates/api_crud/src/community/remove.rs | 8 +- crates/api_crud/src/community/update.rs | 14 +- crates/apub/src/api/read_community.rs | 31 ++--- docker/docker-compose.yml | 8 +- src/api_routes_v4.rs | 130 +++++++----------- 12 files changed, 129 insertions(+), 157 deletions(-) diff --git a/crates/api/src/community/add_mod.rs b/crates/api/src/community/add_mod.rs index 4c5b4eae5..f781ab4a3 100644 --- a/crates/api/src/community/add_mod.rs +++ b/crates/api/src/community/add_mod.rs @@ -1,5 +1,5 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use lemmy_api_common::{ community::{AddModToCommunity, AddModToCommunityResponse}, context::LemmyContext, @@ -7,6 +7,7 @@ use lemmy_api_common::{ utils::check_community_mod_action, }; use lemmy_db_schema::{ + newtypes::CommunityId, source::{ community::{Community, CommunityModerator, CommunityModeratorForm}, local_user::LocalUser, @@ -23,8 +24,10 @@ pub async fn add_mod_to_community( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { - let community = Community::read(&mut context.pool(), data.community_id).await?; + let community_id = path.into_inner(); + let community = Community::read(&mut context.pool(), community_id).await?; // Verify that only mods or admins can add mod check_community_mod_action( &local_user_view.person, @@ -38,7 +41,7 @@ pub async fn add_mod_to_community( if !data.added { LocalUser::is_higher_mod_or_admin_check( &mut context.pool(), - community.id, + community_id, local_user_view.person.id, vec![data.person_id], ) @@ -59,7 +62,7 @@ pub async fn add_mod_to_community( // Update in local database let community_moderator_form = CommunityModeratorForm { - community_id: data.community_id, + community_id, person_id: data.person_id, }; if data.added { @@ -76,7 +79,7 @@ pub async fn add_mod_to_community( let form = ModAddCommunityForm { mod_person_id: local_user_view.person.id, other_person_id: data.person_id, - community_id: data.community_id, + community_id, removed: Some(!data.added), }; @@ -84,13 +87,12 @@ pub async fn add_mod_to_community( // Note: in case a remote mod is added, this returns the old moderators list, it will only get // updated once we receive an activity from the community (like `Announce/Add/Moderator`) - let community_id = data.community_id; let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?; ActivityChannel::submit_activity( SendActivityData::AddModToCommunity { moderator: local_user_view.person, - community_id: data.community_id, + community_id, target: data.person_id, added: data.added, }, diff --git a/crates/api/src/community/ban.rs b/crates/api/src/community/ban.rs index 547838fa7..65ea21ba2 100644 --- a/crates/api/src/community/ban.rs +++ b/crates/api/src/community/ban.rs @@ -1,22 +1,18 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use lemmy_api_common::{ community::{BanFromCommunity, BanFromCommunityResponse}, context::LemmyContext, send_activity::{ActivityChannel, SendActivityData}, utils::{ - check_community_mod_action, - check_expire_time, - remove_or_restore_user_data_in_community, + check_community_mod_action, check_expire_time, remove_or_restore_user_data_in_community, }, }; use lemmy_db_schema::{ + newtypes::CommunityId, source::{ community::{ - Community, - CommunityFollower, - CommunityFollowerForm, - CommunityPersonBan, + Community, CommunityFollower, CommunityFollowerForm, CommunityPersonBan, CommunityPersonBanForm, }, local_user::LocalUser, @@ -36,10 +32,12 @@ pub async fn ban_from_community( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { + let community_id = path.into_inner(); let banned_person_id = data.person_id; let expires = check_expire_time(data.expires)?; - let community = Community::read(&mut context.pool(), data.community_id).await?; + let community = Community::read(&mut context.pool(), community_id).await?; // Verify that only mods or admins can ban check_community_mod_action( @@ -52,7 +50,7 @@ pub async fn ban_from_community( LocalUser::is_higher_mod_or_admin_check( &mut context.pool(), - data.community_id, + community_id, local_user_view.person.id, vec![data.person_id], ) @@ -63,7 +61,7 @@ pub async fn ban_from_community( } let community_user_ban_form = CommunityPersonBanForm { - community_id: data.community_id, + community_id, person_id: data.person_id, expires: Some(expires), }; @@ -74,7 +72,7 @@ pub async fn ban_from_community( .with_lemmy_type(LemmyErrorType::CommunityUserAlreadyBanned)?; // Also unsubscribe them from the community, if they are subscribed - let community_follower_form = CommunityFollowerForm::new(data.community_id, banned_person_id); + let community_follower_form = CommunityFollowerForm::new(community_id, banned_person_id); CommunityFollower::unfollow(&mut context.pool(), &community_follower_form) .await .ok(); @@ -88,7 +86,7 @@ pub async fn ban_from_community( if data.remove_or_restore_data.unwrap_or(false) { let remove_data = data.ban; remove_or_restore_user_data_in_community( - data.community_id, + community_id, local_user_view.person.id, banned_person_id, remove_data, @@ -102,7 +100,7 @@ pub async fn ban_from_community( let form = ModBanFromCommunityForm { mod_person_id: local_user_view.person.id, other_person_id: data.person_id, - community_id: data.community_id, + community_id, reason: data.reason.clone(), banned: Some(data.ban), expires, @@ -115,7 +113,7 @@ pub async fn ban_from_community( ActivityChannel::submit_activity( SendActivityData::BanFromCommunity { moderator: local_user_view.person, - community_id: data.community_id, + community_id, target: person_view.person.clone(), data: data.0.clone(), }, diff --git a/crates/api/src/community/follow.rs b/crates/api/src/community/follow.rs index d5cd3e5b1..5c2ffabb5 100644 --- a/crates/api/src/community/follow.rs +++ b/crates/api/src/community/follow.rs @@ -1,5 +1,5 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use lemmy_api_common::{ community::{CommunityResponse, FollowCommunity}, context::LemmyContext, @@ -7,6 +7,7 @@ use lemmy_api_common::{ utils::{check_community_deleted_removed, check_user_valid}, }; use lemmy_db_schema::{ + newtypes::CommunityId, source::{ actor_language::CommunityLanguage, community::{Community, CommunityFollower, CommunityFollowerForm, CommunityFollowerState}, @@ -23,10 +24,12 @@ pub async fn follow_community( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { + let community_id = path.into_inner(); check_user_valid(&local_user_view.person)?; - let community = Community::read(&mut context.pool(), data.community_id).await?; - let form = CommunityFollowerForm::new(community.id, local_user_view.person.id); + let community = Community::read(&mut context.pool(), community_id).await?; + let form = CommunityFollowerForm::new(community_id, local_user_view.person.id); if data.follow { // Only run these checks for local community, in case of remote community the local @@ -34,7 +37,7 @@ pub async fn follow_community( // actions from existing followers for private community (so following would be impossible). if community.local { check_community_deleted_removed(&community)?; - CommunityPersonBanView::check(&mut context.pool(), local_user_view.person.id, community.id) + CommunityPersonBanView::check(&mut context.pool(), local_user_view.person.id, community_id) .await?; } @@ -51,7 +54,7 @@ pub async fn follow_community( let form = CommunityFollowerForm { state, - ..CommunityFollowerForm::new(community.id, local_user_view.person.id) + ..CommunityFollowerForm::new(community_id, local_user_view.person.id) }; // Write to db diff --git a/crates/api/src/community/hide.rs b/crates/api/src/community/hide.rs index f494ad732..1dfb05e9a 100644 --- a/crates/api/src/community/hide.rs +++ b/crates/api/src/community/hide.rs @@ -1,5 +1,5 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use lemmy_api_common::{ community::HideCommunity, context::LemmyContext, @@ -8,6 +8,7 @@ use lemmy_api_common::{ SuccessResponse, }; use lemmy_db_schema::{ + newtypes::CommunityId, source::{ community::{Community, CommunityUpdateForm}, mod_log::moderator::{ModHideCommunity, ModHideCommunityForm}, @@ -22,7 +23,9 @@ pub async fn hide_community( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { + let community_id = path.into_inner(); // Verify its a admin (only admin can hide or unhide it) is_admin(&local_user_view)?; @@ -32,13 +35,12 @@ pub async fn hide_community( }; let mod_hide_community_form = ModHideCommunityForm { - community_id: data.community_id, + community_id: community_id, mod_person_id: local_user_view.person.id, reason: data.reason.clone(), hidden: Some(data.hidden), }; - let community_id = data.community_id; let community = Community::update(&mut context.pool(), community_id, &community_form) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateCommunityHiddenStatus)?; diff --git a/crates/api/src/community/pending_follows/list.rs b/crates/api/src/community/pending_follows/list.rs index 9f300a74f..e48a9dae7 100644 --- a/crates/api/src/community/pending_follows/list.rs +++ b/crates/api/src/community/pending_follows/list.rs @@ -1,9 +1,10 @@ -use actix_web::web::{Data, Json, Query}; +use actix_web::web::{Data, Json, Path, Query}; use lemmy_api_common::{ community::{ListCommunityPendingFollows, ListCommunityPendingFollowsResponse}, context::LemmyContext, utils::check_community_mod_of_any_or_admin_action, }; +use lemmy_db_schema::newtypes::CommunityId; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::CommunityFollowerView; use lemmy_utils::error::LemmyResult; @@ -12,7 +13,9 @@ pub async fn get_pending_follows_list( data: Query, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { + let community_id = path.into_inner(); check_community_mod_of_any_or_admin_action(&local_user_view, &mut context.pool()).await?; let all_communities = data.all_communities.unwrap_or_default() && local_user_view.local_user.admin; diff --git a/crates/api/src/community/transfer.rs b/crates/api/src/community/transfer.rs index e60b50aa2..cb7916857 100644 --- a/crates/api/src/community/transfer.rs +++ b/crates/api/src/community/transfer.rs @@ -1,4 +1,4 @@ -use actix_web::web::{Data, Json}; +use actix_web::web::{Data, Json, Path}; use anyhow::Context; use lemmy_api_common::{ community::{GetCommunityResponse, TransferCommunity}, @@ -6,6 +6,7 @@ use lemmy_api_common::{ utils::{check_community_user_action, is_admin, is_top_mod}, }; use lemmy_db_schema::{ + newtypes::CommunityId, source::{ community::{Community, CommunityModerator, CommunityModeratorForm}, mod_log::moderator::{ModTransferCommunity, ModTransferCommunityForm}, @@ -26,10 +27,12 @@ pub async fn transfer_community( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { - let community = Community::read(&mut context.pool(), data.community_id).await?; + let community_id = path.into_inner(); + let community = Community::read(&mut context.pool(), community_id).await?; let mut community_mods = - CommunityModeratorView::for_community(&mut context.pool(), community.id).await?; + CommunityModeratorView::for_community(&mut context.pool(), community_id).await?; check_community_user_action(&local_user_view.person, &community, &mut context.pool()).await?; @@ -49,8 +52,6 @@ pub async fn transfer_community( community_mods.insert(0, creator_person); // Delete all the mods - let community_id = data.community_id; - CommunityModerator::delete_for_community(&mut context.pool(), community_id).await?; // TODO: this should probably be a bulk operation @@ -70,12 +71,11 @@ pub async fn transfer_community( let form = ModTransferCommunityForm { mod_person_id: local_user_view.person.id, other_person_id: data.person_id, - community_id: data.community_id, + community_id, }; ModTransferCommunity::create(&mut context.pool(), &form).await?; - let community_id = data.community_id; let community_view = CommunityView::read( &mut context.pool(), community_id, @@ -84,7 +84,6 @@ pub async fn transfer_community( ) .await?; - let community_id = data.community_id; let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?; // Return the jwt diff --git a/crates/api_crud/src/community/delete.rs b/crates/api_crud/src/community/delete.rs index 7f9d04933..939386130 100644 --- a/crates/api_crud/src/community/delete.rs +++ b/crates/api_crud/src/community/delete.rs @@ -1,5 +1,5 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use lemmy_api_common::{ build_response::build_community_response, community::{CommunityResponse, DeleteCommunity}, @@ -8,6 +8,7 @@ use lemmy_api_common::{ utils::{check_community_mod_action, is_top_mod}, }; use lemmy_db_schema::{ + newtypes::CommunityId, source::community::{Community, CommunityUpdateForm}, traits::Crud, }; @@ -20,12 +21,14 @@ pub async fn delete_community( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { + let community_id = path.into_inner(); // Fetch the community mods let community_mods = - CommunityModeratorView::for_community(&mut context.pool(), data.community_id).await?; + CommunityModeratorView::for_community(&mut context.pool(), community_id).await?; - let community = Community::read(&mut context.pool(), data.community_id).await?; + let community = Community::read(&mut context.pool(), community_id).await?; check_community_mod_action( &local_user_view.person, &community, @@ -38,7 +41,6 @@ pub async fn delete_community( is_top_mod(&local_user_view, &community_mods)?; // Do the delete - let community_id = data.community_id; let deleted = data.deleted; let community = Community::update( &mut context.pool(), diff --git a/crates/api_crud/src/community/remove.rs b/crates/api_crud/src/community/remove.rs index 7dc78a37a..dfc64cba9 100644 --- a/crates/api_crud/src/community/remove.rs +++ b/crates/api_crud/src/community/remove.rs @@ -1,5 +1,5 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use lemmy_api_common::{ build_response::build_community_response, community::{CommunityResponse, RemoveCommunity}, @@ -8,6 +8,7 @@ use lemmy_api_common::{ utils::{check_community_mod_action, is_admin}, }; use lemmy_db_schema::{ + newtypes::CommunityId, source::{ community::{Community, CommunityUpdateForm}, mod_log::moderator::{ModRemoveCommunity, ModRemoveCommunityForm}, @@ -22,8 +23,10 @@ pub async fn remove_community( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { - let community = Community::read(&mut context.pool(), data.community_id).await?; + let community_id = path.into_inner(); + let community = Community::read(&mut context.pool(), community_id).await?; check_community_mod_action( &local_user_view.person, &community, @@ -36,7 +39,6 @@ pub async fn remove_community( is_admin(&local_user_view)?; // Do the remove - let community_id = data.community_id; let removed = data.removed; let community = Community::update( &mut context.pool(), diff --git a/crates/api_crud/src/community/update.rs b/crates/api_crud/src/community/update.rs index d9c062c53..87f7b2f0a 100644 --- a/crates/api_crud/src/community/update.rs +++ b/crates/api_crud/src/community/update.rs @@ -1,6 +1,6 @@ use super::check_community_visibility_allowed; use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use chrono::Utc; use lemmy_api_common::{ build_response::build_community_response, @@ -9,14 +9,12 @@ use lemmy_api_common::{ request::replace_image, send_activity::{ActivityChannel, SendActivityData}, utils::{ - check_community_mod_action, - get_url_blocklist, - local_site_to_slur_regex, - process_markdown_opt, + check_community_mod_action, get_url_blocklist, local_site_to_slur_regex, process_markdown_opt, proxy_image_link_opt_api, }, }; use lemmy_db_schema::{ + newtypes::CommunityId, source::{ actor_language::{CommunityLanguage, SiteLanguage}, community::{Community, CommunityUpdateForm}, @@ -36,7 +34,9 @@ pub async fn update_community( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { + let community_id = path.into_inner(); let local_site = LocalSite::read(&mut context.pool()).await?; let slur_regex = local_site_to_slur_regex(&local_site); @@ -56,7 +56,7 @@ pub async fn update_community( check_community_visibility_allowed(data.visibility, &local_user_view)?; let description = diesel_string_update(data.description.as_deref()); - let old_community = Community::read(&mut context.pool(), data.community_id).await?; + let old_community = Community::read(&mut context.pool(), community_id).await?; let icon = diesel_url_update(data.icon.as_deref())?; replace_image(&icon, &old_community.icon, &context).await?; @@ -75,7 +75,6 @@ pub async fn update_community( ) .await?; - let community_id = data.community_id; if let Some(languages) = data.discussion_languages.clone() { let site_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?; // check that community languages are a subset of site languages @@ -100,7 +99,6 @@ pub async fn update_community( ..Default::default() }; - let community_id = data.community_id; let community = Community::update(&mut context.pool(), community_id, &community_form) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?; diff --git a/crates/apub/src/api/read_community.rs b/crates/apub/src/api/read_community.rs index f94769158..d69cd4c76 100644 --- a/crates/apub/src/api/read_community.rs +++ b/crates/apub/src/api/read_community.rs @@ -1,15 +1,13 @@ -use crate::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity}; use activitypub_federation::config::Data; -use actix_web::web::{Json, Query}; +use actix_web::web::{Json, Path, Query}; use lemmy_api_common::{ community::{GetCommunity, GetCommunityResponse}, context::LemmyContext, utils::{check_private_instance, is_mod_or_admin_opt, read_site_for_actor}, }; -use lemmy_db_schema::source::{ - actor_language::CommunityLanguage, - community::Community, - local_site::LocalSite, +use lemmy_db_schema::{ + newtypes::CommunityId, + source::{actor_language::CommunityLanguage, local_site::LocalSite}, }; use lemmy_db_views::structs::LocalUserView; use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView}; @@ -20,7 +18,9 @@ pub async fn get_community( data: Query, context: Data, local_user_view: Option, + path: Path, ) -> LemmyResult> { + let community_id = path.into_inner(); let local_site = LocalSite::read(&mut context.pool()).await?; if data.name.is_none() && data.id.is_none() { @@ -31,15 +31,15 @@ pub async fn get_community( let local_user = local_user_view.as_ref().map(|u| &u.local_user); - let community_id = match data.id { - Some(id) => id, - None => { - let name = data.name.clone().unwrap_or_else(|| "main".to_string()); - resolve_actor_identifier::(&name, &context, &local_user_view, true) - .await? - .id - } - }; + // let community_id = match data.id { + // Some(id) => id, + // None => { + // let name = data.name.clone().unwrap_or_else(|| "main".to_string()); + // resolve_actor_identifier::(&name, &context, &local_user_view, true) + // .await? + // .id + // } + // }; let is_mod_or_admin = is_mod_or_admin_opt( &mut context.pool(), @@ -61,7 +61,6 @@ pub async fn get_community( let site = read_site_for_actor(community_view.community.actor_id.clone(), &context).await?; - let community_id = community_view.community.id; let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?; Ok(Json(GetCommunityResponse { diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index cb438af3a..ebc2fbbe9 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -23,14 +23,14 @@ services: lemmy: # use "image" to pull down an already compiled lemmy. make sure to comment out "build". - # image: dessalines/lemmy:0.19.6 + image: dessalines/lemmy:0.19.6 # platform: linux/x86_64 # no arm64 support. uncomment platform if using m1. # use "build" to build your local lemmy server image for development. make sure to comment out "image". # run: docker compose up --build - build: - context: ../ - dockerfile: docker/Dockerfile + # build: + # context: ../ + # dockerfile: docker/Dockerfile # args: # RUST_RELEASE_MODE: release # CARGO_BUILD_FEATURES: default diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index a9f71c9da..ebcadad9c 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -1,15 +1,11 @@ use actix_web::{guard, web::*}; use lemmy_api::{ comment::{ - distinguish::distinguish_comment, - like::like_comment, - list_comment_likes::list_comment_likes, + distinguish::distinguish_comment, like::like_comment, list_comment_likes::list_comment_likes, save::save_comment, }, comment_report::{ - create::create_comment_report, - list::list_comment_reports, - resolve::resolve_comment_report, + create::create_comment_report, list::list_comment_reports, resolve::resolve_comment_report, }, community::{ add_mod::add_mod_to_community, @@ -18,8 +14,7 @@ use lemmy_api::{ follow::follow_community, hide::hide_community, pending_follows::{ - approve::post_pending_follows_approve, - count::get_pending_follows_count, + approve::post_pending_follows_approve, count::get_pending_follows_count, list::get_pending_follows_list, }, random::get_random_community, @@ -39,12 +34,9 @@ use lemmy_api::{ login::login, logout::logout, notifications::{ - list_mentions::list_mentions, - list_replies::list_replies, - mark_all_read::mark_all_notifications_read, - mark_mention_read::mark_person_mention_as_read, - mark_reply_read::mark_reply_as_read, - unread_count::unread_count, + list_mentions::list_mentions, list_replies::list_replies, + mark_all_read::mark_all_notifications_read, mark_mention_read::mark_person_mention_as_read, + mark_reply_read::mark_reply_as_read, unread_count::unread_count, }, report_count::report_count, reset_password::reset_password, @@ -55,26 +47,16 @@ use lemmy_api::{ verify_email::verify_email, }, post::{ - feature::feature_post, - get_link_metadata::get_link_metadata, - hide::hide_post, - like::like_post, - list_post_likes::list_post_likes, - lock::lock_post, - mark_many_read::mark_posts_as_read, - mark_read::mark_post_as_read, - save::save_post, + feature::feature_post, get_link_metadata::get_link_metadata, hide::hide_post, like::like_post, + list_post_likes::list_post_likes, lock::lock_post, mark_many_read::mark_posts_as_read, + mark_read::mark_post_as_read, save::save_post, }, post_report::{ - create::create_post_report, - list::list_post_reports, - resolve::resolve_post_report, + create::create_post_report, list::list_post_reports, resolve::resolve_post_report, }, private_message::mark_read::mark_pm_as_read, private_message_report::{ - create::create_pm_report, - list::list_pm_reports, - resolve::resolve_pm_report, + create::create_pm_report, list::list_pm_reports, resolve::resolve_pm_report, }, site::{ admin_allow_instance::admin_allow_instance, @@ -84,14 +66,10 @@ use lemmy_api::{ list_all_media::list_all_media, mod_log::get_mod_log, purge::{ - comment::purge_comment, - community::purge_community, - person::purge_person, - post::purge_post, + comment::purge_comment, community::purge_community, person::purge_person, post::purge_post, }, registration_applications::{ - approve::approve_registration_application, - get::get_registration_application, + approve::approve_registration_application, get::get_registration_application, list::list_registration_applications, unread_count::get_unread_registration_application_count, }, @@ -100,49 +78,31 @@ use lemmy_api::{ }; use lemmy_api_crud::{ comment::{ - create::create_comment, - delete::delete_comment, - read::get_comment, - remove::remove_comment, + create::create_comment, delete::delete_comment, read::get_comment, remove::remove_comment, update::update_comment, }, community::{ - create::create_community, - delete::delete_community, - list::list_communities, - remove::remove_community, - update::update_community, + create::create_community, delete::delete_community, list::list_communities, + remove::remove_community, update::update_community, }, custom_emoji::{ - create::create_custom_emoji, - delete::delete_custom_emoji, - list::list_custom_emojis, + create::create_custom_emoji, delete::delete_custom_emoji, list::list_custom_emojis, update::update_custom_emoji, }, oauth_provider::{ - create::create_oauth_provider, - delete::delete_oauth_provider, - update::update_oauth_provider, + create::create_oauth_provider, delete::delete_oauth_provider, update::update_oauth_provider, }, post::{ - create::create_post, - delete::delete_post, - read::get_post, - remove::remove_post, + create::create_post, delete::delete_post, read::get_post, remove::remove_post, update::update_post, }, private_message::{ - create::create_private_message, - delete::delete_private_message, - read::get_private_message, + create::create_private_message, delete::delete_private_message, read::get_private_message, update::update_private_message, }, site::{create::create_site, read::get_site_v4, update::update_site}, tagline::{ - create::create_tagline, - delete::delete_tagline, - list::list_taglines, - update::update_tagline, + create::create_tagline, delete::delete_tagline, list::list_taglines, update::update_tagline, }, user::{ create::{authenticate_with_oauth, register}, @@ -183,30 +143,34 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { .route("/resolve_object", get().to(resolve_object)) // Community .service( - resource("/community") - .guard(guard::Post()) - .wrap(rate_limit.register()) - .route(post().to(create_community)), - ) - .service( - scope("/community") - .route("", get().to(get_community)) - .route("", put().to(update_community)) + scope("/communities") + .route("", get().to(list_communities)) .route("/random", get().to(get_random_community)) - .route("/hide", put().to(hide_community)) - .route("/list", get().to(list_communities)) - .route("/follow", post().to(follow_community)) - .route("/delete", post().to(delete_community)) - // Mod Actions - .route("/remove", post().to(remove_community)) - .route("/transfer", post().to(transfer_community)) - .route("/ban_user", post().to(ban_from_community)) - .route("/mod", post().to(add_mod_to_community)) .service( - scope("/pending_follows") - .route("/count", get().to(get_pending_follows_count)) - .route("/list", get().to(get_pending_follows_list)) - .route("/approve", post().to(post_pending_follows_approve)), + resource("") + .guard(guard::Post()) + .wrap(rate_limit.register()) + .route(post().to(create_community)), + ) + .service( + scope("/{community_id}") + .route("", put().to(update_community)) + .route("", get().to(get_community)) + .route("", delete().to(delete_community)) + .route("/hide", put().to(hide_community)) + .route("/follow", post().to(follow_community)) + // Mod Actions + .route("/remove", post().to(remove_community)) + .route("/transfer", post().to(transfer_community)) + .route("/ban_user", post().to(ban_from_community)) + .route("/mod", post().to(add_mod_to_community)) + .service( + // TODO: Not sure what to do with these + scope("/pending_follows") + .route("", get().to(get_pending_follows_list)) + .route("/count", get().to(get_pending_follows_count)) + .route("/approve", post().to(post_pending_follows_approve)), + ), ), ) .route("/federated_instances", get().to(get_federated_instances))