mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 19:31:33 +00:00
parent
48a033b87f
commit
3021e2c9b8
21 changed files with 45 additions and 52 deletions
|
@ -19,8 +19,6 @@ impl Perform for ListCommentReports {
|
|||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<ListCommentReportsResponse, LemmyError> {
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let data: &ListCommentReports = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
|
@ -31,6 +29,8 @@ impl Perform for ListCommentReports {
|
|||
|
||||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let comment_reports = CommentReportQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.my_person_id(person_id)
|
||||
|
|
|
@ -70,6 +70,7 @@ mod tests {
|
|||
#[serial]
|
||||
async fn test_should_not_validate_user_token_after_password_change() {
|
||||
let conn = &mut build_db_conn_for_tests().await;
|
||||
|
||||
let secret = Secret::init(conn).await.unwrap();
|
||||
let settings = &SETTINGS.to_owned();
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ impl Perform for GetPersonMentions {
|
|||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<GetPersonMentionsResponse, LemmyError> {
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let data: &GetPersonMentions = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
|
@ -29,6 +27,8 @@ impl Perform for GetPersonMentions {
|
|||
let person_id = Some(local_user_view.person.id);
|
||||
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
|
||||
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let mentions = PersonMentionQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.recipient_id(person_id)
|
||||
|
|
|
@ -14,8 +14,6 @@ impl Perform for GetReplies {
|
|||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetRepliesResponse, LemmyError> {
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let data: &GetReplies = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
|
@ -26,6 +24,8 @@ impl Perform for GetReplies {
|
|||
let person_id = Some(local_user_view.person.id);
|
||||
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
|
||||
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let replies = CommentReplyQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.recipient_id(person_id)
|
||||
|
|
|
@ -19,8 +19,6 @@ impl Perform for ListPostReports {
|
|||
&self,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<ListPostReportsResponse, LemmyError> {
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let data: &ListPostReports = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
|
@ -31,6 +29,8 @@ impl Perform for ListPostReports {
|
|||
|
||||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let post_reports = PostReportQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.my_person_id(person_id)
|
||||
|
|
|
@ -14,8 +14,6 @@ impl Perform for ListPrivateMessageReports {
|
|||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
||||
|
||||
is_admin(&local_user_view)?;
|
||||
|
@ -23,6 +21,8 @@ impl Perform for ListPrivateMessageReports {
|
|||
let unresolved_only = self.unresolved_only;
|
||||
let page = self.page;
|
||||
let limit = self.limit;
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let private_message_reports = PrivateMessageReportQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.unresolved_only(unresolved_only)
|
||||
|
|
|
@ -29,6 +29,8 @@ impl Perform for ListRegistrationApplications {
|
|||
|
||||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let registration_applications = RegistrationApplicationQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.unread_only(unread_only)
|
||||
|
|
|
@ -33,6 +33,8 @@ impl PerformCrud for ListCommunities {
|
|||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
let local_user = local_user_view.map(|l| l.local_user);
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let communities = CommunityQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.listing_type(listing_type)
|
||||
|
|
|
@ -50,6 +50,7 @@ impl PerformCrud for CreateSite {
|
|||
let mut conn = context.conn().await?;
|
||||
|
||||
let data: &CreateSite = self;
|
||||
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(&mut conn).await?;
|
||||
|
||||
|
|
|
@ -102,15 +102,13 @@ async fn local_user_settings_view_from_jwt_opt(
|
|||
jwt: Option<&Sensitive<String>>,
|
||||
context: &LemmyContext,
|
||||
) -> Option<LocalUserView> {
|
||||
let mut conn = context.conn().await().ok()?;
|
||||
|
||||
match jwt {
|
||||
Some(jwt) => {
|
||||
let claims = Claims::decode(jwt.as_ref(), &context.secret().jwt_secret)
|
||||
.ok()?
|
||||
.claims;
|
||||
let local_user_id = LocalUserId(claims.sub);
|
||||
let local_user_view = LocalUserView::read(&mut conn, local_user_id)
|
||||
let local_user_view = LocalUserView::read(&mut *context.conn().await.ok()?, local_user_id)
|
||||
.await
|
||||
.ok()?;
|
||||
check_user_valid(
|
||||
|
|
|
@ -90,7 +90,6 @@ impl CreateOrUpdateNote {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
// TODO: might be helpful to add a comment method to retrieve community directly
|
||||
let post_id = comment.post_id;
|
||||
let post = Post::read(&mut conn, post_id).await?;
|
||||
|
|
|
@ -56,6 +56,8 @@ impl PerformApub for GetComments {
|
|||
let parent_path_cloned = parent_path.clone();
|
||||
let post_id = data.post_id;
|
||||
let local_user = local_user_view.map(|l| l.local_user);
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let comments = CommentQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.listing_type(Some(listing_type))
|
||||
|
|
|
@ -47,6 +47,8 @@ impl PerformApub for GetPosts {
|
|||
.await
|
||||
.is_ok();
|
||||
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let posts = PostQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.local_user(local_user_view.map(|l| l.local_user).as_ref())
|
||||
|
|
|
@ -65,6 +65,8 @@ impl PerformApub for GetPersonDetails {
|
|||
let local_user = local_user_view.map(|l| l.local_user);
|
||||
let local_user_clone = local_user.clone();
|
||||
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let posts_query = PostQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.sort(sort)
|
||||
|
@ -87,6 +89,8 @@ impl PerformApub for GetPersonDetails {
|
|||
}
|
||||
.await?;
|
||||
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
let comments_query = CommentQuery::builder()
|
||||
.conn(&mut conn)
|
||||
.local_user(local_user_clone.as_ref())
|
||||
|
|
|
@ -58,6 +58,8 @@ impl PerformApub for Search {
|
|||
};
|
||||
let creator_id = data.creator_id;
|
||||
let local_user = local_user_view.map(|l| l.local_user);
|
||||
let mut conn = context.conn().await?;
|
||||
|
||||
match search_type {
|
||||
SearchType::Posts => {
|
||||
posts = PostQuery::builder()
|
||||
|
|
|
@ -28,10 +28,8 @@ impl Collection for ApubCommunityFeatured {
|
|||
owner: &Self::Owner,
|
||||
data: &Data<Self::DataType>,
|
||||
) -> Result<Self::Kind, Self::Error> {
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
let ordered_items = try_join_all(
|
||||
Post::list_featured_for_community(&mut conn, owner.id)
|
||||
Post::list_featured_for_community(&mut *data.conn().await?, owner.id)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(ApubPost::from)
|
||||
|
|
|
@ -33,10 +33,8 @@ impl Collection for ApubCommunityModerators {
|
|||
owner: &Self::Owner,
|
||||
data: &Data<Self::DataType>,
|
||||
) -> Result<Self::Kind, LemmyError> {
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
let moderators =
|
||||
CommunityModeratorView::for_community(&mut conn, owner.id).await?;
|
||||
CommunityModeratorView::for_community(&mut *data.conn().await?, owner.id).await?;
|
||||
let ordered_items = moderators
|
||||
.into_iter()
|
||||
.map(|m| ObjectId::<ApubPerson>::from(m.moderator.actor_id))
|
||||
|
@ -64,11 +62,9 @@ impl Collection for ApubCommunityModerators {
|
|||
owner: &Self::Owner,
|
||||
data: &Data<Self::DataType>,
|
||||
) -> Result<Self, LemmyError> {
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
let community_id = owner.id;
|
||||
let current_moderators =
|
||||
CommunityModeratorView::for_community(&mut conn, community_id).await?;
|
||||
CommunityModeratorView::for_community(&mut *data.conn().await?, community_id).await?;
|
||||
// Remove old mods from database which arent in the moderators collection anymore
|
||||
for mod_user in ¤t_moderators {
|
||||
let mod_id = ObjectId::from(mod_user.moderator.actor_id.clone());
|
||||
|
@ -77,7 +73,7 @@ impl Collection for ApubCommunityModerators {
|
|||
community_id: mod_user.community.id,
|
||||
person_id: mod_user.moderator.id,
|
||||
};
|
||||
CommunityModerator::leave(&mut conn, &community_moderator_form).await?;
|
||||
CommunityModerator::leave(&mut *data.conn().await?, &community_moderator_form).await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +90,7 @@ impl Collection for ApubCommunityModerators {
|
|||
community_id: owner.id,
|
||||
person_id: mod_user.id,
|
||||
};
|
||||
CommunityModerator::join(&mut conn, &community_moderator_form).await?;
|
||||
CommunityModerator::join(&mut *data.conn().await?, &community_moderator_form).await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,16 +41,14 @@ impl Collection for ApubCommunityOutbox {
|
|||
owner: &Self::Owner,
|
||||
data: &Data<Self::DataType>,
|
||||
) -> Result<Self::Kind, LemmyError> {
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
let post_list: Vec<ApubPost> = Post::list_for_community(&mut conn, owner.id)
|
||||
let post_list: Vec<ApubPost> = Post::list_for_community(&mut *data.conn().await?, owner.id)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect();
|
||||
let mut ordered_items = vec![];
|
||||
for post in post_list {
|
||||
let person = Person::read(&mut conn, post.creator_id)
|
||||
let person = Person::read(&mut *data.conn().await?, post.creator_id)
|
||||
.await?
|
||||
.into();
|
||||
let create =
|
||||
|
|
|
@ -169,8 +169,6 @@ async fn insert_activity<T>(
|
|||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
let ap_id = ap_id.clone().into();
|
||||
let form = ActivityInsertForm {
|
||||
ap_id,
|
||||
|
@ -179,7 +177,7 @@ where
|
|||
sensitive: Some(sensitive),
|
||||
updated: None,
|
||||
};
|
||||
Activity::create(&mut conn, &form).await?;
|
||||
Activity::create(&mut *data.conn().await?, &form).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -86,11 +86,9 @@ impl Object for ApubCommunity {
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Group, LemmyError> {
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
let community_id = self.id;
|
||||
let langs = CommunityLanguage::read(&mut conn, community_id).await?;
|
||||
let language = LanguageTag::new_multiple(langs, &mut conn).await?;
|
||||
let langs = CommunityLanguage::read(&mut *data.conn().await?, community_id).await?;
|
||||
let language = LanguageTag::new_multiple(langs, &mut *data.conn().await?).await?;
|
||||
|
||||
let group = Group {
|
||||
kind: GroupType::Group,
|
||||
|
|
|
@ -70,10 +70,8 @@ impl Object for ApubSite {
|
|||
object_id: Url,
|
||||
data: &Data<Self::DataType>,
|
||||
) -> Result<Option<Self>, LemmyError> {
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
Ok(
|
||||
Site::read_from_apub_id(&mut conn, &object_id.into())
|
||||
Site::read_from_apub_id(&mut *data.conn().await?, &object_id.into())
|
||||
.await?
|
||||
.map(Into::into),
|
||||
)
|
||||
|
@ -85,11 +83,9 @@ impl Object for ApubSite {
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, LemmyError> {
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
let site_id = self.id;
|
||||
let langs = SiteLanguage::read(&mut conn, site_id).await?;
|
||||
let language = LanguageTag::new_multiple(langs, &mut conn).await?;
|
||||
let langs = SiteLanguage::read(&mut *data.conn().await?, site_id).await?;
|
||||
let language = LanguageTag::new_multiple(langs, &mut *data.conn().await?).await?;
|
||||
|
||||
let instance = Instance {
|
||||
kind: ApplicationType::Application,
|
||||
|
@ -117,9 +113,7 @@ impl Object for ApubSite {
|
|||
expected_domain: &Url,
|
||||
data: &Data<Self::DataType>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
let local_site_data = fetch_local_site_data(&mut conn).await?;
|
||||
let local_site_data = fetch_local_site_data(&mut *data.conn().await?).await?;
|
||||
|
||||
check_apub_id_valid_with_strictness(apub.id.inner(), true, &local_site_data, data.settings())?;
|
||||
verify_domains_match(expected_domain, apub.id.inner())?;
|
||||
|
@ -133,10 +127,8 @@ impl Object for ApubSite {
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn from_json(apub: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, LemmyError> {
|
||||
let mut conn = data.conn().await?;
|
||||
|
||||
let domain = apub.id.inner().domain().expect("group id has domain");
|
||||
let instance = DbInstance::read_or_create(&mut conn, domain.to_string()).await?;
|
||||
let instance = DbInstance::read_or_create(&mut *data.conn().await?, domain.to_string()).await?;
|
||||
|
||||
let site_form = SiteInsertForm {
|
||||
name: apub.name.clone(),
|
||||
|
@ -153,10 +145,10 @@ impl Object for ApubSite {
|
|||
instance_id: instance.id,
|
||||
};
|
||||
let languages =
|
||||
LanguageTag::to_language_id_multiple(apub.language, &mut conn).await?;
|
||||
LanguageTag::to_language_id_multiple(apub.language, &mut *data.conn().await?).await?;
|
||||
|
||||
let site = Site::create(&mut conn, &site_form).await?;
|
||||
SiteLanguage::update(&mut conn, languages, &site).await?;
|
||||
let site = Site::create(&mut *data.conn().await?, &site_form).await?;
|
||||
SiteLanguage::update(&mut *data.conn().await?, languages, &site).await?;
|
||||
Ok(site.into())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue