Merge branch 'master' of https://github.com/Human-Connection/Human-Connection into 1062-notification-about-comment-on-post

# Conflicts:
#	backend/src/middleware/index.js
This commit is contained in:
Wolfgang Huß 2019-08-23 15:31:48 +02:00
commit df4f0627b5
19 changed files with 998 additions and 1007 deletions

View File

@ -61,7 +61,7 @@
"dotenv": "~8.1.0",
"express": "^4.17.1",
"faker": "Marak/faker.js#master",
"graphql": "~14.4.2",
"graphql": "^14.5.0",
"graphql-custom-directives": "~0.2.14",
"graphql-iso-date": "~3.6.1",
"graphql-middleware": "~3.0.5",
@ -118,7 +118,7 @@
"cucumber": "~5.1.0",
"eslint": "~6.2.1",
"eslint-config-prettier": "~6.1.0",
"eslint-config-standard": "~14.0.0",
"eslint-config-standard": "~14.0.1",
"eslint-plugin-import": "~2.18.2",
"eslint-plugin-jest": "~22.15.2",
"eslint-plugin-node": "~9.1.0",

View File

@ -4,7 +4,7 @@ import CONFIG from './../config'
// Generate an Access Token for the given User ID
export default function encode(user) {
const token = jwt.sign(user, CONFIG.JWT_SECRET, {
expiresIn: 24 * 60 * 60 * 1000, // one day
expiresIn: '1d',
issuer: CONFIG.GRAPHQL_URI,
audience: CONFIG.CLIENT_URI,
subject: user.id.toString(),

View File

@ -18,22 +18,20 @@ import sentry from './sentryMiddleware'
export default schema => {
const middlewares = {
permissions: permissions,
sentry: sentry,
activityPub: activityPub,
dateTime: dateTime,
validation: validation,
sluggify: sluggify,
excerpt: excerpt,
handleNotifications: handleNotifications,
xss: xss,
softDelete: softDelete,
user: user,
includedFields: includedFields,
orderBy: orderBy,
email: email({
isEnabled: CONFIG.SMTP_HOST && CONFIG.SMTP_PORT,
}),
permissions,
sentry,
activityPub,
dateTime,
validation,
sluggify,
excerpt,
handleNotifications,
xss,
softDelete,
user,
includedFields,
orderBy,
email: email({ isEnabled: CONFIG.SMTP_HOST && CONFIG.SMTP_PORT }),
}
let order = [

View File

@ -2,6 +2,8 @@ import { UserInputError } from 'apollo-server'
const COMMENT_MIN_LENGTH = 1
const NO_POST_ERR_MESSAGE = 'Comment cannot be created without a post!'
const NO_CATEGORIES_ERR_MESSAGE =
'You cannot save a post without at least one category or more than three'
const validateCommentCreation = async (resolve, root, args, context, info) => {
const content = args.content.replace(/<(?:.|\n)*?>/gm, '').trim()
@ -19,6 +21,7 @@ const validateCommentCreation = async (resolve, root, args, context, info) => {
postId,
},
)
session.close()
const [post] = postQueryRes.records.map(record => {
return record.get('post')
})
@ -43,9 +46,33 @@ const validateUpdateComment = async (resolve, root, args, context, info) => {
const validatePost = async (resolve, root, args, context, info) => {
const { categoryIds } = args
if (!Array.isArray(categoryIds) || !categoryIds.length || categoryIds.length > 3) {
throw new UserInputError(
'You cannot save a post without at least one category or more than three',
)
throw new UserInputError(NO_CATEGORIES_ERR_MESSAGE)
}
return resolve(root, args, context, info)
}
const validateUpdatePost = async (resolve, root, args, context, info) => {
const { id, categoryIds } = args
const session = context.driver.session()
const categoryQueryRes = await session.run(
`
MATCH (post:Post {id: $id})-[:CATEGORIZED]->(category:Category)
RETURN category`,
{ id },
)
session.close()
const [category] = categoryQueryRes.records.map(record => {
return record.get('category')
})
if (category) {
if (categoryIds && categoryIds.length > 3) {
throw new UserInputError(NO_CATEGORIES_ERR_MESSAGE)
}
} else {
if (!Array.isArray(categoryIds) || !categoryIds.length || categoryIds.length > 3) {
throw new UserInputError(NO_CATEGORIES_ERR_MESSAGE)
}
}
return resolve(root, args, context, info)
}
@ -55,6 +82,6 @@ export default {
CreateComment: validateCommentCreation,
UpdateComment: validateUpdateComment,
CreatePost: validatePost,
UpdatePost: validatePost,
UpdatePost: validateUpdatePost,
},
}

View File

@ -75,22 +75,28 @@ export default {
delete params.categoryIds
params = await fileUpload(params, { file: 'imageUpload', url: 'image' })
const session = context.driver.session()
const cypherDeletePreviousRelations = `
MATCH (post:Post { id: $params.id })-[previousRelations:CATEGORIZED]->(category:Category)
DELETE previousRelations
RETURN post, category
let updatePostCypher = `MATCH (post:Post {id: $params.id})
SET post = $params
`
await session.run(cypherDeletePreviousRelations, { params })
if (categoryIds && categoryIds.length) {
const cypherDeletePreviousRelations = `
MATCH (post:Post { id: $params.id })-[previousRelations:CATEGORIZED]->(category:Category)
DELETE previousRelations
RETURN post, category
`
const updatePostCypher = `MATCH (post:Post {id: $params.id})
SET post = $params
WITH post
await session.run(cypherDeletePreviousRelations, { params })
updatePostCypher += `WITH post
UNWIND $categoryIds AS categoryId
MATCH (category:Category {id: categoryId})
MERGE (post)-[:CATEGORIZED]->(category)
RETURN post`
`
}
updatePostCypher += `RETURN post`
const updatePostVariables = { categoryIds, params }
const transactionRes = await session.run(updatePostCypher, updatePostVariables)

View File

@ -13,6 +13,7 @@ let client
let userParams
let authorParams
const postId = 'p3589'
const postTitle = 'I am a title'
const postContent = 'Some content'
const oldTitle = 'Old title'
@ -96,7 +97,7 @@ beforeEach(async () => {
}),
])
createPostVariables = {
id: 'p3589',
id: postId,
title: postTitle,
content: postContent,
categoryIds,
@ -218,7 +219,7 @@ describe('CreatePost', () => {
Post: [
{
title: postTitle,
id: 'p3589',
id: postId,
categories: expect.arrayContaining(categoryIdsArray),
},
],
@ -246,17 +247,16 @@ describe('UpdatePost', () => {
await asAuthor.create('User', authorParams)
await asAuthor.authenticateAs(authorParams)
await asAuthor.create('Post', {
id: 'p1',
id: postId,
title: oldTitle,
content: oldContent,
categoryIds,
})
updatePostVariables = {
id: 'p1',
id: postId,
title: newTitle,
content: newContent,
categoryIds: null,
}
})
@ -291,55 +291,96 @@ describe('UpdatePost', () => {
})
it('updates a post', async () => {
updatePostVariables.categoryIds = ['cat9']
const expected = { UpdatePost: { id: 'p1', content: newContent } }
updatePostVariables.categoryIds = ['cat27']
const expected = { UpdatePost: { id: postId, content: newContent } }
await expect(client.request(updatePostMutation, updatePostVariables)).resolves.toEqual(
expected,
)
})
describe('categories', () => {
beforeEach(async () => {
await client.request(createPostMutation, createPostVariables)
updatePostVariables = {
id: 'p3589',
title: newTitle,
content: newContent,
categoryIds: ['cat27'],
}
it('allows a user to update other attributes without passing in categoryIds explicitly', async () => {
const expected = { UpdatePost: { id: postId, content: newContent } }
await expect(client.request(updatePostMutation, updatePostVariables)).resolves.toEqual(
expected,
)
})
it('allows a user to update the categories of a post', async () => {
updatePostVariables.categoryIds = ['cat27']
await client.request(updatePostMutation, updatePostVariables)
const expected = [{ id: 'cat27' }]
const postQueryWithCategoriesVariables = {
id: 'p3589',
id: postId,
}
await expect(
client.request(postQueryWithCategories, postQueryWithCategoriesVariables),
).resolves.toEqual({ Post: [{ categories: expect.arrayContaining(expected) }] })
})
it('throws an error if categoryIds is not an array', async () => {
updatePostVariables.categoryIds = null
await expect(client.request(updatePostMutation, updatePostVariables)).rejects.toThrow(
postSaveError,
)
})
it('requires at least one category for successful update', async () => {
updatePostVariables.categoryIds = []
await expect(client.request(updatePostMutation, updatePostVariables)).rejects.toThrow(
postSaveError,
)
})
it('allows a maximum of three category for a successful update', async () => {
updatePostVariables.categoryIds = ['cat9', 'cat27', 'cat15', 'cat4']
await expect(client.request(updatePostMutation, updatePostVariables)).rejects.toThrow(
postSaveError,
)
})
describe('post created without categories somehow', () => {
let ownerNode, owner, postMutationAction
beforeEach(async () => {
const postSomehowCreated = await instance.create('Post', {
id: 'how-was-this-created',
title: postTitle,
content: postContent,
})
ownerNode = await instance.create('User', {
id: 'author-of-post-without-category',
name: 'Hacker',
slug: 'hacker',
email: 'hacker@example.org',
password: '1234',
})
owner = await ownerNode.toJson()
await postSomehowCreated.relateTo(ownerNode, 'author')
postMutationAction = async (user, mutation, variables) => {
const { server } = createServer({
context: () => {
return {
user,
neode: instance,
driver,
}
},
})
const { mutate } = createTestClient(server)
return mutate({
mutation,
variables,
})
}
updatePostVariables.id = 'how-was-this-created'
})
it('throws an error if categoryIds is not an array', async () => {
const mustAddCategoryToPost = await postMutationAction(
owner,
updatePostMutation,
updatePostVariables,
)
expect(mustAddCategoryToPost.errors[0]).toHaveProperty('message', postSaveError)
})
it('requires at least one category for successful update', async () => {
updatePostVariables.categoryIds = []
const mustAddCategoryToPost = await postMutationAction(
owner,
updatePostMutation,
updatePostVariables,
)
expect(mustAddCategoryToPost.errors[0]).toHaveProperty('message', postSaveError)
})
})
})
})
})
@ -355,7 +396,7 @@ describe('DeletePost', () => {
`
const variables = {
id: 'p1',
id: postId,
}
beforeEach(async () => {
@ -363,7 +404,7 @@ describe('DeletePost', () => {
await asAuthor.create('User', authorParams)
await asAuthor.authenticateAs(authorParams)
await asAuthor.create('Post', {
id: 'p1',
id: postId,
content: 'To be deleted',
categoryIds,
})
@ -396,7 +437,7 @@ describe('DeletePost', () => {
})
it('deletes a post', async () => {
const expected = { DeletePost: { id: 'p1', content: 'To be deleted' } }
const expected = { DeletePost: { id: postId, content: 'To be deleted' } }
await expect(client.request(mutation, variables)).resolves.toEqual(expected)
})
})

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@
"codecov": "^3.5.0",
"cross-env": "^5.2.0",
"cypress": "^3.4.1",
"cypress-cucumber-preprocessor": "^1.14.0",
"cypress-cucumber-preprocessor": "^1.14.1",
"cypress-file-upload": "^3.3.3",
"cypress-plugin-retries": "^1.2.2",
"dotenv": "^8.1.0",

View File

@ -54,6 +54,7 @@ describe('FilterPosts.vue', () => {
'postsFilter/TOGGLE_CATEGORY': jest.fn(),
}
getters = {
'postsFilter/isActive': () => false,
'auth/user': () => {
return { id: 'u34' }
},
@ -63,7 +64,7 @@ describe('FilterPosts.vue', () => {
const openFilterPosts = () => {
const store = new Vuex.Store({ mutations, getters })
const wrapper = mount(FilterPosts, { mocks, localVue, propsData, store })
menuToggle = wrapper.findAll('a').at(0)
menuToggle = wrapper.findAll('button').at(0)
menuToggle.trigger('click')
return wrapper
}
@ -81,13 +82,13 @@ describe('FilterPosts.vue', () => {
it('starts with all categories button active', () => {
const wrapper = openFilterPosts()
allCategoriesButton = wrapper.findAll('button').at(0)
allCategoriesButton = wrapper.findAll('button').at(1)
expect(allCategoriesButton.attributes().class).toContain('ds-button-primary')
})
it('calls TOGGLE_CATEGORY when clicked', () => {
const wrapper = openFilterPosts()
environmentAndNatureButton = wrapper.findAll('button').at(1)
environmentAndNatureButton = wrapper.findAll('button').at(2)
environmentAndNatureButton.trigger('click')
expect(mutations['postsFilter/TOGGLE_CATEGORY']).toHaveBeenCalledWith({}, 'cat4')
})
@ -95,7 +96,7 @@ describe('FilterPosts.vue', () => {
it('sets category button attribute `primary` when corresponding category is filtered', () => {
getters['postsFilter/filteredCategoryIds'] = jest.fn(() => ['cat9'])
const wrapper = openFilterPosts()
democracyAndPoliticsButton = wrapper.findAll('button').at(3)
democracyAndPoliticsButton = wrapper.findAll('button').at(4)
expect(democracyAndPoliticsButton.attributes().class).toContain('ds-button-primary')
})

View File

@ -1,9 +1,15 @@
<template>
<dropdown ref="menu" :placement="placement" :offset="offset">
<a slot="default" slot-scope="{ toggleMenu }" href="#" @click.prevent="toggleMenu()">
<ds-icon style="margin: 12px 0px 0px 10px;" name="filter" size="large" />
<ds-icon style="margin: 7px 0px 0px 2px" size="xx-small" name="angle-down" />
</a>
<ds-button
slot="default"
icon="filter"
:primary="filterActive"
:ghost="!filterActive"
slot-scope="{ toggleMenu }"
@click.prevent="toggleMenu()"
>
<ds-icon size="xx-small" name="angle-down" />
</ds-button>
<template slot="popover">
<filter-posts-menu-items :chunk="chunk" :user="currentUser" />
</template>
@ -28,6 +34,7 @@ export default {
computed: {
...mapGetters({
currentUser: 'auth/user',
filterActive: 'postsFilter/isActive',
}),
chunk() {
return _.chunk(this.categories, 2)

View File

@ -24,6 +24,7 @@ export default i18n => {
badgesCount
shoutedCount
commentedCount
contributionsCount
followingCount
following(first: 7) {
id

View File

@ -3,7 +3,7 @@
<div class="main-navigation">
<ds-container class="main-navigation-container" style="padding: 10px 10px;">
<div>
<ds-flex class="main-navigation-flex">
<ds-flex class="main-navigation-flex" centered>
<ds-flex-item :width="{ lg: '3.5%' }" />
<ds-flex-item :width="{ base: '80%', sm: '80%', md: '80%', lg: '15%' }">
<a @click="redirectToRoot">
@ -293,6 +293,11 @@ export default {
padding-top: 6rem;
padding-bottom: 5rem;
}
.main-navigation-flex {
align-items: center;
}
.main-navigation {
a {
color: $text-color-soft;

View File

@ -271,7 +271,7 @@ module.exports = {
apollo: {
tokenName: 'human-connection-token', // optional, default: apollo-token
cookieAttributes: {
expires: 3, // optional, default: 7 (days)
expires: 1, // optional, default: 7 (days)
},
// includeNodeModules: true, // optional, default: false (this includes graphql-tag for node_modules folder)

View File

@ -63,7 +63,7 @@
"cross-env": "~5.2.0",
"date-fns": "2.0.0",
"express": "~4.17.1",
"graphql": "~14.4.2",
"graphql": "~14.5.0",
"isemail": "^3.2.0",
"jsonwebtoken": "~8.5.1",
"linkify-it": "~2.2.0",
@ -78,7 +78,7 @@
"v-tooltip": "~2.0.2",
"vue-count-to": "~1.0.13",
"vue-infinite-scroll": "^2.0.2",
"vue-izitoast": "roschaefer/vue-izitoast#patch-1",
"vue-izitoast": "^1.2.0",
"vue-sweetalert-icons": "~4.2.0",
"vuex-i18n": "~1.13.1",
"zxcvbn": "^4.4.2"

View File

@ -144,10 +144,4 @@ export const actions = {
commit('SET_TOKEN', null)
return this.app.$apolloHelpers.onLogout()
},
register({ dispatch, commit }, { email, password, inviteCode, invitedByUserId }) {},
async patch({ state, commit, dispatch }, data) {},
resendVerifySignup({ state, dispatch }) {},
resetPassword({ state }, data) {},
setNewPassword({ state }, data) {},
}

View File

@ -2,11 +2,16 @@ import get from 'lodash/get'
import update from 'lodash/update'
import xor from 'lodash/xor'
import isEmpty from 'lodash/isEmpty'
import isEqual from 'lodash/isEqual'
import clone from 'lodash/clone'
const defaultFilter = {}
export const state = () => {
return {
filter: {},
filter: {
...defaultFilter,
},
}
}
@ -38,6 +43,9 @@ export const mutations = {
}
export const getters = {
isActive(state) {
return !isEqual(state.filter, defaultFilter)
},
postsFilter(state) {
return state.filter
},

View File

@ -4,6 +4,15 @@ let state
let testAction
describe('getters', () => {
describe('isActive', () => {
it('returns true if filter differs from default setting', () => {
state = { filter: {} }
expect(getters.isActive(state)).toEqual(false)
state = { filter: { categories_some: { id_in: [24] } } }
expect(getters.isActive(state)).toEqual(true)
})
})
describe('filteredCategoryIds', () => {
it('returns category ids if filter is set', () => {
state = { filter: { categories_some: { id_in: [24] } } }

View File

@ -7624,10 +7624,10 @@ graphql-upload@^8.0.2:
http-errors "^1.7.2"
object-path "^0.11.4"
"graphql@14.0.2 - 14.2.0 || ^14.3.1", graphql@^14.4.0, graphql@~14.4.2:
version "14.4.2"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.4.2.tgz#553a7d546d524663eda49ed6df77577be3203ae3"
integrity sha512-6uQadiRgnpnSS56hdZUSvFrVcQ6OF9y6wkxJfKquFtHlnl7+KSuWwSJsdwiK1vybm1HgcdbpGkCpvhvsVQ0UZQ==
"graphql@14.0.2 - 14.2.0 || ^14.3.1", graphql@^14.4.0, graphql@~14.5.0:
version "14.5.0"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.5.0.tgz#4801e6460942c9c591944617f6dd224a9e531520"
integrity sha512-wnGcTD181L2xPnIwHHjx/moV4ulxA2Kms9zcUY+B/SIrK+2N+iOC6WNgnR2zVTmg1Z8P+CZq5KXibTnatg3WUw==
dependencies:
iterall "^1.2.2"
@ -8851,7 +8851,7 @@ iterall@^1.1.3, iterall@^1.2.1, iterall@^1.2.2:
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"
integrity sha512-yynBb1g+RFUPY64fTrFv7nsjRrENBQJaX2UL+2Szc9REFrSNm1rpSXHGzhmAy7a9uv3vlvgBlXnf9RqmPH1/DA==
izitoast@^1.3.0:
izitoast@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/izitoast/-/izitoast-1.4.0.tgz#1aa4e3408b7159fba743506af66d8be54fd929fb"
integrity sha512-Oc1X2wiQtPp39i5VpIjf3GJf5sfCtHKXZ5szx7RareyEeFLUlcEW0FSfBni28+Ul6KNKZRKzhVuWzSP4Xngh0w==
@ -15159,11 +15159,12 @@ vue-infinite-scroll@^2.0.2:
resolved "https://registry.yarnpkg.com/vue-infinite-scroll/-/vue-infinite-scroll-2.0.2.tgz#ca37a91fe92ee0ad3b74acf8682c00917144b711"
integrity sha512-n+YghR059YmciANGJh9SsNWRi1YZEBVlODtmnb/12zI+4R72QZSWd+EuZ5mW6auEo/yaJXgxzwsuhvALVnm73A==
vue-izitoast@roschaefer/vue-izitoast#patch-1:
version "1.1.2"
resolved "https://codeload.github.com/roschaefer/vue-izitoast/tar.gz/ba6b03eb24c7c04c299e64a9703e101bf158ae50"
vue-izitoast@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/vue-izitoast/-/vue-izitoast-1.2.0.tgz#55b7434a391c6eb64dd10c0de211e99ba7e486e2"
integrity sha512-Jqxfid12SUBIySJxgyPpu6gZ1ssMcbKtCvu9uMQPNM8RUnd3RKC4nyxkncdYe5L6XPU+SaznjYRudnvtclY4wA==
dependencies:
izitoast "^1.3.0"
izitoast "^1.4.0"
vue-jest@~3.0.4:
version "3.0.4"

View File

@ -1847,10 +1847,10 @@ cucumber@^4.2.1:
util-arity "^1.0.2"
verror "^1.9.0"
cypress-cucumber-preprocessor@^1.14.0:
version "1.14.0"
resolved "https://registry.yarnpkg.com/cypress-cucumber-preprocessor/-/cypress-cucumber-preprocessor-1.14.0.tgz#79fa9d4da72e2cb56bf511c17c77f8200b3279f1"
integrity sha512-eo79d7XCX4JG5wWGQJ2tuONTEgQfZHNGvuBMwTNjvZcz+qEVy04kdiBzbQGB7uy2Lf9LAkabt1hKUjwewmMioA==
cypress-cucumber-preprocessor@^1.14.1:
version "1.14.1"
resolved "https://registry.yarnpkg.com/cypress-cucumber-preprocessor/-/cypress-cucumber-preprocessor-1.14.1.tgz#47a6ddd28ca1b0a4ec24707b20ca5c0d7ffc7875"
integrity sha512-72RN3sUeq0r4aNiFfztQD6Uvi58fifkfc2R4pCyX6oTEZLfHfcudkNQLd98ByCyiWXNXPHlGGihE6+EPCDK59A==
dependencies:
"@cypress/browserify-preprocessor" "^1.1.2"
chai "^4.1.2"