From 330eef51e4f3f3fb29833bc9337e705553340aaa Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Fri, 17 Nov 2023 15:27:22 +0100 Subject: [PATCH] fix: max expiration gets ignored if expiration is set to "never" --- backend/src/share/guard/shareOwner.guard.ts | 1 - backend/src/share/share.service.ts | 9 +++++++-- .../components/account/showShareInformationsModal.tsx | 2 +- .../components/upload/modals/showCreateUploadModal.tsx | 8 +++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/backend/src/share/guard/shareOwner.guard.ts b/backend/src/share/guard/shareOwner.guard.ts index 8a5f5386b..0ff726347 100644 --- a/backend/src/share/guard/shareOwner.guard.ts +++ b/backend/src/share/guard/shareOwner.guard.ts @@ -19,7 +19,6 @@ export class ShareOwnerGuard extends JwtGuard { } async canActivate(context: ExecutionContext) { - const request: Request = context.switchToHttp().getRequest(); const shareId = Object.prototype.hasOwnProperty.call( request.params, diff --git a/backend/src/share/share.service.ts b/backend/src/share/share.service.ts index ad44dd651..c4831740b 100644 --- a/backend/src/share/share.service.ts +++ b/backend/src/share/share.service.ts @@ -54,10 +54,15 @@ export class ShareService { } else { const parsedExpiration = parseRelativeDateToAbsolute(share.expiration); + const expiresNever = moment(0).toDate() == parsedExpiration; + if ( this.config.get("share.maxExpiration") !== 0 && - parsedExpiration > - moment().add(this.config.get("share.maxExpiration"), "hours").toDate() + (expiresNever || + parsedExpiration > + moment() + .add(this.config.get("share.maxExpiration"), "hours") + .toDate()) ) { throw new BadRequestException( "Expiration date exceeds maximum expiration date", diff --git a/frontend/src/components/account/showShareInformationsModal.tsx b/frontend/src/components/account/showShareInformationsModal.tsx index 4cfdc20d3..3852e3843 100644 --- a/frontend/src/components/account/showShareInformationsModal.tsx +++ b/frontend/src/components/account/showShareInformationsModal.tsx @@ -12,7 +12,7 @@ const showShareInformationsModal = ( modals: ModalsContextProps, share: MyShare, appUrl: string, - maxShareSize: number + maxShareSize: number, ) => { const t = translateOutsideContext(); const link = `${appUrl}/s/${share.id}`; diff --git a/frontend/src/components/upload/modals/showCreateUploadModal.tsx b/frontend/src/components/upload/modals/showCreateUploadModal.tsx index 72490c964..67f67663f 100644 --- a/frontend/src/components/upload/modals/showCreateUploadModal.tsx +++ b/frontend/src/components/upload/modals/showCreateUploadModal.tsx @@ -125,11 +125,13 @@ const CreateUploadModalBody = ({ "", ) as moment.unitOfTime.DurationConstructor, ); + if ( options.maxExpirationInHours != 0 && - expirationDate.isAfter( - moment().add(options.maxExpirationInHours, "hours"), - ) + (form.values.never_expires || + expirationDate.isAfter( + moment().add(options.maxExpirationInHours, "hours"), + )) ) { form.setFieldError( "expiration_num",