diff --git a/src/main/java/de/tum/cit/aet/artemis/lecture/web/AttachmentUnitResource.java b/src/main/java/de/tum/cit/aet/artemis/lecture/web/AttachmentUnitResource.java index 890e47898c6e..ac71195e08a1 100644 --- a/src/main/java/de/tum/cit/aet/artemis/lecture/web/AttachmentUnitResource.java +++ b/src/main/java/de/tum/cit/aet/artemis/lecture/web/AttachmentUnitResource.java @@ -115,18 +115,18 @@ public ResponseEntity getAttachmentUnit(@PathVariable Long attac * @param attachmentUnit the attachment unit with updated content * @param attachment the attachment with updated content * @param file the optional file to upload + * @param hiddenPages the pages to be hidden in the attachment unit * @param studentVersion the student version of the file to upload * @param keepFilename specifies if the original filename should be kept or not * @param notificationText the text to be used for the notification. No notification will be sent if the parameter is not set - * @param hiddenPages the pages to be hidden in the attachment unit. No hidden pages will be sent if the parameter is not set * @return the ResponseEntity with status 200 (OK) and with body the updated attachmentUnit */ @PutMapping(value = "lectures/{lectureId}/attachment-units/{attachmentUnitId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @EnforceAtLeastEditor public ResponseEntity updateAttachmentUnit(@PathVariable Long lectureId, @PathVariable Long attachmentUnitId, @RequestPart AttachmentUnit attachmentUnit, @RequestPart Attachment attachment, @RequestPart(required = false) MultipartFile file, @RequestPart(required = false) MultipartFile studentVersion, - @RequestParam(defaultValue = "false") boolean keepFilename, @RequestParam(value = "notificationText", required = false) String notificationText, - @RequestParam(value = "hiddenPages", required = false) String hiddenPages) { + @RequestPart(required = false) String hiddenPages, @RequestParam(defaultValue = "false") boolean keepFilename, + @RequestParam(value = "notificationText", required = false) String notificationText) { log.debug("REST request to update an attachment unit : {}", attachmentUnit); AttachmentUnit existingAttachmentUnit = attachmentUnitRepository.findWithSlidesAndCompetenciesByIdElseThrow(attachmentUnitId); checkAttachmentUnitCourseAndLecture(existingAttachmentUnit, lectureId); diff --git a/src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts b/src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts index b7e6dafd7c1a..4a5e3ed80a71 100644 --- a/src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts +++ b/src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachmentUnit.service.ts @@ -37,15 +37,14 @@ export class AttachmentUnitService { .pipe(map((res: EntityResponseType) => this.lectureUnitService.convertLectureUnitResponseDatesFromServer(res))); } - update(lectureId: number, attachmentUnitId: number, formData: FormData, notificationText?: string, hiddenPages?: string): Observable { + update(lectureId: number, attachmentUnitId: number, formData: FormData, notificationText?: string): Observable { /** Ngsw-worker is bypassed temporarily to fix Chromium file upload issue * See: https://issues.chromium.org/issues/374550348 **/ return this.httpClient .put( `${this.resourceURL}/lectures/${lectureId}/attachment-units/${attachmentUnitId}?keepFilename=true` + - (notificationText ? `¬ificationText=${notificationText}` : '') + - (hiddenPages ? `&hiddenPages=${hiddenPages}` : ''), + (notificationText ? `¬ificationText=${notificationText}` : ''), formData, { headers: { 'ngsw-bypass': 'true' }, observe: 'response' }, ) diff --git a/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.ts b/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.ts index 75e71c166801..a96ecc304f5e 100644 --- a/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.ts +++ b/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.ts @@ -180,30 +180,21 @@ export class PdfPreviewComponent implements OnInit, OnDestroy { const finalHiddenPages = this.getHiddenPages(); - if (finalHiddenPages.length <= 0) { - this.attachmentUnitService.update(this.attachmentUnit()!.lecture!.id!, this.attachmentUnit()!.id!, formData).subscribe({ - next: () => { - this.alertService.success('artemisApp.attachment.pdfPreview.attachmentUpdateSuccess'); - this.router.navigate(['course-management', this.course()?.id, 'lectures', this.attachmentUnit()!.lecture!.id, 'unit-management']); - }, - error: (error) => { - this.alertService.error('artemisApp.attachment.pdfPreview.attachmentUpdateError', { error: error.message }); - }, - }); - } else { + if (finalHiddenPages.length > 0) { const pdfFileWithHiddenPages = await this.createStudentVersionOfAttachment(finalHiddenPages); formData.append('studentVersion', pdfFileWithHiddenPages!); - - this.attachmentUnitService.update(this.attachmentUnit()!.lecture!.id!, this.attachmentUnit()!.id!, formData, undefined, finalHiddenPages.join(',')).subscribe({ - next: () => { - this.alertService.success('artemisApp.attachment.pdfPreview.attachmentUpdateSuccess'); - this.router.navigate(['course-management', this.course()?.id, 'lectures', this.attachmentUnit()!.lecture!.id, 'unit-management']); - }, - error: (error) => { - this.alertService.error('artemisApp.attachment.pdfPreview.attachmentUpdateError', { error: error.message }); - }, - }); + formData.append('hiddenPages', finalHiddenPages.join(',')); } + + this.attachmentUnitService.update(this.attachmentUnit()!.lecture!.id!, this.attachmentUnit()!.id!, formData).subscribe({ + next: () => { + this.alertService.success('artemisApp.attachment.pdfPreview.attachmentUpdateSuccess'); + this.router.navigate(['course-management', this.course()?.id, 'lectures', this.attachmentUnit()!.lecture!.id, 'unit-management']); + }, + error: (error) => { + this.alertService.error('artemisApp.attachment.pdfPreview.attachmentUpdateError', { error: error.message }); + }, + }); } }