Skip to content

Commit 0436342

Browse files
authored
fix(rules): preserve collection link and visibility on partial updates (#3046)
When the collection block is omitted from PUT /api/rules, fall back to the saved values for manualCollection, manualCollectionName, visibleOnHome and visibleOnRecommended instead of forwarding undefined. This stops updateCollection from silently unlinking a manual collection (mediaServerId cleared) or switching off Plex Home/Recommended visibility. Follow-up to #3045.
1 parent 3b4cd13 commit 0436342

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

apps/server/src/modules/rules/rules.service.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,21 @@ export class RulesService {
555555
sonarrSettingsId: params.sonarrSettingsId ?? null,
556556
radarrQualityProfileId: params.radarrQualityProfileId ?? null,
557557
sonarrQualityProfileId: params.sonarrQualityProfileId ?? null,
558-
visibleOnRecommended: params.collection?.visibleOnRecommended,
559-
visibleOnHome: params.collection?.visibleOnHome,
558+
// If the collection block is left out of an update, keep the saved
559+
// values instead of sending undefined — otherwise we'd unlink a manual
560+
// collection or switch off Plex visibility.
561+
visibleOnRecommended:
562+
params.collection?.visibleOnRecommended ??
563+
dbCollection?.visibleOnRecommended,
564+
visibleOnHome:
565+
params.collection?.visibleOnHome ?? dbCollection?.visibleOnHome,
560566
deleteAfterDays: params.collection?.deleteAfterDays ?? null,
561-
manualCollection: params.collection?.manualCollection,
562-
manualCollectionName: params.collection?.manualCollectionName,
567+
manualCollection:
568+
params.collection?.manualCollection ??
569+
dbCollection?.manualCollection,
570+
manualCollectionName:
571+
params.collection?.manualCollectionName ??
572+
dbCollection?.manualCollectionName,
563573
keepLogsForMonths: params.collection?.keepLogsForMonths ?? 6,
564574
sortTitle: params.collection?.sortTitle,
565575
mediaServerSort: params.collection?.mediaServerSort ?? null,

apps/server/src/modules/rules/rules.service.updateRules.spec.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,19 @@ describe('RulesService.updateRules', () => {
330330
});
331331
});
332332

333-
// Regression for #3044: an update payload that omits the `collection` block
334-
// used to throw on `params.collection.manualCollection` during the
335-
// "crucial setting changed" check. It must now update without throwing, fall
336-
// back to the default keepLogsForMonths (6), and not trigger a spurious media
337-
// wipe (an absent field means "unchanged", not "changed to undefined").
338-
it('updates without throwing when the collection block is omitted', async () => {
333+
// Leaving the collection block out of an update shouldn't throw, wipe media,
334+
// or quietly drop the saved keepLogsForMonths, manual link, or visibility
335+
// (#3044 + partial-update review).
336+
it('keeps existing collection settings when the collection block is omitted', async () => {
339337
const group = { id: 5, collectionId: 42, dataType: 'movie' };
340338
const dbCollection = {
341339
id: 42,
342340
libraryId: 'lib-1',
343341
mediaServerId: 'col-1',
344-
manualCollection: false,
345-
manualCollectionName: '',
342+
manualCollection: true,
343+
manualCollectionName: 'Shared Collection',
344+
visibleOnHome: true,
345+
visibleOnRecommended: true,
346346
};
347347

348348
const collectionMediaRepository = { delete: jest.fn() };
@@ -388,10 +388,16 @@ describe('RulesService.updateRules', () => {
388388
// collection intentionally omitted
389389
} as any);
390390

391-
// Absent collection settings must not be read as a "crucial" change.
391+
// An absent block means "unchanged", not a crucial change or a reset.
392392
expect(collectionMediaRepository.delete).not.toHaveBeenCalled();
393393
expect(collectionService.updateCollection).toHaveBeenCalledWith(
394-
expect.objectContaining({ keepLogsForMonths: 6 }),
394+
expect.objectContaining({
395+
keepLogsForMonths: 6,
396+
manualCollection: true,
397+
manualCollectionName: 'Shared Collection',
398+
visibleOnHome: true,
399+
visibleOnRecommended: true,
400+
}),
395401
);
396402
expect(result).toEqual({
397403
code: 1,

0 commit comments

Comments
 (0)