Blocked users cannot comment on my posts

This commit is contained in:
mattwr18 2020-01-09 16:07:25 +01:00
parent 36dadfb4c1
commit 5d5574b1b5
8 changed files with 80 additions and 18 deletions

View File

@ -102,6 +102,7 @@ export default shield(
blockedUsers: isAuthenticated, blockedUsers: isAuthenticated,
notifications: isAuthenticated, notifications: isAuthenticated,
Donations: isAuthenticated, Donations: isAuthenticated,
blockedByPostAuthor: isAuthenticated,
}, },
Mutation: { Mutation: {
'*': deny, '*': deny,

View File

@ -42,7 +42,7 @@ const maintainPinnedPosts = params => {
export default { export default {
Query: { Query: {
Post: async (object, params, context, resolveInfo) => { Post: async (object, params, context, resolveInfo) => {
params = await filterForBlockedUsers(params, context) // params = await filterForBlockedUsers(params, context)
params = await maintainPinnedPosts(params) params = await maintainPinnedPosts(params)
return neo4jgraphql(object, params, context, resolveInfo) return neo4jgraphql(object, params, context, resolveInfo)
}, },

View File

@ -48,6 +48,29 @@ export default {
throw new UserInputError(e.message) 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) => { User: async (object, args, context, resolveInfo) => {
const { email } = args const { email } = args
if (email) { if (email) {

View File

@ -68,10 +68,11 @@ type User {
RETURN COUNT(u) >= 1 RETURN COUNT(u) >= 1
""" """
) )
isBlocked: Boolean! @cypher( isBlocked: Boolean! @cypher(
statement: """ statement: """
MATCH (this)<-[: BLOCKED]-(u: User { id: $cypherParams.currentUserId}) MATCH (this)<-[:BLOCKED]-(user:User {id: $cypherParams.currentUserId})
RETURN COUNT(u) >= 1 RETURN COUNT(user) >= 1
""" """
) )
@ -159,7 +160,7 @@ type Query {
orderBy: [_UserOrdering] orderBy: [_UserOrdering]
filter: _UserFilter filter: _UserFilter
): [User] ): [User]
blockedByPostAuthor(postAuthorId: ID!): Boolean!
blockedUsers: [User] blockedUsers: [User]
currentUser: User currentUser: User
} }

View File

@ -33,7 +33,7 @@
</client-only> </client-only>
</ds-space> </ds-space>
<div v-if="openEditCommentMenu"> <div v-if="openEditCommentMenu">
<hc-comment-form <comment-form
:update="true" :update="true"
:post="post" :post="post"
:comment="comment" :comment="comment"
@ -64,7 +64,7 @@ import { COMMENT_MAX_UNTRUNCATED_LENGTH, COMMENT_TRUNCATE_TO_LENGTH } from '~/co
import HcUser from '~/components/User/User' import HcUser from '~/components/User/User'
import ContentMenu from '~/components/ContentMenu/ContentMenu' import ContentMenu from '~/components/ContentMenu/ContentMenu'
import ContentViewer from '~/components/Editor/ContentViewer' import ContentViewer from '~/components/Editor/ContentViewer'
import HcCommentForm from '~/components/CommentForm/CommentForm' import CommentForm from '~/components/CommentForm/CommentForm'
import CommentMutations from '~/graphql/CommentMutations' import CommentMutations from '~/graphql/CommentMutations'
import scrollToAnchor from '~/mixins/scrollToAnchor.js' import scrollToAnchor from '~/mixins/scrollToAnchor.js'
@ -85,7 +85,7 @@ export default {
HcUser, HcUser,
ContentMenu, ContentMenu,
ContentViewer, ContentViewer,
HcCommentForm, CommentForm,
}, },
props: { props: {
routeHash: { type: String, default: () => '' }, routeHash: { type: String, default: () => '' },

View File

@ -216,3 +216,10 @@ export const checkSlugAvailableQuery = gql`
} }
} }
` `
export const blockedByPostAuthor = () => {
return gql`
query($postAuthorId: ID!) {
blockedByPostAuthor(postAuthorId: $postAuthorId)
}
`
}

View File

@ -317,7 +317,9 @@
"their-perspective": "Vice versa: The blocked person will also no longer see your posts in their news feed.", "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.", "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.", "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": { "columns": {
"name": "Name", "name": "Name",

View File

@ -89,7 +89,19 @@
@toggleNewCommentForm="toggleNewCommentForm" @toggleNewCommentForm="toggleNewCommentForm"
/> />
<ds-space margin-bottom="large" /> <ds-space margin-bottom="large" />
<hc-comment-form v-if="showNewCommentForm" :post="post" @createComment="createComment" /> <comment-form
v-if="showNewCommentForm && !this.blocked"
:post="post"
@createComment="createComment"
/>
<ds-space v-else>
<ds-placeholder>
{{ $t('settings.blocked-users.explanation.commenting-disabled') }}
<br />
{{ $t('settings.blocked-users.explanation.commenting-explanation') }}
<a>https://human-connection.org</a>
</ds-placeholder>
</ds-space>
</ds-section> </ds-section>
</ds-card> </ds-card>
</transition> </transition>
@ -102,12 +114,13 @@ import HcHashtag from '~/components/Hashtag/Hashtag'
import ContentMenu from '~/components/ContentMenu/ContentMenu' import ContentMenu from '~/components/ContentMenu/ContentMenu'
import HcUser from '~/components/User/User' import HcUser from '~/components/User/User'
import HcShoutButton from '~/components/ShoutButton.vue' 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 HcCommentList from '~/components/CommentList/CommentList'
import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers' import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostHelpers'
import PostQuery from '~/graphql/PostQuery' import PostQuery from '~/graphql/PostQuery'
import HcEmotions from '~/components/Emotions/Emotions' import HcEmotions from '~/components/Emotions/Emotions'
import PostMutations from '~/graphql/PostMutations' import PostMutations from '~/graphql/PostMutations'
import { blockedByPostAuthor } from '~/graphql/User'
export default { export default {
name: 'PostSlug', name: 'PostSlug',
@ -121,7 +134,7 @@ export default {
HcUser, HcUser,
HcShoutButton, HcShoutButton,
ContentMenu, ContentMenu,
HcCommentForm, CommentForm,
HcCommentList, HcCommentList,
HcEmotions, HcEmotions,
ContentViewer, ContentViewer,
@ -138,15 +151,10 @@ export default {
title: 'loading', title: 'loading',
showNewCommentForm: true, showNewCommentForm: true,
blurred: false, blurred: false,
blocked: null,
postAuthor: null,
} }
}, },
watch: {
Post(post) {
this.post = post[0] || {}
this.title = this.post.title
this.blurred = this.post.imageBlurred
},
},
mounted() { mounted() {
setTimeout(() => { setTimeout(() => {
// NOTE: quick fix for jumping flexbox implementation // NOTE: quick fix for jumping flexbox implementation
@ -215,6 +223,26 @@ export default {
id: this.$route.params.id, 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', fetchPolicy: 'cache-and-network',
}, },
}, },