From c70e6227bae8fecbdbe430b886bd72ae58cf1762 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 10 Apr 2019 13:35:24 +0200 Subject: [PATCH 001/189] first implementation - unclear if specifications are correct --- backend/src/middleware/userMiddleware.js | 3 +- webapp/locales/de.json | 6 +- webapp/locales/en.json | 6 +- webapp/locales/it.json | 4 +- webapp/locales/pl.json | 4 +- webapp/locales/pt.json | 4 +- webapp/pages/profile/_id/_slug.vue | 199 ++++++----------------- webapp/pages/settings/index.vue | 2 +- 8 files changed, 67 insertions(+), 161 deletions(-) diff --git a/backend/src/middleware/userMiddleware.js b/backend/src/middleware/userMiddleware.js index 2979fdadf..b3fc1bf2c 100644 --- a/backend/src/middleware/userMiddleware.js +++ b/backend/src/middleware/userMiddleware.js @@ -1,6 +1,7 @@ -import createOrUpdateLocations from './nodes/locations' import dotenv from 'dotenv' +import createOrUpdateLocations from './nodes/locations' + dotenv.config() export default { diff --git a/webapp/locales/de.json b/webapp/locales/de.json index 6e47d7122..801b01e27 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -15,7 +15,8 @@ "followers": "Folgen", "following": "Folgt", "shouted": "Empfohlen", - "commented": "Kommentiert" + "commented": "Kommentiert", + "userAnonym": "Anonymus" }, "search": { "placeholder": "Suchen", @@ -27,6 +28,7 @@ "data": { "name": "Deine Daten", "labelName": "Dein Name", + "namePlaceholder": "Anonymus", "labelCity": "Deine Stadt oder Region", "labelBio": "Über dich" }, @@ -202,4 +204,4 @@ "shoutButton": { "shouted": "empfohlen" } -} +} \ No newline at end of file diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 62c8f3e19..1e46664f1 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -15,7 +15,8 @@ "followers": "Followers", "following": "Following", "shouted": "Shouted", - "commented": "Commented" + "commented": "Commented", + "userAnonym": "Anonymous" }, "search": { "placeholder": "Search", @@ -27,6 +28,7 @@ "data": { "name": "Your data", "labelName": "Your Name", + "namePlaceholder": "Anonymous", "labelCity": "Your City or Region", "labelBio": "About You" }, @@ -202,4 +204,4 @@ "shoutButton": { "shouted": "shouted" } -} +} \ No newline at end of file diff --git a/webapp/locales/it.json b/webapp/locales/it.json index 0225babad..25005a07a 100644 --- a/webapp/locales/it.json +++ b/webapp/locales/it.json @@ -15,13 +15,15 @@ "followers": "Seguenti", "following": "Seguendo", "shouted": "Gridato", - "commented": "Commentato" + "commented": "Commentato", + "userAnonym": "Anonymous" }, "settings": { "name": "Impostazioni", "data": { "name": "I tuoi dati", "labelName": "Nome", + "namePlaceholder": "Anonymous", "labelCity": "La tua città o regione", "labelBio": "Su di te" }, diff --git a/webapp/locales/pl.json b/webapp/locales/pl.json index 0f2147996..506a04f1b 100644 --- a/webapp/locales/pl.json +++ b/webapp/locales/pl.json @@ -15,13 +15,15 @@ "followers": "Obserwujący", "following": "Obserwowani", "shouted": "Krzyknij", - "commented": "Skomentuj" + "commented": "Skomentuj", + "userAnonym": "Anonymous" }, "settings": { "name": "Ustawienia", "data": { "name": "Twoje dane", "labelName": "Twoje dane", + "namePlaceholder": "Anonymous", "labelCity": "Twoje miasto lub region", "labelBio": "O Tobie" }, diff --git a/webapp/locales/pt.json b/webapp/locales/pt.json index 4151f49c7..0636ba6f9 100644 --- a/webapp/locales/pt.json +++ b/webapp/locales/pt.json @@ -15,13 +15,15 @@ "followers": "Seguidores", "following": "Seguindo", "shouted": "Aclamou", - "commented": "Comentou" + "commented": "Comentou", + "userAnonym": "Anonymous" }, "settings": { "name": "Configurações", "data": { "name": "Seus dados", "labelName": "Seu nome", + "namePlaceholder": "Anonymous", "labelCity": "Sua cidade ou estado", "labelBio": "Sobre você" }, diff --git a/webapp/pages/profile/_id/_slug.vue b/webapp/pages/profile/_id/_slug.vue index a3b10529e..f4367d0be 100644 --- a/webapp/pages/profile/_id/_slug.vue +++ b/webapp/pages/profile/_id/_slug.vue @@ -3,23 +3,14 @@

PROFILE IMAGE

- - + + - + - - {{ user.name }} - - - {{ user.location.name }} + {{ userName() }} + + + {{ user.location.name }} - {{ $t('profile.memberSince') }} {{ user.createdAt | date('MMMM yyyy') }} - + >{{ $t('profile.memberSince') }} {{ user.createdAt | date('MMMM yyyy') }} - - + + - + - + - + - - - Netzwerk - + + Netzwerk - - - Wem folgt {{ user.name | truncate(15) }}? - + + Wem folgt {{ userName(15) }}? - + - - - Wer folgt {{ user.name | truncate(15) }}? - + + Wer folgt {{ userName(15) }}? - + @@ -219,10 +124,7 @@ - + @@ -232,10 +134,7 @@ - + @@ -245,10 +144,7 @@ - + @@ -273,25 +169,16 @@ :key="post.id" :width="{ base: '100%', md: '100%', xl: '50%' }" > - + - + @@ -395,6 +282,14 @@ export default { }, fetchPolicy: 'cache-and-network' }) + }, + userName(maxLength) { + // Return Anonymous if no Username is given + if (!this.user.name) { + return this.$t('profile.userAnonym') + } + // Return full Username or truncated Username + return maxLength ? this.user.name.substring(0, maxLength) : this.user.name } }, apollo: { diff --git a/webapp/pages/settings/index.vue b/webapp/pages/settings/index.vue index 5ff7c171e..3acaf9c4c 100644 --- a/webapp/pages/settings/index.vue +++ b/webapp/pages/settings/index.vue @@ -9,7 +9,7 @@ model="name" icon="user" :label="$t('settings.data.labelName')" - :placeholder="$t('settings.data.labelName')" + :placeholder="$t('settings.data.namePlaceholder')" /> Date: Fri, 12 Apr 2019 16:00:44 +0200 Subject: [PATCH 002/189] Localized HC link on Login page --- webapp/locales/de.json | 1 + webapp/locales/en.json | 1 + webapp/pages/login.vue | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/webapp/locales/de.json b/webapp/locales/de.json index 6e47d7122..ef9600c0e 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -6,6 +6,7 @@ "email": "Deine E-Mail", "password": "Dein Passwort", "moreInfo": "Was ist Human Connection?", + "moreInfoHint": "zur Präsentationsseite", "hello": "Hallo" }, "profile": { diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 62c8f3e19..7c0b747c8 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -6,6 +6,7 @@ "email": "Your Email", "password": "Your Password", "moreInfo": "What is Human Connection?", + "moreInfoHint": "to the presentation page", "hello": "Hello" }, "profile": { diff --git a/webapp/pages/login.vue b/webapp/pages/login.vue index 846191c40..be2215fab 100644 --- a/webapp/pages/login.vue +++ b/webapp/pages/login.vue @@ -80,7 +80,7 @@ {{ $t('login.moreInfo') }} From 26be224464771b835fe062f9e3eddc0119d82f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Fri, 12 Apr 2019 16:08:39 +0200 Subject: [PATCH 003/189] Localised HC URL on Login page --- webapp/locales/de.json | 1 + webapp/locales/en.json | 1 + webapp/pages/login.vue | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/webapp/locales/de.json b/webapp/locales/de.json index ef9600c0e..43885ea17 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -6,6 +6,7 @@ "email": "Deine E-Mail", "password": "Dein Passwort", "moreInfo": "Was ist Human Connection?", + "moreInfoURL": "https://human-connection.org", "moreInfoHint": "zur Präsentationsseite", "hello": "Hallo" }, diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 7c0b747c8..9ea58225f 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -6,6 +6,7 @@ "email": "Your Email", "password": "Your Password", "moreInfo": "What is Human Connection?", + "moreInfoURL": "https://human-connection.org/en/", "moreInfoHint": "to the presentation page", "hello": "Hello" }, diff --git a/webapp/pages/login.vue b/webapp/pages/login.vue index be2215fab..92269143b 100644 --- a/webapp/pages/login.vue +++ b/webapp/pages/login.vue @@ -79,7 +79,7 @@ From 674cdddfc3365fa91a6ced93f030be1840a9b2c8 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Tue, 16 Apr 2019 13:45:07 -0300 Subject: [PATCH 004/189] Add Editor, cancel/submit buttons for comments - to PagesPost_id_slugIndex.vue - handle simple comment creation using auto-generated resolver Co-authored-by: Joseph "Kachulio" Ngugi --- webapp/locales/en.json | 3 +- webapp/pages/post/_id/_slug/index.vue | 105 +++++++++++++++++++------- 2 files changed, 79 insertions(+), 29 deletions(-) diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 40cc766d0..a6ceae9c9 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -106,7 +106,8 @@ }, "takeAction": { "name": "Take action" - } + }, + "submitComment": "Submit Comment" }, "quotes": { "african": { diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index b72faa850..8af07bc26 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -96,34 +96,67 @@ -

- - - {{ post.commentsCount }}  Comments - -

- -
- + +

+ + + {{ post.commentsCount }}  Comments + +

+
+ + + + + + + + {{ $t('actions.cancel') }} + + + + + {{ $t('post.submitComment') }} + + + + + +
+ +
+ -
- +
@@ -139,6 +172,7 @@ import HcUser from '~/components/User' import HcShoutButton from '~/components/ShoutButton.vue' import HcEmpty from '~/components/Empty.vue' import Comment from '~/components/Comment.vue' +import HcEditor from '~/components/Editor/Editor.vue' export default { transition: { @@ -152,7 +186,8 @@ export default { HcShoutButton, HcEmpty, Comment, - ContentMenu + ContentMenu, + HcEditor }, head() { return { @@ -278,6 +313,20 @@ export default { methods: { isAuthor(id) { return this.$store.getters['auth/user'].id === id + }, + handleSubmit() { + this.$apollo.mutate({ + mutation: gql` + mutation($content: String!) { + CreateComment(content: $content) { + content + } + } + `, + variables: { + content: this.value + } + }) } } } From dfef4fe05fa74bad1ea8e2c91ffb1681538c3e42 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Tue, 16 Apr 2019 19:48:59 -0300 Subject: [PATCH 005/189] Add custom resolver, update factories --- backend/src/graphql-schema.js | 4 +++- backend/src/resolvers/comments.js | 28 ++++++++++++++++++++++++++ backend/src/resolvers/socialMedia.js | 2 +- backend/src/schema.graphql | 1 + backend/src/seed/factories/comments.js | 12 +++++------ 5 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 backend/src/resolvers/comments.js diff --git a/backend/src/graphql-schema.js b/backend/src/graphql-schema.js index 1e13c95f4..7befd0507 100644 --- a/backend/src/graphql-schema.js +++ b/backend/src/graphql-schema.js @@ -9,6 +9,7 @@ import moderation from './resolvers/moderation.js' import rewards from './resolvers/rewards.js' import socialMedia from './resolvers/socialMedia.js' import notifications from './resolvers/notifications' +import comments from './resolvers/comments' export const typeDefs = fs .readFileSync( @@ -29,6 +30,7 @@ export const resolvers = { ...moderation.Mutation, ...rewards.Mutation, ...socialMedia.Mutation, - ...notifications.Mutation + ...notifications.Mutation, + ...comments.Mutation } } diff --git a/backend/src/resolvers/comments.js b/backend/src/resolvers/comments.js new file mode 100644 index 000000000..74454322d --- /dev/null +++ b/backend/src/resolvers/comments.js @@ -0,0 +1,28 @@ +import { neo4jgraphql } from 'neo4j-graphql-js' + +export default { + Mutation: { + CreateComment: async (object, params, context, resolveInfo) => { + const { postId } = params + + const result = await neo4jgraphql(object, params, context, resolveInfo, true) + + const session = context.driver.session() + const transactionRes = await session.run(` + MATCH (post:Post {id: $postId}), (comment:Comment {id: $commentId}) + MERGE (post)<-[:COMMENTS]-(comment) + RETURN comment {.id, .content}`, { + postId, + commentId: result.id + } + ) + const [comment] = transactionRes.records.map(record => { + return record.get('comment') + }) + + session.close() + + return comment + } + } +} diff --git a/backend/src/resolvers/socialMedia.js b/backend/src/resolvers/socialMedia.js index 3adf0e2d0..310375820 100644 --- a/backend/src/resolvers/socialMedia.js +++ b/backend/src/resolvers/socialMedia.js @@ -3,7 +3,7 @@ import { neo4jgraphql } from 'neo4j-graphql-js' export default { Mutation: { CreateSocialMedia: async (object, params, context, resolveInfo) => { - const socialMedia = await neo4jgraphql(object, params, context, resolveInfo, true) + const socialMedia = await neo4jgraphql(object, params, context, resolveInfo, false) const session = context.driver.session() await session.run( `MATCH (owner:User {id: $userId}), (socialMedia:SocialMedia {id: $socialMediaId}) diff --git a/backend/src/schema.graphql b/backend/src/schema.graphql index 94e28d0d7..6c35e082d 100644 --- a/backend/src/schema.graphql +++ b/backend/src/schema.graphql @@ -27,6 +27,7 @@ type Mutation { enable(id: ID!): ID reward(fromBadgeId: ID!, toUserId: ID!): ID unreward(fromBadgeId: ID!, toUserId: ID!): ID + CreateComment(id: ID!, postId: ID!, content: String!) : Comment "Shout the given Type and ID" shout(id: ID!, type: ShoutTypeEnum): Boolean! @cypher(statement: """ MATCH (n {id: $id})<-[:WROTE]-(wu:User), (u:User {id: $cypherParams.currentUserId}) diff --git a/backend/src/seed/factories/comments.js b/backend/src/seed/factories/comments.js index 92dca5b14..29d0722b7 100644 --- a/backend/src/seed/factories/comments.js +++ b/backend/src/seed/factories/comments.js @@ -4,22 +4,20 @@ import uuid from 'uuid/v4' export default function (params) { const { id = uuid(), + postId = uuid(), content = [ faker.lorem.sentence(), faker.lorem.sentence() - ].join('. '), - disabled = false, - deleted = false + ].join('. ') } = params return ` mutation { CreateComment( id: "${id}", - content: "${content}", - disabled: ${disabled}, - deleted: ${deleted} - ) { id } + postId: "${postId}", + content: "${content}" + ) { id, content } } ` } From 9bc0c0f92cb95b6b0b7a86eac090ba98d76c1c31 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Tue, 16 Apr 2019 20:31:34 -0300 Subject: [PATCH 006/189] Add tests, create comments only when authenticated --- .../src/middleware/permissionsMiddleware.js | 3 +- backend/src/resolvers/comments.js | 7 +- backend/src/resolvers/comments.spec.js | 64 +++++++++++++++++++ 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 backend/src/resolvers/comments.spec.js diff --git a/backend/src/middleware/permissionsMiddleware.js b/backend/src/middleware/permissionsMiddleware.js index 3ac43a6e2..3688aec16 100644 --- a/backend/src/middleware/permissionsMiddleware.js +++ b/backend/src/middleware/permissionsMiddleware.js @@ -86,7 +86,8 @@ const permissions = shield({ unshout: isAuthenticated, changePassword: isAuthenticated, enable: isModerator, - disable: isModerator + disable: isModerator, + CreateComment: isAuthenticated // CreateUser: allow, }, User: { diff --git a/backend/src/resolvers/comments.js b/backend/src/resolvers/comments.js index 74454322d..5ab20cf46 100644 --- a/backend/src/resolvers/comments.js +++ b/backend/src/resolvers/comments.js @@ -5,7 +5,7 @@ export default { CreateComment: async (object, params, context, resolveInfo) => { const { postId } = params - const result = await neo4jgraphql(object, params, context, resolveInfo, true) + const comment = await neo4jgraphql(object, params, context, resolveInfo, true) const session = context.driver.session() const transactionRes = await session.run(` @@ -13,12 +13,9 @@ export default { MERGE (post)<-[:COMMENTS]-(comment) RETURN comment {.id, .content}`, { postId, - commentId: result.id + commentId: comment.id } ) - const [comment] = transactionRes.records.map(record => { - return record.get('comment') - }) session.close() diff --git a/backend/src/resolvers/comments.spec.js b/backend/src/resolvers/comments.spec.js new file mode 100644 index 000000000..e17f94ec9 --- /dev/null +++ b/backend/src/resolvers/comments.spec.js @@ -0,0 +1,64 @@ +import Factory from '../seed/factories' +import { GraphQLClient } from 'graphql-request' +import { host, login } from '../jest/helpers' + +const factory = Factory() +let client +let variables + +beforeEach(async () => { + await factory.create('User', { + email: 'test@example.org', + password: '1234' + }) +}) + +afterEach(async () => { + await factory.cleanDatabase() +}) + +describe('CreateComment', () => { + const mutation = ` + mutation($id: ID!, $postId: ID!, $content: String!) { + CreateComment(id: $id, postId: $postId, content: $content) { + id + content + } + } + ` + describe('unauthenticated', () => { + it('throws authorization error', async () => { + variables = { + id: 'c1', + postId: 'p1', + content: "I'm not authorised to comment" + } + client = new GraphQLClient(host) + await expect(client.request(mutation, variables)).rejects.toThrow('Not Authorised') + }) + }) + + describe('authenticated', () => { + let headers + beforeEach(async () => { + headers = await login({ email: 'test@example.org', password: '1234' }) + client = new GraphQLClient(host, { headers }) + }) + + it('creates a post', async () => { + variables = { + id: 'c1', + postId: 'p1', + content: "I'm authorised to comment" + } + const expected = { + CreateComment: { + id: 'c1', + content: "I'm authorised to comment" + } + } + + await expect(client.request(mutation, variables)).resolves.toMatchObject(expected) + }) + }) +}) \ No newline at end of file From dd9383ef40fab2b4b616cde39e5e5bca4c1c72d0 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Tue, 16 Apr 2019 23:02:57 -0300 Subject: [PATCH 007/189] Create two custom resolvers, get working with front end - Had difficulty adding a relationship with one custom resolver, if id for comment was not passed in, the comment was not created, hard coding it in also wasn't a good solution --- backend/src/resolvers/comments.js | 23 ++----- backend/src/resolvers/comments.spec.js | 12 ++-- backend/src/schema.graphql | 1 - backend/src/seed/factories/comments.js | 2 - webapp/graphql/AddPostComments.js | 18 ++++++ webapp/pages/post/_id/_slug/index.vue | 90 +++++++++++++++++--------- 6 files changed, 89 insertions(+), 57 deletions(-) create mode 100644 webapp/graphql/AddPostComments.js diff --git a/backend/src/resolvers/comments.js b/backend/src/resolvers/comments.js index 5ab20cf46..4542c075a 100644 --- a/backend/src/resolvers/comments.js +++ b/backend/src/resolvers/comments.js @@ -2,24 +2,11 @@ import { neo4jgraphql } from 'neo4j-graphql-js' export default { Mutation: { - CreateComment: async (object, params, context, resolveInfo) => { - const { postId } = params - - const comment = await neo4jgraphql(object, params, context, resolveInfo, true) - - const session = context.driver.session() - const transactionRes = await session.run(` - MATCH (post:Post {id: $postId}), (comment:Comment {id: $commentId}) - MERGE (post)<-[:COMMENTS]-(comment) - RETURN comment {.id, .content}`, { - postId, - commentId: comment.id - } - ) - - session.close() - - return comment + CreateComment: (object, params, context, resolveInfo) => { + return neo4jgraphql(object, params, context, resolveInfo, false) + }, + AddPostComments: (object, params, context, resolveInfo) => { + return neo4jgraphql(object, params, context, resolveInfo, false) } } } diff --git a/backend/src/resolvers/comments.spec.js b/backend/src/resolvers/comments.spec.js index e17f94ec9..2fcd7245f 100644 --- a/backend/src/resolvers/comments.spec.js +++ b/backend/src/resolvers/comments.spec.js @@ -19,8 +19,8 @@ afterEach(async () => { describe('CreateComment', () => { const mutation = ` - mutation($id: ID!, $postId: ID!, $content: String!) { - CreateComment(id: $id, postId: $postId, content: $content) { + mutation($id: ID!, $content: String!) { + CreateComment(id: $id, content: $content) { id content } @@ -29,8 +29,7 @@ describe('CreateComment', () => { describe('unauthenticated', () => { it('throws authorization error', async () => { variables = { - id: 'c1', - postId: 'p1', + id: 'c1', content: "I'm not authorised to comment" } client = new GraphQLClient(host) @@ -46,9 +45,8 @@ describe('CreateComment', () => { }) it('creates a post', async () => { - variables = { - id: 'c1', - postId: 'p1', + variables = { + id: 'c1', content: "I'm authorised to comment" } const expected = { diff --git a/backend/src/schema.graphql b/backend/src/schema.graphql index 6c35e082d..94e28d0d7 100644 --- a/backend/src/schema.graphql +++ b/backend/src/schema.graphql @@ -27,7 +27,6 @@ type Mutation { enable(id: ID!): ID reward(fromBadgeId: ID!, toUserId: ID!): ID unreward(fromBadgeId: ID!, toUserId: ID!): ID - CreateComment(id: ID!, postId: ID!, content: String!) : Comment "Shout the given Type and ID" shout(id: ID!, type: ShoutTypeEnum): Boolean! @cypher(statement: """ MATCH (n {id: $id})<-[:WROTE]-(wu:User), (u:User {id: $cypherParams.currentUserId}) diff --git a/backend/src/seed/factories/comments.js b/backend/src/seed/factories/comments.js index 29d0722b7..b6ada7ac9 100644 --- a/backend/src/seed/factories/comments.js +++ b/backend/src/seed/factories/comments.js @@ -4,7 +4,6 @@ import uuid from 'uuid/v4' export default function (params) { const { id = uuid(), - postId = uuid(), content = [ faker.lorem.sentence(), faker.lorem.sentence() @@ -15,7 +14,6 @@ export default function (params) { mutation { CreateComment( id: "${id}", - postId: "${postId}", content: "${content}" ) { id, content } } diff --git a/webapp/graphql/AddPostComments.js b/webapp/graphql/AddPostComments.js new file mode 100644 index 000000000..ab9ef8ca5 --- /dev/null +++ b/webapp/graphql/AddPostComments.js @@ -0,0 +1,18 @@ +import gql from 'graphql-tag' + +export default app => { + return { + AddPostComments: gql(` + mutation($from: _CommentInput!, $to: _PostInput!) { + AddPostComments(from: $from, to: $to) { + from { + id + } + to { + id + } + } + } + `) + } +} diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index 8af07bc26..ef1121031 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -117,11 +117,11 @@ v-model="value" /> + - + {{ $t('actions.cancel') }} @@ -140,23 +140,23 @@ - -
- -
- + +
+ +
+ @@ -198,7 +198,9 @@ export default { return { post: null, ready: false, - title: 'loading' + title: 'loading', + loading: false, + disabled: false } }, watch: { @@ -315,18 +317,48 @@ export default { return this.$store.getters['auth/user'].id === id }, handleSubmit() { - this.$apollo.mutate({ - mutation: gql` - mutation($content: String!) { - CreateComment(content: $content) { - content + this.loading = true + this.$apollo + .mutate({ + mutation: gql` + mutation($content: String!) { + CreateComment(content: $content) { + id + content + } } + `, + variables: { + content: this.value } - `, - variables: { - content: this.value - } - }) + }) + .then(res => { + this.disabled = true + this.loading = false + const { id } = res.data.CreateComment + const commentId = { id: id } + const postId = { id: this.post.id } + const AddPostComments = require('~/graphql/AddPostComments.js').default( + this + ) + + this.$apollo + .mutate({ + mutation: AddPostComments.AddPostComments, + variables: { + from: commentId, + to: postId + } + }) + .then(res => { + this.$toast.success('Saved!') + }) + }) + .catch(err => { + this.$toast.error(err.message) + this.loading = false + this.disabled = false + }) } } } From c519bff74340e3381f017dfc20ff638e5e3aabe5 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Tue, 16 Apr 2019 23:37:11 -0300 Subject: [PATCH 008/189] Fix lint --- backend/src/resolvers/comments.spec.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/resolvers/comments.spec.js b/backend/src/resolvers/comments.spec.js index 2fcd7245f..a70dfd974 100644 --- a/backend/src/resolvers/comments.spec.js +++ b/backend/src/resolvers/comments.spec.js @@ -28,9 +28,9 @@ describe('CreateComment', () => { ` describe('unauthenticated', () => { it('throws authorization error', async () => { - variables = { + variables = { id: 'c1', - content: "I'm not authorised to comment" + content: 'I\'m not authorised to comment' } client = new GraphQLClient(host) await expect(client.request(mutation, variables)).rejects.toThrow('Not Authorised') @@ -47,16 +47,16 @@ describe('CreateComment', () => { it('creates a post', async () => { variables = { id: 'c1', - content: "I'm authorised to comment" + content: 'I\'m authorised to comment' } const expected = { CreateComment: { id: 'c1', - content: "I'm authorised to comment" + content: 'I\'m authorised to comment' } } - + await expect(client.request(mutation, variables)).resolves.toMatchObject(expected) }) }) -}) \ No newline at end of file +}) From 2efc77097fcf44f034ccec99545634b3fd6ad2fb Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 17 Apr 2019 14:49:03 +0200 Subject: [PATCH 009/189] match specification of Dennis - minimum 3 characters for username, no hint for user to change the username to "Anonymous", Toast error if userdata cannot be changed due to username restrictions, display "Anonymous" if no username is found in database (even tho this is against implemented rules) --- backend/src/middleware/userMiddleware.js | 5 ++ webapp/components/User/index.vue | 87 ++++++++---------------- webapp/locales/de.json | 5 +- webapp/locales/en.json | 5 +- webapp/pages/settings/index.vue | 44 +++++------- 5 files changed, 58 insertions(+), 88 deletions(-) diff --git a/backend/src/middleware/userMiddleware.js b/backend/src/middleware/userMiddleware.js index b3fc1bf2c..4789b4cbd 100644 --- a/backend/src/middleware/userMiddleware.js +++ b/backend/src/middleware/userMiddleware.js @@ -1,4 +1,5 @@ import dotenv from 'dotenv' +import { UserInputError } from 'apollo-server' import createOrUpdateLocations from './nodes/locations' @@ -12,6 +13,10 @@ export default { return result }, UpdateUser: async (resolve, root, args, context, info) => { + const USERNAME_MIN_LENGTH = 3 // TODO move to the correct place + if (!args.name || args.name.length < USERNAME_MIN_LENGTH) { + throw new UserInputError(`Username must be at least ${USERNAME_MIN_LENGTH} characters long!`) + } const result = await resolve(root, args, context, info) await createOrUpdateLocations(args.id, args.locationName, context.driver) return result diff --git a/webapp/components/User/index.vue b/webapp/components/User/index.vue index 6b0731981..2a3904763 100644 --- a/webapp/components/User/index.vue +++ b/webapp/components/User/index.vue @@ -3,65 +3,35 @@
- +
- Anonymus + {{ $t('profile.userAnonym') }}
- -