mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-29 15:51:20 +00:00
stuff
This commit is contained in:
parent
ce013f9904
commit
ae78eaa3b1
3 changed files with 45 additions and 47 deletions
|
@ -152,16 +152,7 @@ test("Only followers can view and interact with private community content", asyn
|
||||||
follow: true,
|
follow: true,
|
||||||
};
|
};
|
||||||
await user.followCommunity(follow_form);
|
await user.followCommunity(follow_form);
|
||||||
const pendingFollows1 = await waitUntil(
|
approveFollower(alpha, alphaCommunityId);
|
||||||
() => listCommunityPendingFollows(alpha),
|
|
||||||
f => f.items.length == 1,
|
|
||||||
);
|
|
||||||
const approve = await approveCommunityPendingFollow(
|
|
||||||
alpha,
|
|
||||||
alphaCommunityId,
|
|
||||||
pendingFollows1.items[0].person.id,
|
|
||||||
);
|
|
||||||
expect(approve.success).toBe(true);
|
|
||||||
|
|
||||||
// now user can fetch posts and comments in community (using signed fetch), and create posts
|
// now user can fetch posts and comments in community (using signed fetch), and create posts
|
||||||
await waitUntil(
|
await waitUntil(
|
||||||
|
@ -283,7 +274,7 @@ test("Follow a private community and receive activities", async () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Fetch remote content in private community", async () => {
|
test.only("Fetch remote content in private community", async () => {
|
||||||
// create private community
|
// create private community
|
||||||
const community = await createCommunity(alpha, randomString(10), "Private");
|
const community = await createCommunity(alpha, randomString(10), "Private");
|
||||||
expect(community.community_view.community.visibility).toBe("Private");
|
expect(community.community_view.community.visibility).toBe("Private");
|
||||||
|
@ -297,6 +288,7 @@ test("Fetch remote content in private community", async () => {
|
||||||
follow: true,
|
follow: true,
|
||||||
};
|
};
|
||||||
await beta.followCommunity(follow_form_beta);
|
await beta.followCommunity(follow_form_beta);
|
||||||
|
await approveFollower(alpha, alphaCommunityId);
|
||||||
|
|
||||||
// beta creates post and comment
|
// beta creates post and comment
|
||||||
const post = await createPost(beta, betaCommunityId);
|
const post = await createPost(beta, betaCommunityId);
|
||||||
|
@ -306,40 +298,35 @@ test("Fetch remote content in private community", async () => {
|
||||||
const comment_id = comment.comment_view.comment.id;
|
const comment_id = comment.comment_view.comment.id;
|
||||||
expect(comment_id).toBeDefined();
|
expect(comment_id).toBeDefined();
|
||||||
|
|
||||||
// gamma is not following the community and cannot view nor create posts
|
// create gamma user and follow community
|
||||||
const user = await registerUser(gamma, betaUrl);
|
|
||||||
const gammaCommunityId = (
|
const gammaCommunityId = (
|
||||||
await resolveCommunity(user, community.community_view.community.actor_id)
|
await resolveCommunity(gamma, community.community_view.community.actor_id)
|
||||||
).community!.community.id;
|
).community!.community.id;
|
||||||
|
|
||||||
// follow the community and approve
|
|
||||||
const follow_form: FollowCommunity = {
|
const follow_form: FollowCommunity = {
|
||||||
community_id: gammaCommunityId,
|
community_id: gammaCommunityId,
|
||||||
follow: true,
|
follow: true,
|
||||||
};
|
};
|
||||||
await user.followCommunity(follow_form);
|
await gamma.followCommunity(follow_form);
|
||||||
const pendingFollows1 = await waitUntil(
|
await approveFollower(alpha, alphaCommunityId);
|
||||||
() => listCommunityPendingFollows(alpha),
|
|
||||||
f => f.items.length == 1,
|
|
||||||
);
|
|
||||||
const approve = await approveCommunityPendingFollow(
|
|
||||||
alpha,
|
|
||||||
alphaCommunityId,
|
|
||||||
pendingFollows1.items[0].person.id,
|
|
||||||
);
|
|
||||||
expect(approve.success).toBe(true);
|
|
||||||
|
|
||||||
// now user can fetch posts and comments in community (using signed fetch), and create posts
|
// now user can fetch posts and comments in community (using signed fetch), and create posts
|
||||||
console.log(1);
|
let resolvedPost = await waitUntil(
|
||||||
await waitUntil(
|
() => resolvePost(gamma, post.post_view.post),
|
||||||
() => resolvePost(user, post.post_view.post),
|
|
||||||
p => p?.post?.post.id != undefined,
|
p => p?.post?.post.id != undefined,
|
||||||
);
|
);
|
||||||
console.log(2);
|
console.log(post.post_view.post);
|
||||||
|
console.log(resolvedPost.post?.post);
|
||||||
|
expect(resolvedPost.post?.post.ap_id).toBe(post.post_view.post.ap_id);
|
||||||
const resolvedComment = (
|
const resolvedComment = (
|
||||||
await resolveComment(user, comment.comment_view.comment)
|
await resolveComment(gamma, comment.comment_view.comment)
|
||||||
).comment;
|
).comment;
|
||||||
expect(resolvedComment?.comment.id).toBeDefined();
|
expect(resolvedComment?.comment.ap_id).toBe(
|
||||||
|
comment.comment_view.comment.ap_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: this test should fail as check_has_followers_from_instance() on beta returns errors
|
||||||
|
// because it doesnt know the community follower. yet for some reason the test passes???
|
||||||
|
fail();
|
||||||
});
|
});
|
||||||
|
|
||||||
async function approveFollower(user: LemmyHttp, community_id: number) {
|
async function approveFollower(user: LemmyHttp, community_id: number) {
|
||||||
|
|
|
@ -17,8 +17,10 @@ use lemmy_db_schema::{
|
||||||
actor_language::CommunityLanguage,
|
actor_language::CommunityLanguage,
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
comment_reply::{CommentReply, CommentReplyInsertForm},
|
comment_reply::{CommentReply, CommentReplyInsertForm},
|
||||||
|
community::Community,
|
||||||
person::Person,
|
person::Person,
|
||||||
person_mention::{PersonMention, PersonMentionInsertForm},
|
person_mention::{PersonMention, PersonMentionInsertForm},
|
||||||
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
|
@ -101,17 +103,28 @@ pub async fn send_local_notifs(
|
||||||
let mut recipient_ids = Vec::new();
|
let mut recipient_ids = Vec::new();
|
||||||
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
||||||
|
|
||||||
// let person = my_local_user.person;
|
// When called from api code, we have local user view and can read with CommentView
|
||||||
// Read the comment view to get extra info
|
// to reduce db queries. But when receiving a federated comment the user view is None,
|
||||||
|
// which means that comments inside private communities cant be read. As a workaround
|
||||||
|
// we need to read the items manually to bypass this check.
|
||||||
|
let (comment, post, community) = if let Some(local_user_view) = local_user_view {
|
||||||
let comment_view = CommentView::read(
|
let comment_view = CommentView::read(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
comment_id,
|
comment_id,
|
||||||
local_user_view.map(|view| &view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let comment = comment_view.comment;
|
(
|
||||||
let post = comment_view.post;
|
comment_view.comment,
|
||||||
let community = comment_view.community;
|
comment_view.post,
|
||||||
|
comment_view.community,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
let comment = Comment::read(&mut context.pool(), comment_id).await?;
|
||||||
|
let post = Post::read(&mut context.pool(), comment.post_id).await?;
|
||||||
|
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||||
|
(comment, post, community)
|
||||||
|
};
|
||||||
|
|
||||||
// Send the local mentions
|
// Send the local mentions
|
||||||
for mention in mentions
|
for mention in mentions
|
||||||
|
|
|
@ -174,9 +174,7 @@ impl ActivityHandler for CreateOrUpdateNote {
|
||||||
|
|
||||||
// TODO: this fails in local community comment as CommentView::read() returns nothing
|
// TODO: this fails in local community comment as CommentView::read() returns nothing
|
||||||
// without passing LocalUser
|
// without passing LocalUser
|
||||||
send_local_notifs(mentions, comment.id, &actor, do_send_email, context, None)
|
send_local_notifs(mentions, comment.id, &actor, do_send_email, context, None).await?;
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue