From 232882daa2d778b17fc634d4f55961b0e195e4de Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Thu, 25 Aug 2022 14:51:38 +0200 Subject: [PATCH] Mapped '/' attribution url to homepage fixes https://github.com/TryGhost/Team/issues/1846 - Shows homepage instead of / for attribution values --- .../e2e-api/members/__snapshots__/webhooks.test.js.snap | 6 +++--- ghost/core/test/e2e-api/members/webhooks.test.js | 2 +- ghost/member-attribution/lib/attribution.js | 4 ++-- ghost/member-attribution/lib/url-translator.js | 7 +++++++ ghost/member-attribution/test/attribution.test.js | 3 +++ yarn.lock | 7 +------ 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ghost/core/test/e2e-api/members/__snapshots__/webhooks.test.js.snap b/ghost/core/test/e2e-api/members/__snapshots__/webhooks.test.js.snap index 9ec615e833..56d2c7459b 100644 --- a/ghost/core/test/e2e-api/members/__snapshots__/webhooks.test.js.snap +++ b/ghost/core/test/e2e-api/members/__snapshots__/webhooks.test.js.snap @@ -283,7 +283,7 @@ Object { Object { "attribution": Object { "id": null, - "title": "/", + "title": "homepage", "type": "url", "url": "http://127.0.0.1:2369/", }, @@ -316,7 +316,7 @@ exports[`Members API Member attribution Creates a SubscriptionCreatedEvent with Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "2737", + "content-length": "2751", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", @@ -421,7 +421,7 @@ exports[`Members API Member attribution Returns subscription created attribution Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "13523", + "content-length": "13530", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", diff --git a/ghost/core/test/e2e-api/members/webhooks.test.js b/ghost/core/test/e2e-api/members/webhooks.test.js index 66f1980c6f..3d70ff2889 100644 --- a/ghost/core/test/e2e-api/members/webhooks.test.js +++ b/ghost/core/test/e2e-api/members/webhooks.test.js @@ -1822,7 +1822,7 @@ describe('Members API', function () { id: null, url: absoluteUrl, type: 'url', - title: '/' + title: 'homepage' }); }); diff --git a/ghost/member-attribution/lib/attribution.js b/ghost/member-attribution/lib/attribution.js index 623f6fb55e..99876a8d95 100644 --- a/ghost/member-attribution/lib/attribution.js +++ b/ghost/member-attribution/lib/attribution.js @@ -41,7 +41,7 @@ class Attribution { id: null, type: 'url', url: this.#urlTranslator.relativeToAbsolute(this.url), - title: this.url + title: this.#urlTranslator.getUrlTitle(this.url) }; } @@ -51,7 +51,7 @@ class Attribution { id: model.id, type: this.type, url: updatedUrl, - title: model.get('title') ?? model.get('name') ?? this.url + title: model.get('title') ?? model.get('name') ?? this.#urlTranslator.getUrlTitle(this.url) }; } diff --git a/ghost/member-attribution/lib/url-translator.js b/ghost/member-attribution/lib/url-translator.js index f5a021127b..5398956c96 100644 --- a/ghost/member-attribution/lib/url-translator.js +++ b/ghost/member-attribution/lib/url-translator.js @@ -45,6 +45,13 @@ class UrlTranslator { return this.urlUtils.relativeToAbsolute(path); } + /** + * Gives an ordinary URL a name, e.g. / is 'homepage' + */ + getUrlTitle(url) { + return url === '/' ? 'homepage' : url; + } + getTypeAndId(url) { const resource = this.urlService.getResource(url); if (!resource) { diff --git a/ghost/member-attribution/test/attribution.test.js b/ghost/member-attribution/test/attribution.test.js index 26cb282638..ba3970cd3f 100644 --- a/ghost/member-attribution/test/attribution.test.js +++ b/ghost/member-attribution/test/attribution.test.js @@ -36,6 +36,9 @@ describe('AttributionBuilder', function () { } }; }, + getUrlTitle(url) { + return url; + }, getUrlByResourceId() { return 'https://absolute/dir/path'; }, diff --git a/yarn.lock b/yarn.lock index d9da006a1c..5783f08017 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10301,7 +10301,6 @@ ember-power-calendar@^0.16.3: ember-power-datepicker@cibernox/ember-power-datepicker: version "0.8.1" - uid da580474a2c449b715444934ddb626b7c07f46a7 resolved "https://codeload.github.com/cibernox/ember-power-datepicker/tar.gz/da580474a2c449b715444934ddb626b7c07f46a7" dependencies: ember-basic-dropdown "^3.0.11" @@ -12585,7 +12584,6 @@ globrex@^0.1.2: "google-caja-bower@https://github.com/acburdine/google-caja-bower#ghost": version "6011.0.0" - uid "275cb75249f038492094a499756a73719ae071fd" resolved "https://github.com/acburdine/google-caja-bower#275cb75249f038492094a499756a73719ae071fd" got@9.6.0: @@ -12757,7 +12755,7 @@ gscan@4.34.0: uuid "8.3.2" validator "13.0.0" -handlebars@^4.0.13, handlebars@^4.0.4, handlebars@^4.3.1, handlebars@^4.4.2, handlebars@^4.7.3, handlebars@^4.7.6, handlebars@^4.7.7: +handlebars@4.7.7, handlebars@^4.0.13, handlebars@^4.0.4, handlebars@^4.3.1, handlebars@^4.4.2, handlebars@^4.7.3, handlebars@^4.7.6, handlebars@^4.7.7: version "4.7.7" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1" integrity sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA== @@ -14725,7 +14723,6 @@ keygrip@~1.1.0: "keymaster@https://github.com/madrobby/keymaster.git": version "1.6.3" - uid f8f43ddafad663b505dc0908e72853bcf8daea49 resolved "https://github.com/madrobby/keymaster.git#f8f43ddafad663b505dc0908e72853bcf8daea49" keypair@1.0.4: @@ -16478,7 +16475,6 @@ mocha@^2.5.3: mock-knex@TryGhost/mock-knex#8ecb8c227bf463c991c3d820d33f59efc3ab9682: version "0.4.9" - uid "8ecb8c227bf463c991c3d820d33f59efc3ab9682" resolved "https://codeload.github.com/TryGhost/mock-knex/tar.gz/8ecb8c227bf463c991c3d820d33f59efc3ab9682" dependencies: bluebird "^3.4.1" @@ -20376,7 +20372,6 @@ simple-update-notifier@^1.0.7: "simplemde@https://github.com/kevinansfield/simplemde-markdown-editor.git#ghost": version "1.11.2" - uid "4c39702de7d97f9b32d5c101f39237b6dab7c3ee" resolved "https://github.com/kevinansfield/simplemde-markdown-editor.git#4c39702de7d97f9b32d5c101f39237b6dab7c3ee" sinon@14.0.0: