Fixing a few issues.

This commit is contained in:
Dessalines 2023-04-25 23:07:04 -04:00
parent 4a2cd9029a
commit 7095151841
25 changed files with 47 additions and 209 deletions

3
Cargo.lock generated
View file

@ -2394,7 +2394,6 @@ dependencies = [
"lemmy_db_views_actor",
"lemmy_db_views_moderator",
"lemmy_utils",
"opentelemetry 0.17.0",
"percent-encoding",
"rand 0.8.5",
"regex",
@ -2407,7 +2406,6 @@ dependencies = [
"strum_macros",
"tokio",
"tracing",
"tracing-opentelemetry 0.17.4",
"url",
"webpage",
]
@ -2437,6 +2435,7 @@ name = "lemmy_apub"
version = "0.17.2"
dependencies = [
"activitypub_federation",
"activitystreams-kinds",
"actix",
"actix-rt",
"actix-web",

View file

@ -23,7 +23,7 @@ use lemmy_db_schema::{
traits::{Bannable, Crud, Followable},
};
use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix, ConnectionId};
use lemmy_utils::{error::LemmyError, utils::naive_from_unix, ConnectionId};
#[async_trait::async_trait(?Send)]
impl Perform for BanFromCommunity {

View file

@ -14,7 +14,7 @@ use lemmy_db_schema::{
traits::Crud,
};
use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix, ConnectionId};
use lemmy_utils::{error::LemmyError, utils::naive_from_unix, ConnectionId};
#[async_trait::async_trait(?Send)]
impl Perform for BanPerson {

View file

@ -64,8 +64,7 @@ impl Perform for LeaveAdmin {
let all_languages = Language::read_all(context.pool()).await?;
let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
let custom_emojis = CustomEmojiView::get_all(context.pool(), site_view.local_site.id).await?;
let taglines = Some(Tagline::get_all(context.pool(), site_view.local_site.id).await?);
Ok(GetSiteResponse {
site_view,

View file

@ -8,6 +8,7 @@ use lemmy_utils::{
use reqwest_middleware::ClientWithMiddleware;
use std::sync::Arc;
#[derive(Clone)]
pub struct LemmyContext {
pool: DbPool,
chat_server: Addr<ChatServer>,
@ -21,16 +22,14 @@ impl LemmyContext {
pool: DbPool,
chat_server: Addr<ChatServer>,
client: ClientWithMiddleware,
settings: Settings,
secret: Secret,
rate_limit_cell: RateLimitCell,
) -> LemmyContext {
LemmyContext {
pool,
chat_server,
client,
settings,
secret,
client: Arc::new(client),
secret: Arc::new(secret),
rate_limit_cell,
}
}
@ -53,16 +52,3 @@ impl LemmyContext {
&self.rate_limit_cell
}
}
impl Clone for LemmyContext {
fn clone(&self) -> Self {
LemmyContext {
pool: self.pool.clone(),
chat_server: self.chat_server.clone(),
client: self.client.clone(),
settings: self.settings.clone(),
secret: self.secret.clone(),
rate_limit_cell: self.rate_limit_cell.clone(),
}
}
}

View file

@ -39,7 +39,6 @@ fn html_to_site_metadata(html_bytes: &[u8]) -> Result<SiteMetadata, LemmyError>
let first_line = html
.trim_start()
.lines()
.into_iter()
.next()
.ok_or_else(|| LemmyError::from_message("No lines in html"))?
.to_lowercase();

View file

@ -26,12 +26,12 @@ use lemmy_db_schema::{
person_mention::{PersonMention, PersonMentionInsertForm},
post::Post,
},
traits::{Crud, DeleteableOrRemoveable},
traits::Crud,
SubscribedType,
};
use lemmy_db_views::structs::{CommentView, LocalUserView, PostView, PrivateMessageView};
use lemmy_db_views_actor::structs::CommunityView;
use lemmy_utils::{error::LemmyError, utils::mention::MentionData, ConnectionId};
use lemmy_utils::{error::LemmyError, utils::MentionData, ConnectionId};
use serde::Serialize;
impl LemmyContext {
@ -46,7 +46,7 @@ impl LemmyContext {
where
OP: ToString,
{
let post_view = PostView::read(self.pool(), post_id, person_id, Some(true)).await?;
let post_view = PostView::read(self.pool(), post_id, person_id).await?;
let res = PostResponse { post_view };
@ -175,8 +175,7 @@ impl LemmyContext {
where
OP: ToString,
{
let community_view =
CommunityView::read(self.pool(), community_id, person_id, Some(true)).await?;
let community_view = CommunityView::read(self.pool(), community_id, person_id).await?;
let discussion_languages = CommunityLanguage::read(self.pool(), community_id).await?;
let mut res = CommunityResponse {

View file

@ -3,7 +3,12 @@ use actix_web::web::Data;
use lemmy_api_common::{
comment::{CommentResponse, EditComment},
context::LemmyContext,
utils::{check_community_ban, get_local_user_view_from_jwt, local_site_to_slur_regex},
utils::{
check_community_ban,
get_local_user_view_from_jwt,
is_mod_or_admin,
local_site_to_slur_regex,
},
websocket::UserOperationCrud,
};
use lemmy_db_schema::{

View file

@ -5,7 +5,7 @@ use lemmy_api_common::{
context::LemmyContext,
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
};
use lemmy_db_schema::{source::local_site::LocalSite, traits::DeleteableOrRemoveable};
use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views_actor::community_view::CommunityQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -27,14 +27,12 @@ impl PerformCrud for ListCommunities {
check_private_instance(&local_user_view, &local_site)?;
let person_id = local_user_view.clone().map(|l| l.person.id);
let sort = data.sort;
let listing_type = data.type_;
let page = data.page;
let limit = data.limit;
let local_user = local_user_view.map(|l| l.local_user);
let mut communities = CommunityQuery::builder()
let communities = CommunityQuery::builder()
.pool(context.pool())
.listing_type(listing_type)
.sort(sort)
@ -45,16 +43,6 @@ impl PerformCrud for ListCommunities {
.list()
.await?;
// Blank out deleted or removed info for non-logged in users
if person_id.is_none() {
for cv in communities
.iter_mut()
.filter(|cv| cv.community.deleted || cv.community.removed)
{
cv.community = cv.clone().community.blank_out_deleted_or_removed_info();
}
}
// Return the jwt
Ok(ListCommunitiesResponse { communities })
}

View file

@ -3,18 +3,13 @@ use actix_web::web::Data;
use lemmy_api_common::{
context::LemmyContext,
post::{GetPost, GetPostResponse},
utils::{
check_private_instance,
get_local_user_view_from_jwt_opt,
is_mod_or_admin_opt,
mark_post_as_read,
},
utils::{check_private_instance, get_local_user_view_from_jwt_opt, mark_post_as_read},
websocket::handlers::online_users::GetPostUsersOnline,
};
use lemmy_db_schema::{
aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
source::{comment::Comment, local_site::LocalSite},
traits::{Crud, DeleteableOrRemoveable},
traits::Crud,
};
use lemmy_db_views::structs::PostView;
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
@ -52,7 +47,7 @@ impl PerformCrud for GetPost {
Err(LemmyError::from_message("couldnt_find_post"))?
};
let mut post_view = PostView::read(context.pool(), post_id, person_id)
let post_view = PostView::read(context.pool(), post_id, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?;
@ -64,7 +59,7 @@ impl PerformCrud for GetPost {
// Necessary for the sidebar subscribed
let community_id = post_view.community.id;
let mut community_view = CommunityView::read(context.pool(), community_id, person_id)
let community_view = CommunityView::read(context.pool(), community_id, person_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
@ -83,17 +78,6 @@ impl PerformCrud for GetPost {
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?;
}
// Blank out deleted or removed info for non-logged in users
if person_id.is_none() {
if post_view.post.deleted || post_view.post.removed {
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
}
if community_view.community.deleted || community_view.community.removed {
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
}
let moderators = CommunityModeratorView::for_community(context.pool(), community_id).await?;
let online = context

View file

@ -5,7 +5,6 @@ use lemmy_api_common::{
private_message::{GetPrivateMessages, PrivateMessagesResponse},
utils::get_local_user_view_from_jwt,
};
use lemmy_db_schema::traits::DeleteableOrRemoveable;
use lemmy_db_views::private_message_view::PrivateMessageQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -45,17 +44,6 @@ impl PerformCrud for GetPrivateMessages {
}
});
// Blank out deleted or removed info
for pmv in messages
.iter_mut()
.filter(|pmv| pmv.private_message.deleted)
{
pmv.private_message = pmv
.clone()
.private_message
.blank_out_deleted_or_removed_info();
}
Ok(PrivateMessagesResponse {
private_messages: messages,
})

View file

@ -89,8 +89,7 @@ impl PerformCrud for GetSite {
let all_languages = Language::read_all(context.pool()).await?;
let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
let custom_emojis = CustomEmojiView::get_all(context.pool(), site_view.local_site.id).await?;
let taglines = Some(Tagline::get_all(context.pool(), site_view.local_site.id).await?);
Ok(GetSiteResponse {
site_view,

View file

@ -1,5 +1,5 @@
use crate::objects::person::ApubPerson;
use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
use crate::{local_instance, objects::person::ApubPerson};
use activitypub_federation::core::object_id::ObjectId;
use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{
newtypes::LocalUserId,

View file

@ -7,7 +7,8 @@ use crate::{
objects::{community::ApubCommunity, person::ApubPerson},
protocol::{activities::deletion::delete::Delete, IdOrNestedObject},
};
use activitypub_federation::{config::Data, kinds::activity::DeleteType, traits::ActivityHandler};
use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
use activitystreams_kinds::activity::DeleteType;
use lemmy_api_common::{context::LemmyContext, websocket::UserOperationCrud};
use lemmy_db_schema::{
source::{

View file

@ -7,7 +7,8 @@ use crate::{
objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
};
use activitypub_federation::{config::Data, kinds::activity::UndoType, traits::ActivityHandler};
use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
use activitystreams_kinds::activity::UndoType;
use lemmy_api_common::{context::LemmyContext, websocket::UserOperationCrud};
use lemmy_db_schema::{
source::{

View file

@ -11,7 +11,7 @@ use lemmy_api_common::{
};
use lemmy_db_schema::{
source::{comment::Comment, community::Community, local_site::LocalSite},
traits::{Crud, DeleteableOrRemoveable},
traits::Crud,
};
use lemmy_db_views::comment_view::CommentQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -34,7 +34,7 @@ impl PerformApub for GetComments {
check_private_instance(&local_user_view, &local_site)?;
let community_id = if let Some(name) = &data.community_name {
resolve_actor_identifier::<ApubCommunity, Community>(name, context, &None, true)
resolve_actor_identifier::<ApubCommunity, Community>(name, context, true)
.await
.ok()
.map(|c| c.id)
@ -77,14 +77,6 @@ impl PerformApub for GetComments {
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_comments"))?;
// Blank out deleted or removed info
for cv in comments
.iter_mut()
.filter(|cv| cv.comment.deleted || cv.comment.removed)
{
cv.comment = cv.clone().comment.blank_out_deleted_or_removed_info();
}
Ok(GetCommentsResponse { comments })
}
}

View file

@ -7,12 +7,9 @@ use actix_web::web::Data;
use lemmy_api_common::{
context::LemmyContext,
post::{GetPosts, GetPostsResponse},
utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_mod_or_admin_opt},
};
use lemmy_db_schema::{
source::{community::Community, local_site::LocalSite},
traits::DeleteableOrRemoveable,
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
};
use lemmy_db_schema::source::{community::Community, local_site::LocalSite};
use lemmy_db_views::post_view::PostQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -41,7 +38,7 @@ impl PerformApub for GetPosts {
let page = data.page;
let limit = data.limit;
let community_id = if let Some(name) = &data.community_name {
resolve_actor_identifier::<ApubCommunity, Community>(name, context, &None, true)
resolve_actor_identifier::<ApubCommunity, Community>(name, context, true)
.await
.ok()
.map(|c| c.id)
@ -52,11 +49,6 @@ impl PerformApub for GetPosts {
let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
let is_mod_or_admin =
is_mod_or_admin_opt(context.pool(), local_user_view.as_ref(), community_id)
.await
.is_ok();
let posts = PostQuery::builder()
.pool(context.pool())
.local_user(local_user_view.map(|l| l.local_user).as_ref())
@ -71,23 +63,6 @@ impl PerformApub for GetPosts {
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_posts"))?;
// Blank out deleted or removed info for non-logged in users
if !is_logged_in {
for pv in posts
.iter_mut()
.filter(|p| p.post.deleted || p.post.removed)
{
pv.post = pv.clone().post.blank_out_deleted_or_removed_info();
}
for pv in posts
.iter_mut()
.filter(|p| p.community.deleted || p.community.removed)
{
pv.community = pv.clone().community.blank_out_deleted_or_removed_info();
}
}
Ok(GetPostsResponse { posts })
}
}

View file

@ -7,7 +7,7 @@ use actix_web::web::Data;
use lemmy_api_common::{
community::{GetCommunity, GetCommunityResponse},
context::LemmyContext,
utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_mod_or_admin_opt},
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
websocket::handlers::online_users::GetCommunityUsersOnline,
};
use lemmy_db_schema::{
@ -18,7 +18,6 @@ use lemmy_db_schema::{
local_site::LocalSite,
site::Site,
},
traits::DeleteableOrRemoveable,
};
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
use lemmy_utils::{error::LemmyError, ConnectionId};
@ -62,12 +61,6 @@ impl PerformApub for GetCommunity {
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
// Blank out deleted or removed info for non-logged in users
if person_id.is_none() && (community_view.community.deleted || community_view.community.removed)
{
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
let moderators = CommunityModeratorView::for_community(context.pool(), community_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;

View file

@ -11,7 +11,6 @@ use lemmy_api_common::{
};
use lemmy_db_schema::{
source::{community::Community, local_site::LocalSite},
traits::DeleteableOrRemoveable,
utils::post_to_comment_sort_type,
SearchType,
};
@ -55,7 +54,7 @@ impl PerformApub for Search {
let listing_type = data.listing_type;
let search_type = data.type_.unwrap_or(SearchType::All);
let community_id = if let Some(name) = &data.community_name {
resolve_actor_identifier::<ApubCommunity, Community>(name, context, &local_user_view, false)
resolve_actor_identifier::<ApubCommunity, Community>(name, context, false)
.await
.ok()
.map(|c| c.id)
@ -205,30 +204,6 @@ impl PerformApub for Search {
}
};
// Blank out deleted or removed info for non logged in users
if person_id.is_none() {
for cv in communities
.iter_mut()
.filter(|cv| cv.community.deleted || cv.community.removed)
{
cv.community = cv.clone().community.blank_out_deleted_or_removed_info();
}
for pv in posts
.iter_mut()
.filter(|p| p.post.deleted || p.post.removed)
{
pv.post = pv.clone().post.blank_out_deleted_or_removed_info();
}
for cv in comments
.iter_mut()
.filter(|cv| cv.comment.deleted || cv.comment.removed)
{
cv.comment = cv.clone().comment.blank_out_deleted_or_removed_info();
}
}
// Return the jwt
Ok(SearchResponse {
type_: search_type.to_string(),

View file

@ -2,7 +2,6 @@ use crate::{
http::{create_apub_response, create_apub_tombstone_response, err_object_not_local},
objects::comment::ApubComment,
};
use activitypub_federation::traits::ApubObject;
use actix_web::{web, web::Path, HttpResponse};
use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};

View file

@ -10,7 +10,7 @@ use crate::{
CommentSavedForm,
CommentUpdateForm,
},
traits::{Crud, DeleteableOrRemoveable, Likeable, Saveable},
traits::{Crud, Likeable, Saveable},
utils::{get_conn, naive_now, DbPool},
};
use diesel::{
@ -240,13 +240,6 @@ impl Saveable for CommentSaved {
}
}
impl DeleteableOrRemoveable for Comment {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.content = String::new();
self
}
}
#[cfg(test)]
mod tests {
use crate::{

View file

@ -12,11 +12,10 @@ use crate::{
CommunityModeratorForm,
CommunityPersonBan,
CommunityPersonBanForm,
CommunitySafe,
CommunityUpdateForm,
},
},
traits::{ApubActor, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable},
traits::{ApubActor, Bannable, Crud, Followable, Joinable},
utils::{functions::lower, get_conn, DbPool},
SubscribedType,
};
@ -108,26 +107,6 @@ impl Joinable for CommunityModerator {
}
}
impl DeleteableOrRemoveable for CommunitySafe {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.title = String::new();
self.description = None;
self.icon = None;
self.banner = None;
self
}
}
impl DeleteableOrRemoveable for Community {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.title = String::new();
self.description = None;
self.icon = None;
self.banner = None;
self
}
}
pub enum CollectionType {
Moderators,
Featured,

View file

@ -26,7 +26,7 @@ use crate::{
PostSavedForm,
PostUpdateForm,
},
traits::{Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable},
traits::{Crud, Likeable, Readable, Saveable},
utils::{get_conn, naive_now, DbPool, FETCH_LIMIT_MAX},
};
use ::url::Url;
@ -317,20 +317,6 @@ impl Readable for PostRead {
}
}
impl DeleteableOrRemoveable for Post {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.name = String::new();
self.url = None;
self.body = None;
self.embed_title = None;
self.embed_description = None;
self.embed_video_url = None;
self.thumbnail_url = None;
self
}
}
#[cfg(test)]
mod tests {
use crate::{

View file

@ -2,7 +2,7 @@ use crate::{
newtypes::{DbUrl, PersonId, PrivateMessageId},
schema::private_message::dsl::{ap_id, private_message, read, recipient_id},
source::private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
traits::{Crud, DeleteableOrRemoveable},
traits::Crud,
utils::{get_conn, DbPool},
};
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
@ -86,13 +86,6 @@ impl PrivateMessage {
}
}
impl DeleteableOrRemoveable for PrivateMessage {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
self.content = String::new();
self
}
}
#[cfg(test)]
mod tests {
use crate::{

View file

@ -1,9 +1,11 @@
use crate::newtypes::InstanceId;
#[cfg(feature = "full")]
use crate::schema::instance;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use typed_builder::TypedBuilder;
#[derive(PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", diesel(table_name = instance))]
pub struct Instance {
@ -13,9 +15,12 @@ pub struct Instance {
pub updated: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, TypedBuilder)]
#[builder(field_defaults(default))]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", diesel(table_name = instance))]
pub struct InstanceForm {
#[builder(!default)]
pub domain: String,
pub updated: Option<chrono::NaiveDateTime>,
}