Skip to content

Commit

Permalink
fix: max expiration gets ignored if expiration is set to "never"
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Nov 17, 2023
1 parent 2e1a2b6 commit 330eef5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion backend/src/share/guard/shareOwner.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions backend/src/share/share.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 330eef5

Please sign in to comment.