Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🍰 Post In Groups #5380

Merged
merged 34 commits into from
Oct 11, 2022
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
90e1696
add group to post in schema
Mogge Sep 20, 2022
f331813
create post in group
Mogge Sep 20, 2022
0c32fd8
add post access filter for all post queries
Mogge Sep 20, 2022
5e30bfe
add direction of Post in Group
Mogge Sep 20, 2022
4d480d3
add post query
Mogge Sep 22, 2022
e748fcc
add is member of group check to permission of create post
Mogge Sep 22, 2022
a9cd661
add tets for posts in groups
Mogge Sep 22, 2022
b259295
Merge branch '5059-epic-groups' into post-in-group
Mogge Oct 3, 2022
1870efc
add CANNOT_SEE relation to posts in groups
Mogge Oct 3, 2022
5f4d7c2
add notVisibleFor statement
Mogge Oct 3, 2022
abcfe25
query and mutations are functions
Mogge Oct 3, 2022
4a63e14
calls to query and mutate are functions
Mogge Oct 3, 2022
4a12cdf
remove unused memberIds statement
Mogge Oct 3, 2022
069eefd
add helper function to filter invisible posts
Mogge Oct 3, 2022
833bd5f
use invisible post filter
Mogge Oct 4, 2022
16a24bf
remove not working filters from schema
Mogge Oct 4, 2022
32d3c5e
insure that user context is present as posts can be queried without a…
Mogge Oct 4, 2022
4331c73
test post invisibility for unauthenticated users
Mogge Oct 4, 2022
77125e4
createPostMutation as function
Mogge Oct 4, 2022
068d622
createPostMutation as function
Mogge Oct 4, 2022
275d196
further testting for post visibility
Mogge Oct 4, 2022
0343407
fix cypher to have signup verification to block posts of groups for n…
Mogge Oct 4, 2022
67cba10
remove findPosts and findUsers as they are never used.
Mogge Oct 5, 2022
570d6c0
test filter posts
Mogge Oct 5, 2022
ab5d308
test profile page posts
Mogge Oct 5, 2022
aa870b5
searches need authorization as they are not working without user id i…
Mogge Oct 5, 2022
76bfe48
implement and test post visibilty when leaving or changing the role i…
Mogge Oct 5, 2022
a924357
fix cypher when posts do not exist
Mogge Oct 5, 2022
74505a1
filter posts for group visibility on search posts
Mogge Oct 5, 2022
a4cd7a8
test search posts with groups
Mogge Oct 5, 2022
4fdaa0d
Update backend/src/schema/resolvers/helpers/filterInvisiblePosts.js
Mogge Oct 6, 2022
4556276
fix: leaving public group keeps the posts in public group visible. Te…
Mogge Oct 10, 2022
631f34a
improved code and tests as suggested by @tirokk, thanks for the great…
Mogge Oct 10, 2022
7cb1663
change from role eq pending to usual, admin, owner includes role
Mogge Oct 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test post invisibility for unauthenticated users
Mogge committed Oct 4, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 4331c7341479328256eb38211f53ad87c782d39c
7 changes: 5 additions & 2 deletions backend/src/schema/resolvers/helpers/filterInvisiblePosts.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@ const getInvisiblePosts = async (context) => {
const session = context.driver.session()
const readTxResultPromise = await session.readTransaction(async (transaction) => {
let cypher = ''
if (context.user) {
const { user } = context
if (user && user.id) {
cypher = `
MATCH (post:Post)<-[:CANNOT_SEE]-(user:User { id: $userId })
RETURN collect(post.id) AS invisiblePostIds`
@@ -14,7 +15,9 @@ const getInvisiblePosts = async (context) => {
WHERE NOT group.groupType = 'public'
RETURN collect(post.id) AS invisiblePostIds`
Mogge marked this conversation as resolved.
Show resolved Hide resolved
}
const invisiblePostIdsResponse = await transaction.run(cypher, { userId: context.user.id })
const invisiblePostIdsResponse = await transaction.run(cypher, {
userId: user ? user.id : null,
})
return invisiblePostIdsResponse.records.map((record) => record.get('invisiblePostIds'))
})
try {
45 changes: 45 additions & 0 deletions backend/src/schema/resolvers/postsInGroups.spec.js
Original file line number Diff line number Diff line change
@@ -359,6 +359,51 @@ describe('Posts in Groups', () => {

describe('visibility of posts', () => {
describe('query post by ID', () => {
describe('without authentication', () => {
beforeEach(async () => {
Mogge marked this conversation as resolved.
Show resolved Hide resolved
authenticatedUser = null
})

it('shows a post of the public group', async () => {
await expect(
query({ query: postQuery(), variables: { id: 'post-to-public-group' } }),
).resolves.toMatchObject({
data: {
Post: expect.arrayContaining([
{
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
},
]),
},
errors: undefined,
})
})

it('does not show a post of a closed group', async () => {
await expect(
query({ query: postQuery(), variables: { id: 'post-to-closed-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
},
errors: undefined,
})
})

it('does not show a post of a hidden group', async () => {
await expect(
query({ query: postQuery(), variables: { id: 'post-to-hidden-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
},
errors: undefined,
})
})
})

describe('without membership of group', () => {
beforeEach(async () => {
authenticatedUser = await anyUser.toJson()