Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 309787d

Browse files
authored
Merge pull request #121 from Human-Connection/105_get_unique_slug_considers_deleted_contributions
[WIP] Fix #105
2 parents b1da765 + f359de6 commit 309787d

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

server/helper/get-unique-slug.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const getUniqueSlug = (service, slug, count, id) => {
1414
}
1515
service.find({
1616
query,
17+
_includeAll: true,
1718
_populate: 'skip'
1819
}).then((result) => {
1920
if (result.data.length > 0) {

server/hooks/include-all.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = () => hook => {
2+
if (!hook.params._includeAll) {
3+
return hook;
4+
}
5+
if (hook.params.query.deleted) {
6+
delete hook.params.query.deleted;
7+
}
8+
if (hook.params.query.isEnabled) {
9+
delete hook.params.query.isEnabled;
10+
}
11+
return hook;
12+
};

server/services/comments/comments.hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
],
4242
find: [
4343
// We want to deleted comments to show up
44-
(hook) => {
44+
hook => {
4545
delete hook.params.query.deleted;
4646
return hook;
4747
}

server/services/contributions/contributions.hooks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const createSlug = require('../../hooks/create-slug');
1010
const saveRemoteImages = require('../../hooks/save-remote-images');
1111
const createExcerpt = require('../../hooks/create-excerpt');
1212
const patchDeletedData = require('../../hooks/patch-deleted-data');
13+
const includeAll = require('../../hooks/include-all');
1314
const cleanupRelatedItems = require('../../hooks/cleanup-related-items');
1415
const keepDeletedDataFields = require('../../hooks/keep-deleted-data-fields');
1516
const search = require('feathers-mongodb-fuzzy-search');
@@ -108,6 +109,9 @@ module.exports = {
108109
unless(isModerator(),
109110
excludeDisabled()
110111
),
112+
when(isProvider('server'),
113+
includeAll()
114+
),
111115
search(),
112116
search({
113117
fields: ['title', 'content']
@@ -163,7 +167,6 @@ module.exports = {
163167
patchDeletedData({
164168
data: {
165169
$set: {
166-
title: 'DELETED',
167170
type: 'DELETED',
168171
content: 'DELETED',
169172
contentExcerpt: 'DELETED',

test/services/contributions.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,52 @@ describe('\'contributions\' service', () => {
8181
assert.ok(notification.relatedContributionId, 'has relatedContributionId');
8282
assert.equal(notification.relatedContributionId, contribution._id, 'has correct relatedContributionId');
8383
});
84+
85+
context('given soft-deleted contribution', () => {
86+
const contributionAttributes = {
87+
title: 'title',
88+
type: 'post',
89+
content: 'blah',
90+
language: 'en',
91+
};
92+
93+
beforeEach(async () => {
94+
const deletedContributionAttributes = Object.assign({}, contributionAttributes, {
95+
deleted: true,
96+
slug: 'title'
97+
});
98+
await service.create(deletedContributionAttributes, params);
99+
});
100+
101+
it('increments title slug', async () => {
102+
let contribution = await service.create(contributionAttributes, params);
103+
assert.ok(contribution, 'created contribution');
104+
assert.equal(contribution.slug, 'title1');
105+
});
106+
});
107+
108+
context('given disabled contribution', () => {
109+
const contributionAttributes = {
110+
title: 'title',
111+
type: 'post',
112+
content: 'blah',
113+
language: 'en',
114+
};
115+
116+
beforeEach(async () => {
117+
const disabledContributionAttributes = Object.assign({}, contributionAttributes, {
118+
isEnabled: false,
119+
slug: 'title'
120+
});
121+
await service.create(disabledContributionAttributes, params);
122+
});
123+
124+
it('increments title slug', async () => {
125+
let contribution = await service.create(contributionAttributes, params);
126+
assert.ok(contribution, 'created contribution');
127+
assert.equal(contribution.slug, 'title1');
128+
});
129+
});
84130
});
85131

86132
describe('contributions patch', () => {

0 commit comments

Comments
 (0)