mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Changed how we determine if a resource is owned by an url generator
refs #9601 - api v2 returns absolute urls - api v0.1 returns relative urls - it's easier if we compare by id
This commit is contained in:
parent
987e41e8d6
commit
3f9d0f51f5
5 changed files with 14 additions and 12 deletions
|
@ -48,7 +48,7 @@ module.exports = function collectionController(req, res, next) {
|
|||
|
||||
// CASE: does this post belong to this collection?
|
||||
result.posts = _.filter(result.posts, (post) => {
|
||||
if (urlService.owns(res.routerOptions.identifier, post.url)) {
|
||||
if (urlService.owns(res.routerOptions.identifier, post.id)) {
|
||||
return post;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -171,10 +171,10 @@ class UrlGenerator {
|
|||
resource.addListener('removed', onRemoved.bind(this));
|
||||
}
|
||||
|
||||
hasUrl(url) {
|
||||
const existingUrl = this.urls.getByUrl(url);
|
||||
hasId(id) {
|
||||
const existingUrl = this.urls.getByResourceId(id);
|
||||
|
||||
if (existingUrl.length && existingUrl[0].generatorId === this.uid) {
|
||||
if (existingUrl && existingUrl.generatorId === this.uid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -181,8 +181,8 @@ class UrlService {
|
|||
return '/404/';
|
||||
}
|
||||
|
||||
owns(routerId, url) {
|
||||
debug('owns', routerId, url);
|
||||
owns(routerId, id) {
|
||||
debug('owns', routerId, id);
|
||||
|
||||
let urlGenerator;
|
||||
|
||||
|
@ -199,7 +199,7 @@ class UrlService {
|
|||
return false;
|
||||
}
|
||||
|
||||
return urlGenerator.hasUrl(url);
|
||||
return urlGenerator.hasId(id);
|
||||
}
|
||||
|
||||
getPermalinkByUrl(url, options) {
|
||||
|
|
|
@ -56,7 +56,7 @@ describe('Unit - services/routing/controllers/collection', function () {
|
|||
sandbox.stub(filters, 'doFilter');
|
||||
|
||||
sandbox.stub(urlService, 'owns');
|
||||
urlService.owns.withArgs('identifier', posts[0].url).returns(true);
|
||||
urlService.owns.withArgs('identifier', posts[0].id).returns(true);
|
||||
|
||||
req = {
|
||||
path: '/',
|
||||
|
@ -284,10 +284,10 @@ describe('Unit - services/routing/controllers/collection', function () {
|
|||
res.routerOptions.filter = 'featured:true';
|
||||
|
||||
urlService.owns.reset();
|
||||
urlService.owns.withArgs('identifier', posts[0].url).returns(false);
|
||||
urlService.owns.withArgs('identifier', posts[1].url).returns(true);
|
||||
urlService.owns.withArgs('identifier', posts[2].url).returns(false);
|
||||
urlService.owns.withArgs('identifier', posts[3].url).returns(false);
|
||||
urlService.owns.withArgs('identifier', posts[0].id).returns(false);
|
||||
urlService.owns.withArgs('identifier', posts[1].id).returns(true);
|
||||
urlService.owns.withArgs('identifier', posts[2].id).returns(false);
|
||||
urlService.owns.withArgs('identifier', posts[3].id).returns(false);
|
||||
|
||||
fetchDataStub.withArgs({page: 1, slug: undefined, limit: postsPerPage}, res.routerOptions)
|
||||
.resolves({
|
||||
|
|
|
@ -93,6 +93,8 @@ describe('Unit: services/url/Urls', function () {
|
|||
|
||||
it('fn: getByResourceId', function () {
|
||||
urls.getByResourceId('object-id-2').url.should.eql('/something/');
|
||||
should.exist(urls.getByResourceId('object-id-2').generatorId);
|
||||
urls.getByResourceId('object-id-2').generatorId.should.eql(1);
|
||||
});
|
||||
|
||||
it('fn: getByGeneratorId', function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue