Skip to content

Commit

Permalink
improved code and tests as suggested by @Tirokk, thanks for the great…
Browse files Browse the repository at this point in the history
… review!
  • Loading branch information
Mogge committed Oct 10, 2022
1 parent 4556276 commit 631f34a
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 234 deletions.
11 changes: 5 additions & 6 deletions backend/src/schema/resolvers/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,16 @@ export default {
const session = context.driver.session()
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
let postRestrictionCypher = ''
if (['owner', 'admin', 'usual'].includes(roleInGroup)) {
if (roleInGroup === 'pending') {
postRestrictionCypher = `
WITH group, member, membership
FOREACH (restriction IN [(member)-[r:CANNOT_SEE]->(:Post)-[:IN]->(group) | r] |
DELETE restriction)`
FOREACH (post IN [(p:Post)-[:IN]->(group) | p] |
MERGE (member)-[:CANNOT_SEE]->(post))`
} else {
// user becomes pending member
postRestrictionCypher = `
WITH group, member, membership
FOREACH (post IN [(p:Post)-[:IN]->(group) | p] |
MERGE (member)-[:CANNOT_SEE]->(post))`
FOREACH (restriction IN [(member)-[r:CANNOT_SEE]->(:Post)-[:IN]->(group) | r] |
DELETE restriction)`
}

const joinGroupCypher = `
Expand Down
4 changes: 2 additions & 2 deletions backend/src/schema/resolvers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default {
WHERE group.groupType IN ['closed', 'hidden']
AND membership.role IN ['usual', 'admin', 'owner']
WITH post, collect(user.id) AS userIds
OPTIONAL MATCH path =(blocked:User) WHERE NOT blocked.id IN userIds
OPTIONAL MATCH path =(restricted:User) WHERE NOT restricted.id IN userIds
FOREACH (user IN nodes(path) |
MERGE (user)-[:CANNOT_SEE]->(post)
)`
Expand All @@ -129,7 +129,7 @@ export default {
${groupCypher}
RETURN post {.*}
`,
{ userId: context.user.id, params, categoryIds, groupId },
{ userId: context.user.id, categoryIds, groupId, params },
)
const [post] = createPostTransactionResponse.records.map((record) => record.get('post'))
if (imageInput) {
Expand Down
Loading

0 comments on commit 631f34a

Please sign in to comment.