From d024d7df91dbac80237fa74e62bba1a8469ed463 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 14 Jun 2019 14:03:21 +0200 Subject: [PATCH 1/8] fixed importing of urls - remove url prefix --- .../maintenance-worker/migration/neo4j/badges.cql | 2 +- .../maintenance-worker/migration/neo4j/contributions.cql | 6 +++--- .../maintenance-worker/migration/neo4j/users.cql | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/deployment/legacy-migration/maintenance-worker/migration/neo4j/badges.cql b/deployment/legacy-migration/maintenance-worker/migration/neo4j/badges.cql index 62cd4a2cc..2d1548d4f 100644 --- a/deployment/legacy-migration/maintenance-worker/migration/neo4j/badges.cql +++ b/deployment/legacy-migration/maintenance-worker/migration/neo4j/badges.cql @@ -45,7 +45,7 @@ MERGE(b:Badge {id: badge._id["$oid"]}) ON CREATE SET b.key = badge.key, b.type = badge.type, -b.icon = badge.image.path, +b.icon = substring(badge.image.path, 38), b.status = badge.status, b.createdAt = badge.createdAt.`$date`, b.updatedAt = badge.updatedAt.`$date` diff --git a/deployment/legacy-migration/maintenance-worker/migration/neo4j/contributions.cql b/deployment/legacy-migration/maintenance-worker/migration/neo4j/contributions.cql index 98d8f24e9..70f09e035 100644 --- a/deployment/legacy-migration/maintenance-worker/migration/neo4j/contributions.cql +++ b/deployment/legacy-migration/maintenance-worker/migration/neo4j/contributions.cql @@ -28,7 +28,7 @@ [?] unique: true, // Unique value is not enforced in Nitro? [-] index: true }, -[ ] type: { +[ ] type: { // db.getCollection('contributions').distinct('type') -> 'DELETED', 'cando', 'post' [ ] type: String, [ ] required: true, [-] index: true @@ -50,7 +50,7 @@ [?] required: true // Not required in Nitro }, [ ] hasMore: { type: Boolean }, -[?] teaserImg: { type: String }, // Path is incorrect in Nitro +[X] teaserImg: { type: String }, [ ] language: { [ ] type: String, [ ] required: true, @@ -131,7 +131,7 @@ MERGE (p:Post {id: post._id["$oid"]}) ON CREATE SET p.title = post.title, p.slug = post.slug, -p.image = post.teaserImg, +p.image = substring(post.teaserImg, 38), p.content = post.content, p.contentExcerpt = post.contentExcerpt, p.visibility = toLower(post.visibility), diff --git a/deployment/legacy-migration/maintenance-worker/migration/neo4j/users.cql b/deployment/legacy-migration/maintenance-worker/migration/neo4j/users.cql index aec5499fc..96251a9ce 100644 --- a/deployment/legacy-migration/maintenance-worker/migration/neo4j/users.cql +++ b/deployment/legacy-migration/maintenance-worker/migration/neo4j/users.cql @@ -49,8 +49,8 @@ } }, [ ] timezone: { type: String }, -[?] avatar: { type: String }, // Path is incorrect in Nitro -[?] coverImg: { type: String }, // Path is incorrect in Nitro, was not modeled in latest Nitro - do we want this? +[X] avatar: { type: String }, +[X] coverImg: { type: String }, [ ] doiToken: { type: String }, [ ] confirmedAt: { type: Date }, [?] badgeIds: [], // Verify this is working properly @@ -102,8 +102,8 @@ u.name = user.name, u.slug = user.slug, u.email = user.email, u.password = user.password, -u.avatar = user.avatar, -u.coverImg = user.coverImg, +u.avatar = substring(user.avatar, 38), +u.coverImg = substring(user.coverImg, 38), u.wasInvited = user.wasInvited, u.wasSeeded = user.wasSeeded, u.role = toLower(user.role), From 89d630b1eb82914996e140e6c481b292611f800a Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 14 Jun 2019 14:03:37 +0200 Subject: [PATCH 2/8] removed fixImageUrlsMiddleware --- .../src/middleware/fixImageUrlsMiddleware.js | 48 ------------------- .../middleware/fixImageUrlsMiddleware.spec.js | 36 -------------- 2 files changed, 84 deletions(-) delete mode 100644 backend/src/middleware/fixImageUrlsMiddleware.js delete mode 100644 backend/src/middleware/fixImageUrlsMiddleware.spec.js diff --git a/backend/src/middleware/fixImageUrlsMiddleware.js b/backend/src/middleware/fixImageUrlsMiddleware.js deleted file mode 100644 index c930915bf..000000000 --- a/backend/src/middleware/fixImageUrlsMiddleware.js +++ /dev/null @@ -1,48 +0,0 @@ -const legacyUrls = [ - 'https://api-alpha.human-connection.org', - 'https://staging-api.human-connection.org', - 'http://localhost:3000', -] - -export const fixUrl = url => { - legacyUrls.forEach(legacyUrl => { - url = url.replace(legacyUrl, '/api') - }) - return url -} - -const checkUrl = thing => { - return ( - thing && - typeof thing === 'string' && - legacyUrls.find(legacyUrl => { - return thing.indexOf(legacyUrl) === 0 - }) - ) -} - -export const fixImageURLs = (result, recursive) => { - if (checkUrl(result)) { - result = fixUrl(result) - } else if (result && Array.isArray(result)) { - result.forEach((res, index) => { - result[index] = fixImageURLs(result[index], true) - }) - } else if (result && typeof result === 'object') { - Object.keys(result).forEach(key => { - result[key] = fixImageURLs(result[key], true) - }) - } - return result -} - -export default { - Mutation: async (resolve, root, args, context, info) => { - const result = await resolve(root, args, context, info) - return fixImageURLs(result) - }, - Query: async (resolve, root, args, context, info) => { - let result = await resolve(root, args, context, info) - return fixImageURLs(result) - }, -} diff --git a/backend/src/middleware/fixImageUrlsMiddleware.spec.js b/backend/src/middleware/fixImageUrlsMiddleware.spec.js deleted file mode 100644 index b2d808dd9..000000000 --- a/backend/src/middleware/fixImageUrlsMiddleware.spec.js +++ /dev/null @@ -1,36 +0,0 @@ -import { fixImageURLs } from './fixImageUrlsMiddleware' - -describe('fixImageURLs', () => { - describe('image url of legacy alpha', () => { - it('removes domain', () => { - const url = - 'https://api-alpha.human-connection.org/uploads/4bfaf9172c4ba03d7645108bbbd16f0a696a37d01eacd025fb131e5da61b15d9.png' - expect(fixImageURLs(url)).toEqual( - '/api/uploads/4bfaf9172c4ba03d7645108bbbd16f0a696a37d01eacd025fb131e5da61b15d9.png', - ) - }) - }) - - describe('image url of legacy staging', () => { - it('removes domain', () => { - const url = - 'https://staging-api.human-connection.org/uploads/1b3c39a24f27e2fb62b69074b2f71363b63b263f0c4574047d279967124c026e.jpeg' - expect(fixImageURLs(url)).toEqual( - '/api/uploads/1b3c39a24f27e2fb62b69074b2f71363b63b263f0c4574047d279967124c026e.jpeg', - ) - }) - }) - - describe('object', () => { - it('returns untouched', () => { - const object = { some: 'thing' } - expect(fixImageURLs(object)).toEqual(object) - }) - }) - - describe('some string', () => { - it('returns untouched', () => {}) - const string = "Yeah I'm a String" - expect(fixImageURLs(string)).toEqual(string) - }) -}) From 794bb08f141eeed293c9a59821dc506d87eba841 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 14 Jun 2019 14:04:15 +0200 Subject: [PATCH 3/8] removed reference for fixImageUrls middleware --- backend/src/middleware/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/middleware/index.js b/backend/src/middleware/index.js index 75314abc0..aae2dcef3 100644 --- a/backend/src/middleware/index.js +++ b/backend/src/middleware/index.js @@ -3,7 +3,6 @@ import activityPub from './activityPubMiddleware' import password from './passwordMiddleware' import softDelete from './softDeleteMiddleware' import sluggify from './sluggifyMiddleware' -import fixImageUrls from './fixImageUrlsMiddleware' import excerpt from './excerptMiddleware' import dateTime from './dateTimeMiddleware' import xss from './xssMiddleware' @@ -25,7 +24,6 @@ export default schema => { excerpt: excerpt, notifications: notifications, xss: xss, - fixImageUrls: fixImageUrls, softDelete: softDelete, user: user, includedFields: includedFields, From 65df4c5a20b9d05cd08cfd4a33cebab1ccc29461 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 17 Jun 2019 12:16:15 +0200 Subject: [PATCH 4/8] use replace instead of substring --- .../maintenance-worker/migration/neo4j/badges.cql | 2 +- .../maintenance-worker/migration/neo4j/contributions.cql | 2 +- .../maintenance-worker/migration/neo4j/users.cql | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deployment/legacy-migration/maintenance-worker/migration/neo4j/badges.cql b/deployment/legacy-migration/maintenance-worker/migration/neo4j/badges.cql index 2d1548d4f..027cea019 100644 --- a/deployment/legacy-migration/maintenance-worker/migration/neo4j/badges.cql +++ b/deployment/legacy-migration/maintenance-worker/migration/neo4j/badges.cql @@ -45,7 +45,7 @@ MERGE(b:Badge {id: badge._id["$oid"]}) ON CREATE SET b.key = badge.key, b.type = badge.type, -b.icon = substring(badge.image.path, 38), +b.icon = replace(badge.image.path, 'https://api-alpha.human-connection.org', ''), b.status = badge.status, b.createdAt = badge.createdAt.`$date`, b.updatedAt = badge.updatedAt.`$date` diff --git a/deployment/legacy-migration/maintenance-worker/migration/neo4j/contributions.cql b/deployment/legacy-migration/maintenance-worker/migration/neo4j/contributions.cql index 70f09e035..472354763 100644 --- a/deployment/legacy-migration/maintenance-worker/migration/neo4j/contributions.cql +++ b/deployment/legacy-migration/maintenance-worker/migration/neo4j/contributions.cql @@ -131,7 +131,7 @@ MERGE (p:Post {id: post._id["$oid"]}) ON CREATE SET p.title = post.title, p.slug = post.slug, -p.image = substring(post.teaserImg, 38), +p.image = replace(post.teaserImg, 'https://api-alpha.human-connection.org', ''), p.content = post.content, p.contentExcerpt = post.contentExcerpt, p.visibility = toLower(post.visibility), diff --git a/deployment/legacy-migration/maintenance-worker/migration/neo4j/users.cql b/deployment/legacy-migration/maintenance-worker/migration/neo4j/users.cql index 96251a9ce..4d7c9aa9f 100644 --- a/deployment/legacy-migration/maintenance-worker/migration/neo4j/users.cql +++ b/deployment/legacy-migration/maintenance-worker/migration/neo4j/users.cql @@ -102,8 +102,8 @@ u.name = user.name, u.slug = user.slug, u.email = user.email, u.password = user.password, -u.avatar = substring(user.avatar, 38), -u.coverImg = substring(user.coverImg, 38), +u.avatar = replace(user.avatar, 'https://api-alpha.human-connection.org', ''), +u.coverImg = replace(user.coverImg, 'https://api-alpha.human-connection.org', ''), u.wasInvited = user.wasInvited, u.wasSeeded = user.wasSeeded, u.role = toLower(user.role), From 4dde53f67d4dca075240c90466fd765c67e24d19 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 17 Jun 2019 13:30:18 +0200 Subject: [PATCH 5/8] added coverage report text in oder to fix coverage --- webapp/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webapp/package.json b/webapp/package.json index 1abaf479b..4f203ef5c 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -29,6 +29,7 @@ "!**/?(*.)+(spec|test).js?(x)" ], "coverageReporters": [ + "text", "lcov" ], "transform": { @@ -110,4 +111,4 @@ "vue-jest": "~3.0.4", "vue-svg-loader": "~0.12.0" } -} +} \ No newline at end of file From 8984df937120c91bdcdb0892671066ccfe097b6a Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 18 Jun 2019 17:43:00 +0200 Subject: [PATCH 6/8] lint fixes --- backend/src/activitypub/NitroDataSource.js | 8 ++++++-- backend/src/middleware/notifications/spec.js | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/src/activitypub/NitroDataSource.js b/backend/src/activitypub/NitroDataSource.js index 0900bed6c..eea37337a 100644 --- a/backend/src/activitypub/NitroDataSource.js +++ b/backend/src/activitypub/NitroDataSource.js @@ -505,7 +505,9 @@ export default class NitroDataSource { const result2 = await this.client.mutate({ mutation: gql` mutation { - AddCommentAuthor(from: {id: "${result.data.CreateComment.id}"}, to: {id: "${toUserId}"}) { + AddCommentAuthor(from: {id: "${ + result.data.CreateComment.id + }"}, to: {id: "${toUserId}"}) { id } } @@ -517,7 +519,9 @@ export default class NitroDataSource { result = await this.client.mutate({ mutation: gql` mutation { - AddCommentPost(from: { id: "${result.data.CreateComment.id}", to: { id: "${postId}" }}) { + AddCommentPost(from: { id: "${ + result.data.CreateComment.id + }", to: { id: "${postId}" }}) { id } } diff --git a/backend/src/middleware/notifications/spec.js b/backend/src/middleware/notifications/spec.js index 985654b0f..65212e544 100644 --- a/backend/src/middleware/notifications/spec.js +++ b/backend/src/middleware/notifications/spec.js @@ -87,7 +87,9 @@ describe('currentUser { notifications }', () => { describe('who mentions me again', () => { beforeEach(async () => { - const updatedContent = `${post.content} One more mention to @al-capone` + const updatedContent = `${ + post.content + } One more mention to @al-capone` // The response `post.content` contains a link but the XSSmiddleware // should have the `mention` CSS class removed. I discovered this // during development and thought: A feature not a bug! This way we From 65471efb0d19a4f9130ef6e4aa2ac168758db2bc Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 19 Jun 2019 13:08:51 +0200 Subject: [PATCH 7/8] removed fixImageUrls reference --- backend/src/middleware/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/middleware/index.js b/backend/src/middleware/index.js index aae2dcef3..9b85bd340 100644 --- a/backend/src/middleware/index.js +++ b/backend/src/middleware/index.js @@ -40,7 +40,6 @@ export default schema => { 'excerpt', 'notifications', 'xss', - 'fixImageUrls', 'softDelete', 'user', 'includedFields', From 7613ddfc04c2e3f8fd62fc954f1c6486e5fdaeff Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 19 Jun 2019 13:36:14 +0200 Subject: [PATCH 8/8] lint fixes --- backend/src/activitypub/NitroDataSource.js | 8 ++------ backend/src/middleware/notifications/spec.js | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/backend/src/activitypub/NitroDataSource.js b/backend/src/activitypub/NitroDataSource.js index eea37337a..0900bed6c 100644 --- a/backend/src/activitypub/NitroDataSource.js +++ b/backend/src/activitypub/NitroDataSource.js @@ -505,9 +505,7 @@ export default class NitroDataSource { const result2 = await this.client.mutate({ mutation: gql` mutation { - AddCommentAuthor(from: {id: "${ - result.data.CreateComment.id - }"}, to: {id: "${toUserId}"}) { + AddCommentAuthor(from: {id: "${result.data.CreateComment.id}"}, to: {id: "${toUserId}"}) { id } } @@ -519,9 +517,7 @@ export default class NitroDataSource { result = await this.client.mutate({ mutation: gql` mutation { - AddCommentPost(from: { id: "${ - result.data.CreateComment.id - }", to: { id: "${postId}" }}) { + AddCommentPost(from: { id: "${result.data.CreateComment.id}", to: { id: "${postId}" }}) { id } } diff --git a/backend/src/middleware/notifications/spec.js b/backend/src/middleware/notifications/spec.js index 65212e544..985654b0f 100644 --- a/backend/src/middleware/notifications/spec.js +++ b/backend/src/middleware/notifications/spec.js @@ -87,9 +87,7 @@ describe('currentUser { notifications }', () => { describe('who mentions me again', () => { beforeEach(async () => { - const updatedContent = `${ - post.content - } One more mention to @al-capone` + const updatedContent = `${post.content} One more mention to @al-capone` // The response `post.content` contains a link but the XSSmiddleware // should have the `mention` CSS class removed. I discovered this // during development and thought: A feature not a bug! This way we