Skip to content

Commit

Permalink
SHIBUI-1848
Browse files Browse the repository at this point in the history
Periodic check-in at point where unti testing all passes
  • Loading branch information
chasegawa committed Jun 30, 2021
1 parent 63bf89c commit 038b9b4
Show file tree
Hide file tree
Showing 20 changed files with 893 additions and 671 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,9 @@ public ResponseEntity<?> update(@RequestBody EntityDescriptorRepresentation edRe
public ResponseEntity<?> getAll() {
User currentUser = userService.getCurrentUser();
if (currentUser != null) {
if (currentUser.getRole().equals("ROLE_ADMIN")) {
return ResponseEntity.ok(entityDescriptorRepository.findAllStreamByCustomQuery()
.map(ed -> entityDescriptorService.createRepresentationFromDescriptor(ed))
.collect(Collectors.toList()));
} else {
return ResponseEntity.ok(entityDescriptorRepository.findAllStreamByCreatedBy(currentUser.getUsername())
.map(ed -> entityDescriptorService.createRepresentationFromDescriptor(ed))
.collect(Collectors.toList()));
}
return ResponseEntity.ok(entityDescriptorService.getAllRepresentationsBasedOnUserAccess());
// .map(ed -> entityDescriptorService.createRepresentationFromDescriptor(ed))
// .collect(Collectors.toList()));
} else {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ErrorResponse(HttpStatus.FORBIDDEN,
"You are not authorized to perform the requested operation."));
Expand Down Expand Up @@ -246,8 +240,7 @@ public ResponseEntity<?> getAllVersions(@PathVariable String resourceId) {
@GetMapping("/EntityDescriptor/{resourceId}/Versions/{versionId}")
@Transactional(readOnly = true)
public ResponseEntity<?> getSpecificVersion(@PathVariable String resourceId, @PathVariable String versionId) {
EntityDescriptorRepresentation edRepresentation =
versionService.findSpecificVersionOfEntityDescriptor(resourceId, versionId);
EntityDescriptorRepresentation edRepresentation = versionService.findSpecificVersionOfEntityDescriptor(resourceId, versionId);

if (edRepresentation == null) {
return ResponseEntity.notFound().build();
Expand Down Expand Up @@ -309,9 +302,16 @@ private ResponseEntity<?> handleUploadingEntityDescriptorXml(byte[] rawXmlBytes,

private boolean isAuthorizedFor(String username) {
User u = userService.getCurrentUser();
return (u != null) &&
(u.getRole().equals("ROLE_ADMIN")
|| (u.getUsername().equals(username)));

switch (userService.getCurrentUserAccess()) {
case ADMIN:
return true;
case GROUP:
case OWNER:
return u.getUsername().equals(username);
default:
return false;
}
}

}
Loading

0 comments on commit 038b9b4

Please sign in to comment.