Skip to content

Commit 4ee5a62

Browse files
nikkuma7GMishx
authored andcommitted
chore(deps): bump org.apache.velocity:velocity-engine-core
Bumps org.apache.velocity:velocity-engine-core from 2.4 to 2.4.1. --- updated-dependencies: - dependency-name: org.apache.velocity:velocity-engine-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Nikesh kumar <kumar.nikesh@siemens.com>
1 parent a84a42b commit 4ee5a62

File tree

3 files changed

+217
-92
lines changed

3 files changed

+217
-92
lines changed

rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.eclipse.sw360.datahandler.thrift.components.Release;
4242
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink;
4343
import org.eclipse.sw360.datahandler.thrift.projects.Project;
44+
import org.eclipse.sw360.datahandler.thrift.users.RequestedAction;
4445
import org.eclipse.sw360.datahandler.thrift.users.User;
4546
import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
4647
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO;
@@ -95,6 +96,7 @@
9596
import java.util.stream.Collectors;
9697

9798
import static org.eclipse.sw360.datahandler.common.WrappedException.wrapSW360Exception;
99+
import static org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission;
98100
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
99101

100102
@BasePathAwareController
@@ -108,6 +110,8 @@ public class ComponentController implements RepresentationModelProcessor<Reposit
108110
private static final Logger log = LogManager.getLogger(ComponentController.class);
109111
private static final ImmutableMap<String, String> RESPONSE_BODY_FOR_MODERATION_REQUEST = ImmutableMap.<String, String>builder()
110112
.put("message", "Moderation request is created").build();
113+
private static final ImmutableMap<String, String> RESPONSE_BODY_FOR_MODERATION_REQUEST_WITH_COMMIT = ImmutableMap.<String, String>builder()
114+
.put("message", "Unauthorized user or empty commit message passed.").build();
111115

112116
@NonNull
113117
private final Sw360ComponentService componentService;
@@ -383,12 +387,20 @@ public ResponseEntity<EntityModel<Component>> patchComponent(
383387
@Parameter(description = "The id of the component to be updated.")
384388
@PathVariable("id") String id,
385389
@Parameter(description = "The component with updated fields.")
386-
@RequestBody ComponentDTO updateComponentDto
390+
@RequestBody ComponentDTO updateComponentDto,
391+
@Parameter(description = "Comment message.")
392+
@RequestParam(value = "comment", required = false) String comment
387393
) throws TException {
388394
User user = restControllerHelper.getSw360UserFromAuthentication();
389395
Component sw360Component = componentService.getComponentForUserById(id, user);
396+
user.setCommentMadeDuringModerationRequest(comment);
397+
if (!restControllerHelper.isWriteActionAllowed(sw360Component, user)
398+
&& (comment == null || comment.isBlank())) {
399+
return new ResponseEntity(RESPONSE_BODY_FOR_MODERATION_REQUEST_WITH_COMMIT, HttpStatus.BAD_REQUEST);
400+
}
390401
if (updateComponentDto.getAttachments() != null) {
391-
updateComponentDto.getAttachments().forEach(attachment -> wrapSW360Exception(() -> this.attachmentService.fillCheckedAttachmentData(attachment, user)));
402+
updateComponentDto.getAttachments().forEach(attachment -> wrapSW360Exception(
403+
() -> this.attachmentService.fillCheckedAttachmentData(attachment, user)));
392404
}
393405
sw360Component = this.restControllerHelper.updateComponent(sw360Component, updateComponentDto);
394406
RequestStatus updateComponentStatus = componentService.updateComponent(sw360Component, user);
@@ -516,18 +528,27 @@ public ResponseEntity<EntityModel<Attachment>> patchComponentAttachmentInfo(
516528
@Parameter(description = "The id of the attachment.")
517529
@PathVariable("attachmentId") String attachmentId,
518530
@Parameter(description = "The attachment info to be updated.")
519-
@RequestBody Attachment attachmentData
531+
@RequestBody Attachment attachmentData,
532+
@Parameter(description = "Comment message.")
533+
@RequestParam(value = "comment", required = false) String comment
534+
520535
) throws TException {
521536
final User sw360User = restControllerHelper.getSw360UserFromAuthentication();
522537
final Component sw360Component = componentService.getComponentForUserById(id, sw360User);
523538
Set<Attachment> attachments = sw360Component.getAttachments();
524-
Attachment updatedAttachment = attachmentService.updateAttachment(attachments, attachmentData, attachmentId, sw360User);
539+
sw360User.setCommentMadeDuringModerationRequest(comment);
540+
Attachment updatedAttachment = attachmentService.updateAttachment(attachments, attachmentData, attachmentId,
541+
sw360User);
525542
RequestStatus updateComponentStatus = componentService.updateComponent(sw360Component, sw360User);
526-
if (updateComponentStatus == RequestStatus.SENT_TO_MODERATOR) {
527-
return new ResponseEntity(RESPONSE_BODY_FOR_MODERATION_REQUEST, HttpStatus.ACCEPTED);
543+
if (!restControllerHelper.isWriteActionAllowed(sw360Component, sw360User) && comment == null) {
544+
return new ResponseEntity(RESPONSE_BODY_FOR_MODERATION_REQUEST_WITH_COMMIT, HttpStatus.BAD_REQUEST);
545+
} else {
546+
if (updateComponentStatus == RequestStatus.SENT_TO_MODERATOR) {
547+
return new ResponseEntity(RESPONSE_BODY_FOR_MODERATION_REQUEST, HttpStatus.ACCEPTED);
548+
}
549+
EntityModel<Attachment> attachmentResource = EntityModel.of(updatedAttachment);
550+
return new ResponseEntity<>(attachmentResource, HttpStatus.OK);
528551
}
529-
EntityModel<Attachment> attachmentResource = EntityModel.of(updatedAttachment);
530-
return new ResponseEntity<>(attachmentResource, HttpStatus.OK);
531552
}
532553

533554
@Operation(
@@ -563,10 +584,16 @@ public ResponseEntity<HalResource> addAttachmentToComponent(
563584
@Parameter(description = "The file to be uploaded.")
564585
@RequestPart("file") MultipartFile file,
565586
@Parameter(description = "The attachment info to be created.")
566-
@RequestPart("attachment") Attachment newAttachment
587+
@RequestPart("attachment") Attachment newAttachment,
588+
@Parameter(description = "Comment message.")
589+
@RequestParam(value = "comment", required = false) String comment
567590
) throws TException {
568591
final User sw360User = restControllerHelper.getSw360UserFromAuthentication();
569592
final Component component = componentService.getComponentForUserById(componentId, sw360User);
593+
sw360User.setCommentMadeDuringModerationRequest(comment);
594+
if (!restControllerHelper.isWriteActionAllowed(component, sw360User) && comment == null) {
595+
return new ResponseEntity(RESPONSE_BODY_FOR_MODERATION_REQUEST_WITH_COMMIT, HttpStatus.BAD_REQUEST);
596+
}
570597
Attachment attachment = null;
571598
try {
572599
attachment = attachmentService.uploadAttachment(file, newAttachment, sw360User);
@@ -641,10 +668,15 @@ public void downloadAttachmentBundleFromComponent(
641668
@DeleteMapping(COMPONENTS_URL + "/{componentId}/attachments/{attachmentIds}")
642669
public ResponseEntity<HalResource<Component>> deleteAttachmentsFromComponent(
643670
@PathVariable("componentId") String componentId,
644-
@PathVariable("attachmentIds") List<String> attachmentIds) throws TException {
671+
@PathVariable("attachmentIds") List<String> attachmentIds,
672+
@Parameter(description = "Comment message.")
673+
@RequestParam(value = "comment", required = false) String comment) throws TException {
645674
User user = restControllerHelper.getSw360UserFromAuthentication();
646675
Component component = componentService.getComponentForUserById(componentId, user);
647-
676+
user.setCommentMadeDuringModerationRequest(comment);
677+
if (!restControllerHelper.isWriteActionAllowed(component, user) && comment == null) {
678+
return new ResponseEntity(RESPONSE_BODY_FOR_MODERATION_REQUEST_WITH_COMMIT, HttpStatus.BAD_REQUEST);
679+
}
648680
Set<Attachment> attachmentsToDelete = attachmentService.filterAttachmentsToRemove(Source.componentId(componentId),
649681
component.getAttachments(), attachmentIds);
650682
if (attachmentsToDelete.isEmpty()) {

rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,7 @@ public ClearingRequest updateCRSize(ClearingRequest clearingRequest, Project pro
16601660
return clearingRequestService.getClearingRequestById(clearingRequest.getId(), sw360User);
16611661
}
16621662

1663+
16631664
public boolean isWriteActionAllowed(Object object, User user) {
16641665
return makePermission(object, user).isActionAllowed(RequestedAction.WRITE);
16651666
}

0 commit comments

Comments
 (0)