From 08a0a6d3cec958040132410039c69300e2a48bf9 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 27 Jul 2024 13:37:15 -0400 Subject: [PATCH] Adding deny unimplemented to clippy lints. - Context: #4782 --- Cargo.toml | 1 + crates/apub/src/activities/block/mod.rs | 14 ++++-- crates/apub/src/activities/deletion/delete.rs | 5 ++- .../src/activities/deletion/undo_delete.rs | 5 ++- crates/apub/src/activity_lists.rs | 5 ++- crates/apub/src/fetcher/post_or_comment.rs | 7 ++- crates/apub/src/fetcher/search.rs | 15 ++++++- .../src/fetcher/site_or_community_or_user.rs | 45 ++++++++++++++----- crates/apub/src/fetcher/user_or_community.rs | 12 +++-- crates/apub/src/objects/instance.rs | 2 +- crates/apub/src/objects/private_message.rs | 2 +- crates/apub/src/protocol/objects/page.rs | 5 ++- crates/db_schema/src/impls/comment.rs | 2 +- crates/db_schema/src/impls/person.rs | 5 ++- .../src/impls/private_message_report.rs | 2 +- crates/db_schema/src/impls/site.rs | 2 +- crates/utils/src/error.rs | 2 + 17 files changed, 95 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96c4e2800..31af67042 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,6 +86,7 @@ suspicious = { level = "deny", priority = -1 } uninlined_format_args = "allow" unused_self = "deny" unwrap_used = "deny" +unimplemented = "deny" [workspace.dependencies] lemmy_api = { version = "=0.19.5", path = "./crates/api" } diff --git a/crates/apub/src/activities/block/mod.rs b/crates/apub/src/activities/block/mod.rs index ced50e2de..228c29a77 100644 --- a/crates/apub/src/activities/block/mod.rs +++ b/crates/apub/src/activities/block/mod.rs @@ -74,12 +74,18 @@ impl Object for SiteOrCommunity { }) } - async fn delete(self, _data: &Data) -> LemmyResult<()> { - unimplemented!() + async fn delete(self, data: &Data) -> LemmyResult<()> { + match self { + SiteOrCommunity::Site(i) => i.delete(data).await, + SiteOrCommunity::Community(c) => c.delete(data).await, + } } - async fn into_json(self, _data: &Data) -> LemmyResult { - unimplemented!() + async fn into_json(self, data: &Data) -> LemmyResult { + Ok(match self { + SiteOrCommunity::Site(i) => InstanceOrGroup::Instance(i.into_json(data).await?), + SiteOrCommunity::Community(c) => InstanceOrGroup::Group(c.into_json(data).await?), + }) } #[tracing::instrument(skip_all)] diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index cecc051b4..d203aacf2 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -175,8 +175,9 @@ pub(in crate::activities) async fn receive_remove_action( ) .await?; } - DeletableObjects::PrivateMessage(_) => unimplemented!(), - DeletableObjects::Person { .. } => unimplemented!(), + // TODO these need to be implemented yet, for now, return errors + DeletableObjects::PrivateMessage(_) => Err(LemmyErrorType::CouldntFindPrivateMessage)?, + DeletableObjects::Person(_) => Err(LemmyErrorType::CouldntFindPerson)?, } Ok(()) } diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index 4f0fad670..b50580852 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -155,8 +155,9 @@ impl UndoDelete { ) .await?; } - DeletableObjects::PrivateMessage(_) => unimplemented!(), - DeletableObjects::Person { .. } => unimplemented!(), + // TODO these need to be implemented yet, for now, return errors + DeletableObjects::PrivateMessage(_) => Err(LemmyErrorType::CouldntFindPrivateMessage)?, + DeletableObjects::Person(_) => Err(LemmyErrorType::CouldntFindPerson)?, } Ok(()) } diff --git a/crates/apub/src/activity_lists.rs b/crates/apub/src/activity_lists.rs index 3aeb7e45e..2643dc6f4 100644 --- a/crates/apub/src/activity_lists.rs +++ b/crates/apub/src/activity_lists.rs @@ -26,7 +26,7 @@ use crate::{ }; use activitypub_federation::{config::Data, traits::ActivityHandler}; use lemmy_api_common::context::LemmyContext; -use lemmy_utils::error::LemmyResult; +use lemmy_utils::{error::LemmyResult, LemmyErrorType}; use serde::{Deserialize, Serialize}; use url::Url; @@ -117,7 +117,8 @@ impl InCommunity for AnnouncableActivities { CollectionRemove(a) => a.community(context).await, LockPost(a) => a.community(context).await, UndoLockPost(a) => a.community(context).await, - Page(_) => unimplemented!(), + // TODO this needs to be implemented + Page(_) => Err(LemmyErrorType::CouldntFindPost.into()), } } } diff --git a/crates/apub/src/fetcher/post_or_comment.rs b/crates/apub/src/fetcher/post_or_comment.rs index 083369b9d..e352e1257 100644 --- a/crates/apub/src/fetcher/post_or_comment.rs +++ b/crates/apub/src/fetcher/post_or_comment.rs @@ -61,8 +61,11 @@ impl Object for PostOrComment { } } - async fn into_json(self, _data: &Data) -> LemmyResult { - unimplemented!() + async fn into_json(self, data: &Data) -> LemmyResult { + Ok(match self { + PostOrComment::Post(p) => PageOrNote::Page(Box::new(p.into_json(data).await?)), + PostOrComment::Comment(c) => PageOrNote::Note(c.into_json(data).await?), + }) } #[tracing::instrument(skip_all)] diff --git a/crates/apub/src/fetcher/search.rs b/crates/apub/src/fetcher/search.rs index 8c533ba88..89c3cda8f 100644 --- a/crates/apub/src/fetcher/search.rs +++ b/crates/apub/src/fetcher/search.rs @@ -118,8 +118,19 @@ impl Object for SearchableObjects { } } - async fn into_json(self, _data: &Data) -> LemmyResult { - unimplemented!() + async fn into_json(self, data: &Data) -> LemmyResult { + Ok(match self { + SearchableObjects::Post(p) => SearchableKinds::Page(Box::new(p.into_json(data).await?)), + SearchableObjects::Comment(c) => SearchableKinds::Note(c.into_json(data).await?), + SearchableObjects::PersonOrCommunity(pc) => match *pc { + UserOrCommunity::User(p) => { + SearchableKinds::PersonOrGroup(Box::new(PersonOrGroup::Person(p.into_json(data).await?))) + } + UserOrCommunity::Community(c) => { + SearchableKinds::PersonOrGroup(Box::new(PersonOrGroup::Group(c.into_json(data).await?))) + } + }, + }) } #[tracing::instrument(skip_all)] diff --git a/crates/apub/src/fetcher/site_or_community_or_user.rs b/crates/apub/src/fetcher/site_or_community_or_user.rs index 30b5fd568..252d31ce3 100644 --- a/crates/apub/src/fetcher/site_or_community_or_user.rs +++ b/crates/apub/src/fetcher/site_or_community_or_user.rs @@ -1,6 +1,6 @@ use crate::{ fetcher::user_or_community::{PersonOrGroup, UserOrCommunity}, - objects::instance::ApubSite, + objects::{community::ApubCommunity, instance::ApubSite, person::ApubPerson}, protocol::objects::instance::Instance, }; use activitypub_federation::{ @@ -41,11 +41,14 @@ impl Object for SiteOrCommunityOrUser { } #[tracing::instrument(skip_all)] - async fn read_from_id( - _object_id: Url, - _data: &Data, - ) -> LemmyResult> { - unimplemented!(); + async fn read_from_id(object_id: Url, data: &Data) -> LemmyResult> { + let site = ApubSite::read_from_id(object_id.clone(), data).await?; + Ok(match site { + Some(o) => Some(SiteOrCommunityOrUser::Site(o)), + None => UserOrCommunity::read_from_id(object_id, data) + .await? + .map(SiteOrCommunityOrUser::UserOrCommunity), + }) } #[tracing::instrument(skip_all)] @@ -56,8 +59,13 @@ impl Object for SiteOrCommunityOrUser { } } - async fn into_json(self, _data: &Data) -> LemmyResult { - unimplemented!() + async fn into_json(self, data: &Data) -> LemmyResult { + Ok(match self { + SiteOrCommunityOrUser::Site(p) => SiteOrPersonOrGroup::Instance(p.into_json(data).await?), + SiteOrCommunityOrUser::UserOrCommunity(p) => { + SiteOrPersonOrGroup::PersonOrGroup(p.into_json(data).await?) + } + }) } #[tracing::instrument(skip_all)] @@ -75,8 +83,20 @@ impl Object for SiteOrCommunityOrUser { } #[tracing::instrument(skip_all)] - async fn from_json(_apub: Self::Kind, _data: &Data) -> LemmyResult { - unimplemented!(); + async fn from_json(apub: Self::Kind, data: &Data) -> LemmyResult { + Ok(match apub { + SiteOrPersonOrGroup::Instance(a) => { + SiteOrCommunityOrUser::Site(ApubSite::from_json(a, data).await?) + } + SiteOrPersonOrGroup::PersonOrGroup(a) => match a { + PersonOrGroup::Person(p) => SiteOrCommunityOrUser::UserOrCommunity(UserOrCommunity::User( + ApubPerson::from_json(p, data).await?, + )), + PersonOrGroup::Group(g) => SiteOrCommunityOrUser::UserOrCommunity( + UserOrCommunity::Community(ApubCommunity::from_json(g, data).await?), + ), + }, + }) } } @@ -103,6 +123,9 @@ impl Actor for SiteOrCommunityOrUser { } fn inbox(&self) -> Url { - unimplemented!() + match self { + SiteOrCommunityOrUser::Site(u) => u.inbox(), + SiteOrCommunityOrUser::UserOrCommunity(c) => c.inbox(), + } } } diff --git a/crates/apub/src/fetcher/user_or_community.rs b/crates/apub/src/fetcher/user_or_community.rs index d29cbb6b0..129af8803 100644 --- a/crates/apub/src/fetcher/user_or_community.rs +++ b/crates/apub/src/fetcher/user_or_community.rs @@ -65,8 +65,11 @@ impl Object for UserOrCommunity { } } - async fn into_json(self, _data: &Data) -> LemmyResult { - unimplemented!() + async fn into_json(self, data: &Data) -> LemmyResult { + Ok(match self { + UserOrCommunity::User(p) => PersonOrGroup::Person(p.into_json(data).await?), + UserOrCommunity::Community(p) => PersonOrGroup::Group(p.into_json(data).await?), + }) } #[tracing::instrument(skip_all)] @@ -115,7 +118,10 @@ impl Actor for UserOrCommunity { } fn inbox(&self) -> Url { - unimplemented!() + match self { + UserOrCommunity::User(p) => p.inbox(), + UserOrCommunity::Community(p) => p.inbox(), + } } } diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 6f0a7328d..c67a223e0 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -88,7 +88,7 @@ impl Object for ApubSite { } async fn delete(self, _data: &Data) -> LemmyResult<()> { - unimplemented!() + Err(LemmyErrorType::CantDeleteSite.into()) } #[tracing::instrument(skip_all)] diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index 35f2fe418..fc9697391 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -73,7 +73,7 @@ impl Object for ApubPrivateMessage { async fn delete(self, _context: &Data) -> LemmyResult<()> { // do nothing, because pm can't be fetched over http - unimplemented!() + Err(LemmyErrorType::CouldntFindPrivateMessage.into()) } #[tracing::instrument(skip_all)] diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index 6075b14a1..0741ee9b6 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -193,10 +193,11 @@ impl ActivityHandler for Page { type DataType = LemmyContext; type Error = LemmyError; fn id(&self) -> &Url { - unimplemented!() + self.id.inner() } + // TODO this needs to be implemented fn actor(&self) -> &Url { - unimplemented!() + self.id.inner() } async fn verify(&self, data: &Data) -> LemmyResult<()> { ApubPost::verify(self, self.id.inner(), data).await diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index aa7b418fe..977bc9083 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -117,7 +117,7 @@ impl Crud for Comment { type UpdateForm = CommentUpdateForm; type IdType = CommentId; - /// This is unimplemented, use [[Comment::create]] + /// Use [[Comment::create]] async fn create(pool: &mut DbPool<'_>, comment_form: &Self::InsertForm) -> Result { debug_assert!(false); Comment::create(pool, comment_form, None).await diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 89c108f8c..f2909218c 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -191,9 +191,12 @@ impl Followable for PersonFollower { .get_result::(conn) .await } + + /// Currently no user following async fn follow_accepted(_: &mut DbPool<'_>, _: CommunityId, _: PersonId) -> Result { - unimplemented!() + Err(Error::NotFound) } + async fn unfollow(pool: &mut DbPool<'_>, form: &PersonFollowerForm) -> Result { let conn = &mut get_conn(pool).await?; diesel::delete(person_follower::table.find((form.follower_id, form.person_id))) diff --git a/crates/db_schema/src/impls/private_message_report.rs b/crates/db_schema/src/impls/private_message_report.rs index b5d8fd039..0d5876659 100644 --- a/crates/db_schema/src/impls/private_message_report.rs +++ b/crates/db_schema/src/impls/private_message_report.rs @@ -52,7 +52,7 @@ impl Reportable for PrivateMessageReport { _pm_id_: PrivateMessageId, _by_resolver_id: PersonId, ) -> Result { - unimplemented!() + Err(Error::NotFound) } async fn unresolve( diff --git a/crates/db_schema/src/impls/site.rs b/crates/db_schema/src/impls/site.rs index a371f9e07..9dbd2401d 100644 --- a/crates/db_schema/src/impls/site.rs +++ b/crates/db_schema/src/impls/site.rs @@ -20,7 +20,7 @@ impl Crud for Site { /// Use SiteView::read_local, or Site::read_from_apub_id instead async fn read(_pool: &mut DbPool<'_>, _site_id: SiteId) -> Result, Error> { - unimplemented!() + Err(Error::NotFound) } async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result { diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index 896539057..21c3fb06a 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -179,6 +179,8 @@ pub enum LemmyErrorType { UrlWithoutDomain, InboxTimeout, Unknown(String), + NotAnActor, + CantDeleteSite, } cfg_if! {