Updated feedback button links (#15701)

fixes https://github.com/TryGhost/Team/issues/2174

The feedback links now use a hash instead of a querystring, so it won't pass by the server.

New format: https://site.ghost/post-slug/#/feedback/6359174f2eb251019d14d6fb/0?uuid=13924399-c3ae-413b-a045-0b8294d71f64
This commit is contained in:
Simon Backx 2022-10-26 18:04:11 +02:00 committed by GitHub
parent 57817eefc8
commit c7ef22d4df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 17 deletions

View File

@ -25,11 +25,7 @@ class AudienceFeedbackService {
postUrl = this.#baseURL; postUrl = this.#baseURL;
} }
const url = new URL(postUrl); const url = new URL(postUrl);
url.searchParams.set('action', 'feedback'); url.hash = `#/feedback/${postId}/${score}/?uuid=${encodeURIComponent(uuid)}`;
url.searchParams.set('post', postId);
url.searchParams.set('uuid', uuid);
url.searchParams.set('score', `${score}`);
return url; return url;
} }
} }

View File

@ -24,7 +24,7 @@ describe('audienceFeedbackService', function () {
} }
}); });
const link = instance.buildLink(mockData.uuid, mockData.postId, mockData.score); const link = instance.buildLink(mockData.uuid, mockData.postId, mockData.score);
const expectedLink = `https://localhost:2368/${mockData.postTitle}/?action=feedback&post=${mockData.postId}&uuid=${mockData.uuid}&score=${mockData.score}`; const expectedLink = `https://localhost:2368/${mockData.postTitle}/#/feedback/${mockData.postId}/${mockData.score}/?uuid=${mockData.uuid}`;
assert.equal(link.href, expectedLink); assert.equal(link.href, expectedLink);
}); });
@ -38,7 +38,7 @@ describe('audienceFeedbackService', function () {
} }
}); });
const link = instance.buildLink(mockData.uuid, mockData.postId, mockData.score); const link = instance.buildLink(mockData.uuid, mockData.postId, mockData.score);
const expectedLink = `https://localhost:2368/?action=feedback&post=${mockData.postId}&uuid=${mockData.uuid}&score=${mockData.score}`; const expectedLink = `https://localhost:2368/#/feedback/${mockData.postId}/${mockData.score}/?uuid=${mockData.uuid}`;
assert.equal(link.href, expectedLink); assert.equal(link.href, expectedLink);
}); });
}); });

View File

@ -405,26 +405,29 @@ export default class App extends React.Component {
} }
}; };
} }
const [path, hashQueryString] = window.location.hash.substr(1).split('?');
const hashQuery = new URLSearchParams(hashQueryString ?? '');
const productMonthlyPriceQueryRegex = /^(?:(\w+?))?\/monthly$/;
const productYearlyPriceQueryRegex = /^(?:(\w+?))?\/yearly$/;
const offersRegex = /^offers\/(\w+?)\/?$/;
const linkRegex = /^\/portal\/?(?:\/(\w+(?:\/\w+)*))?\/?$/;
const feedbackRegex = /^\/feedback\/(\w+?)\/(\w+?)\/?$/;
if (qParams.get('uuid') && qParams.get('action') === 'feedback' && qParams.get('score') && qParams.get('post')) { if (path && feedbackRegex.test(path) && hashQuery.get('uuid')) {
const score = parseInt(qParams.get('score')); const [, postId, scoreString] = path.match(feedbackRegex);
const score = parseInt(scoreString);
if (score === 1 || score === 0) { if (score === 1 || score === 0) {
return { return {
showPopup: true, showPopup: true,
page: 'feedback', page: 'feedback',
pageData: { pageData: {
uuid: qParams.get('uuid'), uuid: hashQuery.get('uuid'),
postId: qParams.get('post'), postId,
score score
} }
}; };
} }
} }
const productMonthlyPriceQueryRegex = /^(?:(\w+?))?\/monthly$/;
const productYearlyPriceQueryRegex = /^(?:(\w+?))?\/yearly$/;
const offersRegex = /^offers\/(\w+?)\/?$/;
const [path] = window.location.hash.substr(1).split('?');
const linkRegex = /^\/portal\/?(?:\/(\w+(?:\/\w+)*))?\/?$/;
if (path && linkRegex.test(path)) { if (path && linkRegex.test(path)) {
const [,pagePath] = path.match(linkRegex); const [,pagePath] = path.match(linkRegex);
const {page, pageQuery} = this.getPageFromLinkPath(pagePath) || {}; const {page, pageQuery} = this.getPageFromLinkPath(pagePath) || {};