Skip to content

Commit 0b590c6

Browse files
authored
Merge pull request #5844 from AlexVelezLl/robust-solution-for-unpublishable-changes
Robust solution for filtering unpublishable changes on frontend
2 parents f4a95cd + bc02793 commit 0b590c6

6 files changed

Lines changed: 49 additions & 8 deletions

File tree

contentcuration/contentcuration/frontend/shared/data/__tests__/serverSync.spec.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { queueChange, debouncedSyncChanges } from '../serverSync';
22
import { CreatedChange } from '../changes';
33
import db from '../db';
4-
import { Session, Task } from 'shared/data/resources';
4+
import { Channel, Session, Task } from 'shared/data/resources';
55
import client from 'shared/client';
6-
import { CHANGES_TABLE, CURRENT_USER, TABLE_NAMES } from 'shared/data/constants';
6+
import { CHANGE_TYPES, CHANGES_TABLE, CURRENT_USER, TABLE_NAMES } from 'shared/data/constants';
77
import { mockChannelScope, resetMockChannelScope } from 'shared/utils/testing';
88

99
async function makeChange(key, server_rev) {
@@ -225,4 +225,37 @@ describe('ServerSync tests', () => {
225225
expect(dbTask.status).toEqual(task.status);
226226
}
227227
});
228+
229+
it('should not set unpublished_changes when response contains only unpublishable changes', async () => {
230+
const channelId = 'test-channel-unpublishable';
231+
await Channel.table.put({ id: channelId });
232+
233+
client.post.mockResolvedValue({
234+
data: {
235+
disallowed: [],
236+
allowed: [],
237+
returned: [],
238+
errors: [],
239+
successes: [
240+
{
241+
channel_id: channelId,
242+
server_rev: 100,
243+
created_by_id: 'some-user-id',
244+
type: CHANGE_TYPES.UPDATED,
245+
unpublishable: true,
246+
},
247+
],
248+
maxRevs: [],
249+
tasks: [],
250+
},
251+
});
252+
253+
await debouncedSyncChanges();
254+
255+
const channel = await Channel.table.get(channelId);
256+
expect(channel.unpublished_changes).not.toBe(true);
257+
258+
// Manual clean up
259+
await Channel.table.delete(channelId);
260+
});
228261
});

contentcuration/contentcuration/frontend/shared/data/serverSync.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ function handleMaxRevs(response, userId) {
175175
maxRevs[`${MAX_REV_KEY}.${channelId}`] = channelChanges[0].server_rev;
176176
const lastChannelEditIndex = findLastIndex(
177177
channelChanges,
178-
c => !c.errors && !c.user_id && c.created_by_id && c.type !== CHANGE_TYPES.PUBLISHED,
178+
c =>
179+
!c.errors &&
180+
!c.user_id &&
181+
c.created_by_id &&
182+
c.type !== CHANGE_TYPES.PUBLISHED &&
183+
!c.unpublishable,
179184
);
180185
const lastPublishIndex = findLastIndex(
181186
channelChanges,

contentcuration/contentcuration/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,6 +3820,7 @@ def serialize(cls, change):
38203820
"channel_id": get_attribute(change, ["channel_id"]),
38213821
"user_id": get_attribute(change, ["user_id"]),
38223822
"created_by_id": get_attribute(change, ["created_by_id"]),
3823+
"unpublishable": get_attribute(change, ["unpublishable"]),
38233824
}
38243825
)
38253826
return datum

contentcuration/contentcuration/tests/viewsets/test_community_library_submission.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -720,12 +720,12 @@ def test_resolve_submission__accept_correct(self, apply_task_mock):
720720
self.assertEqual(resolved_submission.resolved_by, self.admin_user)
721721
self.assertEqual(resolved_submission.date_updated, self.resolved_time)
722722

723-
self.assertTrue(
724-
Change.objects.filter(
725-
channel=self.submission.channel,
726-
change_type=ADDED_TO_COMMUNITY_LIBRARY,
727-
).exists()
723+
change = Change.objects.get(
724+
channel=self.submission.channel,
725+
change_type=ADDED_TO_COMMUNITY_LIBRARY,
728726
)
727+
self.assertEqual(change.created_by_id, self.admin_user.id)
728+
self.assertTrue(change.unpublishable)
729729
apply_task_mock.fetch_or_enqueue.assert_called_once_with(
730730
self.admin_user,
731731
channel_id=self.submission.channel.id,

contentcuration/contentcuration/viewsets/community_library_submission.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def _add_to_community_library(self, submission):
320320
categories=submission.categories,
321321
country_codes=country_codes,
322322
),
323+
created_by_id=submission.resolved_by_id,
323324
# This change is not publishable and should not trigger publish-related logic
324325
unpublishable=True,
325326
)

contentcuration/contentcuration/viewsets/sync/endpoint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def return_changes(self, request, channel_revs):
155155
"table",
156156
"change_type",
157157
"kwargs",
158+
"unpublishable",
158159
)
159160
.order_by("server_rev")[:CHANGE_RETURN_LIMIT]
160161
)

0 commit comments

Comments
 (0)