mirror of
https://github.com/seerr-team/seerr.git
synced 2026-10-12 02:22:17 +00:00
fix(requests): stop editing a request from stealing another's season (#3376)
This commit is contained in:
@@ -339,6 +339,75 @@ describe('PUT /request/:requestId (movie)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /request/:requestId (tv)', () => {
|
||||
it('does not add a season held by another request', async () => {
|
||||
const userRepo = getRepository(User);
|
||||
const mediaRepo = getRepository(Media);
|
||||
const requestRepo = getRepository(MediaRequest);
|
||||
|
||||
const owner = await userRepo.findOneOrFail({
|
||||
where: { email: '[email protected]' },
|
||||
});
|
||||
const otherUser = await userRepo.findOneOrFail({
|
||||
where: { email: '[email protected]' },
|
||||
});
|
||||
|
||||
const media = await mediaRepo.save(
|
||||
new Media({
|
||||
mediaType: MediaType.TV,
|
||||
tmdbId: 67890,
|
||||
status: MediaStatus.PENDING,
|
||||
status4k: MediaStatus.UNKNOWN,
|
||||
})
|
||||
);
|
||||
|
||||
const seedTvRequest = (requestedBy: User, seasons: number[]) =>
|
||||
requestRepo.save(
|
||||
new MediaRequest({
|
||||
type: MediaType.TV,
|
||||
status: MediaRequestStatus.PENDING,
|
||||
media,
|
||||
requestedBy,
|
||||
is4k: false,
|
||||
seasons: seasons.map(
|
||||
(seasonNumber) =>
|
||||
new SeasonRequest({
|
||||
seasonNumber,
|
||||
status: MediaRequestStatus.PENDING,
|
||||
})
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
const mediaRequest = await seedTvRequest(owner, [1, 2]);
|
||||
const otherRequest = await seedTvRequest(otherUser, [3]);
|
||||
|
||||
const agent = await loginAs('[email protected]', 'test1234');
|
||||
const res = await agent.put(`/request/${mediaRequest.id}`).send({
|
||||
mediaType: MediaType.TV,
|
||||
seasons: [1, 2, 3],
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
|
||||
const saved = await requestRepo.findOneOrFail({
|
||||
where: { id: mediaRequest.id },
|
||||
});
|
||||
assert.deepStrictEqual(
|
||||
saved.seasons.map((s) => s.seasonNumber).sort((a, b) => a - b),
|
||||
[1, 2]
|
||||
);
|
||||
|
||||
const otherSaved = await requestRepo.findOneOrFail({
|
||||
where: { id: otherRequest.id },
|
||||
});
|
||||
assert.deepStrictEqual(
|
||||
otherSaved.seasons.map((s) => s.seasonNumber),
|
||||
[3]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /request/:requestId/:status', () => {
|
||||
const cases = [
|
||||
{ action: 'approve', expected: MediaRequestStatus.APPROVED },
|
||||
|
||||
@@ -571,7 +571,7 @@ requestRoutes.put<{ requestId: string }>(
|
||||
});
|
||||
}
|
||||
|
||||
const newSeasons = requestedSeasons.filter(
|
||||
const newSeasons = filteredSeasons.filter(
|
||||
(sn) => !request.seasons.map((s) => s.seasonNumber).includes(sn)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user