From 411bbabcd5a95b558c7f5a09c1ccf3244916c479 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Fri, 18 Oct 2019 00:42:44 +0200 Subject: [PATCH] Add profilePagePostsQuery to deal with bug - we do not want to add pinnedPosts to every user's profile page --- .../src/middleware/permissionsMiddleware.js | 1 + backend/src/schema/resolvers/posts.js | 4 ++++ backend/src/schema/types/type/Post.gql | 1 + webapp/graphql/PostQuery.js | 20 +++++++++++++++++++ webapp/pages/profile/_id/_slug.vue | 8 ++++---- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/backend/src/middleware/permissionsMiddleware.js b/backend/src/middleware/permissionsMiddleware.js index 5d0e4f784..a0116a439 100644 --- a/backend/src/middleware/permissionsMiddleware.js +++ b/backend/src/middleware/permissionsMiddleware.js @@ -134,6 +134,7 @@ const permissions = shield( PostsEmotionsByCurrentUser: isAuthenticated, blockedUsers: isAuthenticated, notifications: isAuthenticated, + profilePagePosts: or(onlyEnabledContent, isModerator), }, Mutation: { '*': deny, diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index 97f2e78e7..e7c54375d 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -49,6 +49,10 @@ export default { params = await filterForBlockedUsers(params, context) return neo4jgraphql(object, params, context, resolveInfo, false) }, + profilePagePosts: async (object, params, context, resolveInfo) => { + params = await filterForBlockedUsers(params, context) + return neo4jgraphql(object, params, context, resolveInfo, false) + }, PostsEmotionsCountByEmotion: async (object, params, context, resolveInfo) => { const session = context.driver.session() const { postId, data } = params diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index cc05ce4d4..a7e0c76a3 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -95,4 +95,5 @@ type Mutation { type Query { PostsEmotionsCountByEmotion(postId: ID!, data: _EMOTEDInput!): Int! PostsEmotionsByCurrentUser(postId: ID!): [String] + profilePagePosts(filter: _PostFilter, first: Int, offset: Int, orderBy: [_PostOrdering]): [Post] } diff --git a/webapp/graphql/PostQuery.js b/webapp/graphql/PostQuery.js index bca276f64..3de1178b0 100644 --- a/webapp/graphql/PostQuery.js +++ b/webapp/graphql/PostQuery.js @@ -35,6 +35,26 @@ export const filterPosts = i18n => { ` } +export const profilePagePosts = i18n => { + const lang = i18n.locale().toUpperCase() + return gql` + ${postFragment(lang)} + ${postCountsFragment} + + query profilePagePosts( + $filter: _PostFilter + $first: Int + $offset: Int + $orderBy: [_PostOrdering] + ) { + profilePagePosts(filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) { + ...post + ...postCounts + } + } + ` +} + export const PostsEmotionsByCurrentUser = () => { return gql` query PostsEmotionsByCurrentUser($postId: ID!) { diff --git a/webapp/pages/profile/_id/_slug.vue b/webapp/pages/profile/_id/_slug.vue index 571d6bee7..6961046ab 100644 --- a/webapp/pages/profile/_id/_slug.vue +++ b/webapp/pages/profile/_id/_slug.vue @@ -281,7 +281,7 @@ import HcUpload from '~/components/Upload' import HcAvatar from '~/components/Avatar/Avatar.vue' import MasonryGrid from '~/components/MasonryGrid/MasonryGrid.vue' import MasonryGridItem from '~/components/MasonryGrid/MasonryGridItem.vue' -import { filterPosts } from '~/graphql/PostQuery' +import { profilePagePosts } from '~/graphql/PostQuery' import UserQuery from '~/graphql/User' import { Block, Unblock } from '~/graphql/settings/BlockedUsers' import PostMutations from '~/graphql/PostMutations' @@ -466,7 +466,7 @@ export default { apollo: { Post: { query() { - return filterPosts(this.$i18n) + return profilePagePosts(this.$i18n) }, variables() { return { @@ -476,8 +476,8 @@ export default { orderBy: ['pinnedAt_asc', 'createdAt_desc'], } }, - update({ Post }) { - this.posts = Post + update({ profilePagePosts }) { + this.posts = profilePagePosts }, fetchPolicy: 'cache-and-network', },