diff --git a/backend/.env.template b/backend/.env.template
index 5858a5d1e..239046dd3 100644
--- a/backend/.env.template
+++ b/backend/.env.template
@@ -28,3 +28,5 @@ AWS_BUCKET=
EMAIL_DEFAULT_SENDER="devops@ocelot.social"
EMAIL_SUPPORT="devops@ocelot.social"
+
+CATEGORIES_ACTIVE=false
\ No newline at end of file
diff --git a/backend/src/config/index.js b/backend/src/config/index.js
index 6ad8c578b..7df780cfc 100644
--- a/backend/src/config/index.js
+++ b/backend/src/config/index.js
@@ -86,6 +86,7 @@ const options = {
ORGANIZATION_URL: emails.ORGANIZATION_LINK,
PUBLIC_REGISTRATION: env.PUBLIC_REGISTRATION === 'true' || false,
INVITE_REGISTRATION: env.INVITE_REGISTRATION !== 'false', // default = true
+ CATEGORIES_ACTIVE: process.env.CATEGORIES_ACTIVE === 'true' || false,
}
// Check if all required configs are present
diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js
index d199b6f09..b09bb3edd 100644
--- a/backend/src/schema/resolvers/posts.js
+++ b/backend/src/schema/resolvers/posts.js
@@ -5,6 +5,7 @@ import { UserInputError } from 'apollo-server'
import { mergeImage, deleteImage } from './images/images'
import Resolver from './helpers/Resolver'
import { filterForMutedUsers } from './helpers/filterForMutedUsers'
+import CONFIG from '../../config'
const maintainPinnedPosts = (params) => {
const pinnedPostFilter = { pinned: true }
@@ -76,12 +77,20 @@ export default {
},
Mutation: {
CreatePost: async (_parent, params, context, _resolveInfo) => {
+ const { categoryIds } = params
const { image: imageInput } = params
delete params.categoryIds
delete params.image
params.id = params.id || uuid()
const session = context.driver.session()
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
+ const categoriesCypher =
+ CONFIG.CATEGORIES_ACTIVE && categoryIds
+ ? `WITH post
+ UNWIND $categoryIds AS categoryId
+ MATCH (category:Category {id: categoryId})
+ MERGE (post)-[:CATEGORIZED]->(category)`
+ : ''
const createPostTransactionResponse = await transaction.run(
`
CREATE (post:Post)
@@ -93,9 +102,10 @@ export default {
WITH post
MATCH (author:User {id: $userId})
MERGE (post)<-[:WROTE]-(author)
+ ${categoriesCypher}
RETURN post {.*}
`,
- { userId: context.user.id, params },
+ { userId: context.user.id, params, categoryIds },
)
const [post] = createPostTransactionResponse.records.map((record) => record.get('post'))
if (imageInput) {
@@ -127,7 +137,7 @@ export default {
WITH post
`
- if (categoryIds && categoryIds.length) {
+ if (CONFIG.CATEGORIES_ACTIVE && categoryIds && categoryIds.length) {
const cypherDeletePreviousRelations = `
MATCH (post:Post { id: $params.id })-[previousRelations:CATEGORIZED]->(category:Category)
DELETE previousRelations
diff --git a/webapp/.env.template b/webapp/.env.template
index 7373255a9..0a4c3405f 100644
--- a/webapp/.env.template
+++ b/webapp/.env.template
@@ -4,3 +4,4 @@ PUBLIC_REGISTRATION=false
INVITE_REGISTRATION=true
WEBSOCKETS_URI=ws://localhost:3000/api/graphql
GRAPHQL_URI=http://localhost:4000/
+CATEGORIES_ACTIVE=false
\ No newline at end of file
diff --git a/webapp/components/ContributionForm/ContributionForm.spec.js b/webapp/components/ContributionForm/ContributionForm.spec.js
index cce187a63..ce432fc42 100644
--- a/webapp/components/ContributionForm/ContributionForm.spec.js
+++ b/webapp/components/ContributionForm/ContributionForm.spec.js
@@ -58,6 +58,9 @@ describe('ContributionForm.vue', () => {
back: jest.fn(),
push: jest.fn(),
},
+ $env: {
+ CATEGORIES_ACTIVE: false,
+ },
}
propsData = {}
})
@@ -132,6 +135,7 @@ describe('ContributionForm.vue', () => {
variables: {
title: postTitle,
content: postContent,
+ categoryIds: [],
id: null,
image: null,
},
@@ -254,6 +258,7 @@ describe('ContributionForm.vue', () => {
variables: {
title: propsData.contribution.title,
content: propsData.contribution.content,
+ categoryIds: [],
id: propsData.contribution.id,
image: {
sensitive: false,
diff --git a/webapp/components/ContributionForm/ContributionForm.vue b/webapp/components/ContributionForm/ContributionForm.vue
index a06679149..3d4bb8e7c 100644
--- a/webapp/components/ContributionForm/ContributionForm.vue
+++ b/webapp/components/ContributionForm/ContributionForm.vue
@@ -51,6 +51,19 @@
{{ contentLength }}