diff --git a/backend/src/middleware/permissionsMiddleware.js b/backend/src/middleware/permissionsMiddleware.js index 3b42ae7fe..12a557232 100644 --- a/backend/src/middleware/permissionsMiddleware.js +++ b/backend/src/middleware/permissionsMiddleware.js @@ -102,6 +102,7 @@ export default shield( blockedUsers: isAuthenticated, notifications: isAuthenticated, Donations: isAuthenticated, + blockedByPostAuthor: isAuthenticated, }, Mutation: { '*': deny, diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index 47223faea..619b1de25 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -42,7 +42,7 @@ const maintainPinnedPosts = params => { export default { Query: { Post: async (object, params, context, resolveInfo) => { - params = await filterForBlockedUsers(params, context) + // params = await filterForBlockedUsers(params, context) params = await maintainPinnedPosts(params) return neo4jgraphql(object, params, context, resolveInfo) }, diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index 0b3f13631..c2600ab24 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -48,6 +48,29 @@ export default { throw new UserInputError(e.message) } }, + blockedByPostAuthor: async (_parent, params, context, _resolveInfo) => { + const { postAuthorId } = params + const { user, driver } = context + const session = driver.session() + const readTxResultPromise = session.readTransaction(async transaction => { + const blockedByPostAuthorTransactionResponse = await transaction.run( + ` + MATCH (currentUser:User {id: $currentUserId})<-[relationship:BLOCKED]-(postAuthor:User {id: $postAuthorId}) + RETURN COUNT(relationship) >= 1 as blockedByPostAuthor + `, + { postAuthorId, currentUserId: user.id }, + ) + return blockedByPostAuthorTransactionResponse.records.map(record => + record.get('blockedByPostAuthor'), + ) + }) + try { + const [blockedByPostAuthor] = await readTxResultPromise + return blockedByPostAuthor + } finally { + session.close() + } + }, User: async (object, args, context, resolveInfo) => { const { email } = args if (email) { diff --git a/backend/src/schema/types/type/User.gql b/backend/src/schema/types/type/User.gql index 243f45322..17ee2a733 100644 --- a/backend/src/schema/types/type/User.gql +++ b/backend/src/schema/types/type/User.gql @@ -68,10 +68,11 @@ type User { RETURN COUNT(u) >= 1 """ ) + isBlocked: Boolean! @cypher( statement: """ - MATCH (this)<-[: BLOCKED]-(u: User { id: $cypherParams.currentUserId}) - RETURN COUNT(u) >= 1 + MATCH (this)<-[:BLOCKED]-(user:User {id: $cypherParams.currentUserId}) + RETURN COUNT(user) >= 1 """ ) @@ -159,7 +160,7 @@ type Query { orderBy: [_UserOrdering] filter: _UserFilter ): [User] - + blockedByPostAuthor(postAuthorId: ID!): Boolean! blockedUsers: [User] currentUser: User } diff --git a/webapp/components/Comment/Comment.vue b/webapp/components/Comment/Comment.vue index cc7f815b9..f776aa413 100644 --- a/webapp/components/Comment/Comment.vue +++ b/webapp/components/Comment/Comment.vue @@ -33,7 +33,7 @@
- '' }, diff --git a/webapp/graphql/User.js b/webapp/graphql/User.js index 4ed832ad3..fa4b47423 100644 --- a/webapp/graphql/User.js +++ b/webapp/graphql/User.js @@ -216,3 +216,10 @@ export const checkSlugAvailableQuery = gql` } } ` +export const blockedByPostAuthor = () => { + return gql` + query($postAuthorId: ID!) { + blockedByPostAuthor(postAuthorId: $postAuthorId) + } + ` +} diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 6d8401e21..7d970998d 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -317,7 +317,9 @@ "their-perspective": "Vice versa: The blocked person will also no longer see your posts in their news feed.", "search": "Posts of blocked people disappear from your search results.", "notifications": "Blocked users will no longer receive notifications if they are mentioned in your posts.", - "closing": "This should be sufficient for now so that blocked users can no longer bother you." + "closing": "This should be sufficient for now so that blocked users can no longer bother you.", + "commenting-disabled": "Commenting is not possible at this time on this post.", + "commenting-explanation": "This can happen for several reasons, please see " }, "columns": { "name": "Name", diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index a94bf7b2d..bdfa13cf2 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -89,7 +89,19 @@ @toggleNewCommentForm="toggleNewCommentForm" /> - + + + + {{ $t('settings.blocked-users.explanation.commenting-disabled') }} +
+ {{ $t('settings.blocked-users.explanation.commenting-explanation') }} + https://human-connection.org +
+
@@ -102,12 +114,13 @@ import HcHashtag from '~/components/Hashtag/Hashtag' import ContentMenu from '~/components/ContentMenu/ContentMenu' import HcUser from '~/components/User/User' import HcShoutButton from '~/components/ShoutButton.vue' -import HcCommentForm from '~/components/CommentForm/CommentForm' +import CommentForm from '~/components/CommentForm/CommentForm' import HcCommentList from '~/components/CommentList/CommentList' import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers' import PostQuery from '~/graphql/PostQuery' import HcEmotions from '~/components/Emotions/Emotions' import PostMutations from '~/graphql/PostMutations' +import { blockedByPostAuthor } from '~/graphql/User' export default { name: 'PostSlug', @@ -121,7 +134,7 @@ export default { HcUser, HcShoutButton, ContentMenu, - HcCommentForm, + CommentForm, HcCommentList, HcEmotions, ContentViewer, @@ -138,15 +151,10 @@ export default { title: 'loading', showNewCommentForm: true, blurred: false, + blocked: null, + postAuthor: null, } }, - watch: { - Post(post) { - this.post = post[0] || {} - this.title = this.post.title - this.blurred = this.post.imageBlurred - }, - }, mounted() { setTimeout(() => { // NOTE: quick fix for jumping flexbox implementation @@ -215,6 +223,26 @@ export default { id: this.$route.params.id, } }, + update({ Post }) { + this.post = Post[0] || {} + this.title = this.post.title + this.blurred = this.post.imageBlurred + this.postAuthor = this.post.author + }, + fetchPolicy: 'cache-and-network', + }, + blockedByPostAuthor: { + query() { + return blockedByPostAuthor() + }, + variables() { + return { + postAuthorId: this.postAuthor ? this.postAuthor.id : this.$store.getters['auth/user'].id, + } + }, + update({ blockedByPostAuthor }) { + this.blocked = blockedByPostAuthor + }, fetchPolicy: 'cache-and-network', }, },