Skip to content

Commit

Permalink
Make expiration check on update optional
Browse files Browse the repository at this point in the history
Disable for tasks
  • Loading branch information
minottic committed Mar 25, 2024
1 parent 89957ba commit 34b91c0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -823,4 +823,24 @@ describe('Basesnippet', function (this: Suite) {
.expect(t);
});
});

it(`patch expired snippet by id should return 403`, async () => {
const bs = await client
.post('/basesnippets')
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.send({
...baseSnippet,
expiresAt: '1990-10-10T14:04:19.522Z',
});
await client
.patch(`/basesnippets/${bs.body.id}`)
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.send({name: 'something'})
.expect(403)
.catch(err => {
throw err;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('TaskRepositorySnippet', function (this: Suite) {
shareACL: ['taskAcceptance'],
isPrivate: true,
defaultOrder: 0,
expiresAt: '2055-10-10T14:04:19.522Z',
expiresAt: '1991-10-10T14:04:19.522Z',
tags: ['aSearchableTag'],
dashboardName: 'string',
versionable: true,
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('TaskRepositorySnippet', function (this: Suite) {
// when patching by id, to preserve the history, the original snippet is duplicated, then a history snippet is created and then the original one is updated
// to keep the linking between the three, the parentId of the duplicated one = id of the history snippet and the parentId of the history snippet = id of the original one
// to prevent the search to return too many snippets, the fields used in the subsequent search are updated
it('patch snippet by id with token should return 204', async () => {
it('patch snippet by id with token should return 204 even if expired', async () => {
await client
.patch(`/tasks/${taskSnippetId}`)
.set('Authorization', 'Bearer ' + token)
Expand Down
11 changes: 8 additions & 3 deletions sci-log-db/src/controllers/task.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ export class TaskController {
})
task: Task,
): Promise<void> {
await this.taskRepository.updateByIdWithHistory(id, task, {
currentUser: this.user,
});
await this.taskRepository.updateByIdWithHistory(
id,
task,
{
currentUser: this.user,
},
false,
);
}

@del('/tasks/{id}', {
Expand Down
2 changes: 2 additions & 0 deletions sci-log-db/src/mixins/basesnippet.repository-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function UpdateAndDeleteRepositoryMixin<
id: ID,
basesnippet: ExpandedBasesnippet,
options?: Options,
checkExpiration = true,
): Promise<void> {
const baseSnippetRepository = await this.baseSnippetRepository();
const snippet = await baseSnippetRepository.findById(id, {}, options);
Expand All @@ -70,6 +71,7 @@ function UpdateAndDeleteRepositoryMixin<
if (Object.keys(patches).length === 0) return;
if (!basesnippet.deleted) {
if (
checkExpiration &&
!this.isSharing(patches) &&
(snippet.expiresAt?.getTime() < Date.now() || !snippet?.expiresAt)
) {
Expand Down

0 comments on commit 34b91c0

Please sign in to comment.