mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Blocked users cannot comment on my posts
This commit is contained in:
parent
36dadfb4c1
commit
5d5574b1b5
@ -102,6 +102,7 @@ export default shield(
|
||||
blockedUsers: isAuthenticated,
|
||||
notifications: isAuthenticated,
|
||||
Donations: isAuthenticated,
|
||||
blockedByPostAuthor: isAuthenticated,
|
||||
},
|
||||
Mutation: {
|
||||
'*': deny,
|
||||
|
||||
@ -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)
|
||||
},
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
</client-only>
|
||||
</ds-space>
|
||||
<div v-if="openEditCommentMenu">
|
||||
<hc-comment-form
|
||||
<comment-form
|
||||
:update="true"
|
||||
:post="post"
|
||||
:comment="comment"
|
||||
@ -64,7 +64,7 @@ import { COMMENT_MAX_UNTRUNCATED_LENGTH, COMMENT_TRUNCATE_TO_LENGTH } from '~/co
|
||||
import HcUser from '~/components/User/User'
|
||||
import ContentMenu from '~/components/ContentMenu/ContentMenu'
|
||||
import ContentViewer from '~/components/Editor/ContentViewer'
|
||||
import HcCommentForm from '~/components/CommentForm/CommentForm'
|
||||
import CommentForm from '~/components/CommentForm/CommentForm'
|
||||
import CommentMutations from '~/graphql/CommentMutations'
|
||||
import scrollToAnchor from '~/mixins/scrollToAnchor.js'
|
||||
|
||||
@ -85,7 +85,7 @@ export default {
|
||||
HcUser,
|
||||
ContentMenu,
|
||||
ContentViewer,
|
||||
HcCommentForm,
|
||||
CommentForm,
|
||||
},
|
||||
props: {
|
||||
routeHash: { type: String, default: () => '' },
|
||||
|
||||
@ -216,3 +216,10 @@ export const checkSlugAvailableQuery = gql`
|
||||
}
|
||||
}
|
||||
`
|
||||
export const blockedByPostAuthor = () => {
|
||||
return gql`
|
||||
query($postAuthorId: ID!) {
|
||||
blockedByPostAuthor(postAuthorId: $postAuthorId)
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -89,7 +89,19 @@
|
||||
@toggleNewCommentForm="toggleNewCommentForm"
|
||||
/>
|
||||
<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-card>
|
||||
</transition>
|
||||
@ -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',
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user