Skip to content

Commit

Permalink
Merge pull request #455 from SSHOC/feature/myaccesid
Browse files Browse the repository at this point in the history
Enable MyAccessId as AAI proxy
  • Loading branch information
olanowak authored Aug 22, 2024
2 parents af59b43 + cf88472 commit f475e95
Show file tree
Hide file tree
Showing 25 changed files with 428 additions and 33 deletions.
6 changes: 3 additions & 3 deletions docker-compose-acdh-develop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: "2"
services:
marketplace:
build:
build:
context: .
dockerfile: Dockerfile-acdh-ch
args:
args:
- GID=1032
- UID=1032
image: docker.gitlab.gwdg.de/sshoc/sshoc-marketplace-backend/api:latest
Expand All @@ -23,7 +23,7 @@ services:
POSTGRES_PORT: 5432
SOLR_HOST: solr
SOLR_PORT: 8983
aai_base_uri: https://aai.eosc-portal.eu/oidc
aai_base_uri: https://proxy.acc.myaccessid.org/OIDC
egi_id: ${egi_id}
egi_secret: ${egi_secret}
token_secret: ${token_secret}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-acdh-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
POSTGRES_PORT: 5432
SOLR_HOST: solr-prod
SOLR_PORT: 8983
aai_base_uri: https://aai.eosc-portal.eu/oidc
aai_base_uri: https://proxy.acc.myaccessid.org/OIDC
egi_id: ${egi_id}
egi_secret: ${egi_secret}
token_secret: ${token_secret}
Expand Down
6 changes: 3 additions & 3 deletions docker-compose-acdh-stage.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: "2"
services:
marketplace-stage:
build:
build:
context: .
dockerfile: Dockerfile-acdh-ch
args:
args:
- GID=1057
- UID=1057
image: docker.gitlab.gwdg.de/sshoc/sshoc-marketplace-backend/api-stage:latest
Expand All @@ -23,7 +23,7 @@ services:
POSTGRES_PORT: 5432
SOLR_HOST: solr-stage
SOLR_PORT: 8983
aai_base_uri: https://aai.eosc-portal.eu/oidc
aai_base_uri: https://proxy.acc.myaccessid.org/OIDC
egi_id: ${egi_id}
egi_secret: ${egi_secret}
token_secret: ${token_secret}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- solr
environment:
APPLICATION_PROFILE: dev
aai_base_uri: https://aai.eosc-portal.eu/oidc
aai_base_uri: https://proxy.acc.myaccessid.org/OIDC
egi_id: ${egi_id}
egi_secret: ${egi_secret}
token_secret: ${token_secret}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.GET, "/api/datasets/*/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.POST, "/api/datasets/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/datasets/*/versions/*/revert").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/datasets/*/revert").hasAuthority(Authority.ADMINISTRATOR.name())
.antMatchers(HttpMethod.POST, "/api/datasets/**").hasAuthority(Authority.CONTRIBUTOR.name())
.antMatchers(HttpMethod.PUT, "/api/datasets/**").hasAuthority(Authority.CONTRIBUTOR.name())
.antMatchers(HttpMethod.DELETE, "/api/datasets/**").hasAuthority(Authority.CONTRIBUTOR.name());
Expand All @@ -123,6 +124,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.GET, "/api/tools-services/*/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.POST, "/api/tools-services/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/tools-services/*/versions/*/revert").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/tools-services/*/revert").hasAuthority(Authority.ADMINISTRATOR.name())
.antMatchers(HttpMethod.POST, "/api/tools-services/**").hasAuthority(Authority.CONTRIBUTOR.name())
.antMatchers(HttpMethod.PUT, "/api/tools-services/**").hasAuthority(Authority.CONTRIBUTOR.name())
.antMatchers(HttpMethod.DELETE, "/api/tools-services/**").hasAuthority(Authority.CONTRIBUTOR.name());
Expand All @@ -131,6 +133,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.GET, "/api/training-materials/*/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.POST, "/api/training-materials/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/training-materials/*/versions/*/revert").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/training-materials/*/revert").hasAuthority(Authority.ADMINISTRATOR.name())
.antMatchers(HttpMethod.POST, "/api/training-materials/**").hasAuthority(Authority.CONTRIBUTOR.name())
.antMatchers(HttpMethod.PUT, "/api/training-materials/**").hasAuthority(Authority.CONTRIBUTOR.name())
.antMatchers(HttpMethod.DELETE, "/api/training-materials/**").hasAuthority(Authority.CONTRIBUTOR.name());
Expand All @@ -139,6 +142,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.GET, "/api/publications/*/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.POST, "/api/publications/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/publications/*/versions/*/revert").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/publications/*/revert").hasAuthority(Authority.ADMINISTRATOR.name())
.antMatchers(HttpMethod.POST, "/api/publications/**").hasAuthority(Authority.CONTRIBUTOR.name())
.antMatchers(HttpMethod.PUT, "/api/publications/**").hasAuthority(Authority.CONTRIBUTOR.name())
.antMatchers(HttpMethod.DELETE, "/api/publications/**").hasAuthority(Authority.MODERATOR.name());
Expand All @@ -147,6 +151,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.GET, "/api/workflows/*/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.POST, "/api/workflows/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/workflows/*/versions/*/revert").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/workflows/*/revert").hasAuthority(Authority.ADMINISTRATOR.name())
.antMatchers(HttpMethod.GET, "/api/workflows/*/steps/*/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.POST, "/api/workflows/*/steps/merge").hasAuthority(Authority.MODERATOR.name())
.antMatchers(HttpMethod.PUT, "/api/workflows/*/steps/*/versions/*/revert").hasAuthority(Authority.MODERATOR.name())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ public ResponseEntity<DatasetDto> revertDataset(@PathVariable("persistentId") St
return ResponseEntity.ok(datasetService.revertDataset(persistentId, versionId));
}

@Operation(summary = "Revert dataset by its persistentId. This method will set its status to ACTIVE " +
"and its versioned item to REVIEWED status and active state.")
@PutMapping(path = "/{persistentId}/revert", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<DatasetDto> revertDataset(@PathVariable("persistentId") String persistentId) {
return ResponseEntity.ok(datasetService.revertDataset(persistentId));
}

@Operation(summary = "Delete dataset by its persistentId")
@DeleteMapping(path = "/{persistentId}")
public void deleteDataset(@PathVariable("persistentId") String persistentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public void deletePublication(@PathVariable("persistentId") String persistentId,
publicationService.deletePublication(persistentId, draft);
}

@Operation(summary = "Revert publication by its persistentId. This method will set its status to ACTIVE " +
"and its versioned item to REVIEWED status and active state.")
@PutMapping(path = "/{persistentId}/revert", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PublicationDto> revertPublication(@PathVariable("persistentId") String persistentId) {
return ResponseEntity.ok(publicationService.revertPublication(persistentId));
}

@Operation(summary = "Delete publication by its persistentId and versionId")
@DeleteMapping(path = "/{persistentId}/versions/{versionId}")
public void deletePublicationVersion(@PathVariable("persistentId") String persistentId, @PathVariable("versionId") long versionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public ResponseEntity<ToolDto> revertTool(@PathVariable("persistentId") String p
return ResponseEntity.ok(toolService.revertTool(persistentId, versionId));
}

@Operation(summary = "Revert tool by its persistentId. This method will set its status to ACTIVE " +
"and its versioned item to REVIEWED status and active state.")
@PutMapping(path = "/{persistentId}/revert", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ToolDto> revertTool(@PathVariable("persistentId") String persistentId) {
return ResponseEntity.ok(toolService.revertTool(persistentId));
}

@Operation(summary = "Delete tool by its persistentId")
@DeleteMapping(path = "/{persistentId}")
public void deleteTool(@PathVariable("persistentId") String persistentId, @RequestParam(value = "draft", defaultValue = "false") boolean draft) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ public ResponseEntity<TrainingMaterialDto> revertTrainingMaterial(@PathVariable(
return ResponseEntity.ok(trainingMaterialService.revertTrainingMaterial(persistentId, versionId));
}

@Operation(summary = ("Revert training material by its persistentId. This method " +
"will set its status to ACTIVE and its versioned item to REVIEWED status and active state."))
@PutMapping(path = "/{persistentId}/revert", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<TrainingMaterialDto> revertTrainingMaterial(@PathVariable("persistentId") String persistentId) {
return ResponseEntity.ok(trainingMaterialService.revertTrainingMaterial(persistentId));
}

@Operation(summary = "Delete training material by its persistentId")
@DeleteMapping(path = "/{persistentId}")
public void deleteTrainingMaterial(@PathVariable("persistentId") String persistentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public ResponseEntity<WorkflowDto> revertWorkflow(@PathVariable("persistentId")
return ResponseEntity.ok(workflowService.revertWorkflow(workflowPersistentId, versionId));
}

@Operation(summary = "Revert workflow by its persistentId. This method will set its status to ACTIVE " +
"and its versioned item to REVIEWED status and active state.")
@PutMapping(path = "/{persistentId}/revert", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<WorkflowDto> revertWorkflow(@PathVariable("persistentId") String workflowPersistentId) {
return ResponseEntity.ok(workflowService.revertWorkflow(workflowPersistentId));
}

@Operation(summary = "Delete workflow by its persistentId")
@DeleteMapping(path = "/{persistentId}")
public void deleteWorkflow(@PathVariable("persistentId") String workflowPersistentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ public interface ItemVersionRepository<T extends Item> extends JpaRepository<T,
"where i.persistentId = :persistentId " +
"and i.active = true"
)
Optional<T> findCurrentVersion(@Param("persistentId") String persistentId);
Optional<T> findCurrentActiveVersion(@Param("persistentId") String persistentId);

@Query(
"select v from #{#entityName} v " +
"join VersionedItem i on i.currentVersion = v " +
"where i.persistentId = :persistentId"
)
Optional<T> findCurrentVersion(@Param("persistentId") String persistentId);

@Query(
"select v from #{#entityName} v " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public DatasetDto revertDataset(String persistentId, long versionId) {
return prepareItemDto(dataset);
}

public DatasetDto revertDataset(String persistentId) {
Dataset dataset = revertItemVersion(persistentId);
return prepareItemDto(dataset);
}

public DatasetDto commitDraftDataset(String persistentId) {
Dataset dataset = publishDraftItem(persistentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,18 @@ protected I revertItemVersion(String persistentId, long versionId) {
return targetVersion;
}

protected I revertItemVersion(String persistentId) {
I currentVersion = loadCurrentItem(persistentId, false);

currentVersion.setStatus(ItemStatus.APPROVED);
currentVersion.getVersionedItem().setActive(true);
currentVersion.getVersionedItem().setStatus(VersionedItemStatus.REVIEWED);

indexItemService.indexItem(currentVersion);

return currentVersion;
}

protected I liftItemVersion(String persistentId, boolean draft) {
return liftItemVersion(persistentId, draft, true);
}
Expand Down Expand Up @@ -691,7 +703,7 @@ protected D prepareMergeItems(String persistentId, List<String> mergeList) {

for (int i = 0; i < mergeList.size(); i++) {

Optional<Item> toMergeHolder = itemRepository.findCurrentVersion(mergeList.get(i));
Optional<Item> toMergeHolder = itemRepository.findCurrentActiveVersion(mergeList.get(i));
if (toMergeHolder.isEmpty())
continue;
Item toMerge = toMergeHolder.get();
Expand Down Expand Up @@ -791,7 +803,7 @@ protected ItemsDifferencesDto getDifferences(String persistentId, Long versionId

Optional<Item> otherHolder;
if (Objects.isNull(otherVersionId))
otherHolder = itemRepository.findCurrentVersion(otherPersistentId);
otherHolder = itemRepository.findCurrentActiveVersion(otherPersistentId);
else
otherHolder = itemRepository.findByVersionedItemPersistentIdAndId(otherPersistentId, otherVersionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,26 @@ protected Optional<I> tryLoadLatestItem(String persistentId) {
}

/**
* Loads the most recent item for update. Does not necessarily need to be approved
* Loads the most recent item for update. Does not need to be approved.
* For the internal use only, as this method does not validate user access privileges
* @param onlyActive if true seeks for active items only
*/
protected I loadCurrentItem(String persistentId) {
protected I loadCurrentItem(String persistentId, boolean onlyActive) {
// Here - why not to load VersionedItem, and then do getCurrentVersion() ?
// Because getCurrentVersion() returns Item, and we want the generic item type I
// Because getCurrentVersion() and getCurrentActiveVersion() returns Item, and we want the generic item type I
// Hence, there is a dedicated method in the repository - do not remove
return getItemRepository().findCurrentVersion(persistentId).orElseThrow(() -> new EntityNotFoundException(
String.format("Unable to find current %s with id %s", getItemTypeName(), persistentId)));
return (onlyActive ? getItemRepository().findCurrentActiveVersion(
persistentId) : getItemRepository().findCurrentVersion(persistentId)).orElseThrow(
() -> new EntityNotFoundException(
String.format("Unable to find current %s with id %s", getItemTypeName(), persistentId)));
}

/**
* Loads the most recent item for update. Does not need to be approved, but needs to be active.
* For the internal use only, as this method does not validate user access privileges
*/
protected I loadCurrentItem(String persistentId) {
return loadCurrentItem(persistentId, true);
}


Expand Down Expand Up @@ -166,6 +177,6 @@ protected Optional<I> tryLoadLatestMergedItem(String persistentId) {
while (isMerged(itemPersistentId)) {
itemPersistentId = getItemRepository().findMergedWithPersistentId(itemPersistentId);
}
return getItemRepository().findCurrentVersion(itemPersistentId);
return getItemRepository().findCurrentActiveVersion(itemPersistentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import eu.sshopencloud.marketplace.domain.media.MediaStorageService;
import eu.sshopencloud.marketplace.dto.PageCoords;
import eu.sshopencloud.marketplace.dto.auth.UserDto;
import eu.sshopencloud.marketplace.dto.datasets.DatasetDto;
import eu.sshopencloud.marketplace.dto.items.ItemExtBasicDto;
import eu.sshopencloud.marketplace.dto.items.ItemsDifferencesDto;
import eu.sshopencloud.marketplace.dto.publications.PaginatedPublications;
import eu.sshopencloud.marketplace.dto.publications.PublicationCore;
import eu.sshopencloud.marketplace.dto.publications.PublicationDto;
import eu.sshopencloud.marketplace.dto.sources.SourceDto;
import eu.sshopencloud.marketplace.mappers.datasets.DatasetMapper;
import eu.sshopencloud.marketplace.mappers.publications.PublicationMapper;
import eu.sshopencloud.marketplace.model.items.Item;
import eu.sshopencloud.marketplace.model.publications.Publication;
Expand Down Expand Up @@ -86,6 +84,11 @@ public PublicationDto revertPublication(String persistentId, long versionId) {
return prepareItemDto(publication);
}

public PublicationDto revertPublication(String persistentId) {
Publication publication = revertItemVersion(persistentId);
return prepareItemDto(publication);
}

public PublicationDto commitDraftPublication(String persistentId) {
Publication publication = publishDraftItem(persistentId);
return prepareItemDto(publication);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import eu.sshopencloud.marketplace.domain.media.MediaStorageService;
import eu.sshopencloud.marketplace.dto.PageCoords;
import eu.sshopencloud.marketplace.dto.auth.UserDto;
import eu.sshopencloud.marketplace.dto.datasets.DatasetDto;
import eu.sshopencloud.marketplace.dto.items.ItemExtBasicDto;
import eu.sshopencloud.marketplace.dto.items.ItemsDifferencesDto;
import eu.sshopencloud.marketplace.dto.sources.SourceDto;
import eu.sshopencloud.marketplace.dto.tools.PaginatedTools;
import eu.sshopencloud.marketplace.dto.tools.ToolCore;
import eu.sshopencloud.marketplace.dto.tools.ToolDto;
import eu.sshopencloud.marketplace.mappers.datasets.DatasetMapper;
import eu.sshopencloud.marketplace.mappers.tools.ToolMapper;
import eu.sshopencloud.marketplace.model.items.Item;
import eu.sshopencloud.marketplace.model.tools.Tool;
Expand Down Expand Up @@ -86,6 +84,11 @@ public ToolDto revertTool(String persistentId, long versionId) {
return prepareItemDto(tool);
}

public ToolDto revertTool(String persistentId) {
Tool tool = revertItemVersion(persistentId);
return prepareItemDto(tool);
}

public ToolDto commitDraftTool(String persistentId) {
Tool tool = publishDraftItem(persistentId);
return prepareItemDto(tool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import eu.sshopencloud.marketplace.domain.media.MediaStorageService;
import eu.sshopencloud.marketplace.dto.PageCoords;
import eu.sshopencloud.marketplace.dto.auth.UserDto;
import eu.sshopencloud.marketplace.dto.datasets.DatasetDto;
import eu.sshopencloud.marketplace.dto.items.ItemExtBasicDto;
import eu.sshopencloud.marketplace.dto.items.ItemsDifferencesDto;
import eu.sshopencloud.marketplace.dto.sources.SourceDto;
import eu.sshopencloud.marketplace.dto.trainings.PaginatedTrainingMaterials;
import eu.sshopencloud.marketplace.dto.trainings.TrainingMaterialCore;
import eu.sshopencloud.marketplace.dto.trainings.TrainingMaterialDto;
import eu.sshopencloud.marketplace.mappers.datasets.DatasetMapper;
import eu.sshopencloud.marketplace.mappers.trainings.TrainingMaterialMapper;
import eu.sshopencloud.marketplace.model.items.Item;
import eu.sshopencloud.marketplace.model.trainings.TrainingMaterial;
Expand Down Expand Up @@ -90,6 +88,11 @@ public TrainingMaterialDto revertTrainingMaterial(String persistentId, long vers
return prepareItemDto(trainingMaterial);
}

public TrainingMaterialDto revertTrainingMaterial(String persistentId) {
TrainingMaterial trainingMaterial = revertItemVersion(persistentId);
return prepareItemDto(trainingMaterial);
}

public TrainingMaterialDto commitDraftTrainingMaterial(String persistentId) {
TrainingMaterial trainingMaterial = publishDraftItem(persistentId);
return prepareItemDto(trainingMaterial);
Expand Down
Loading

0 comments on commit f475e95

Please sign in to comment.