Skip to content

Commit

Permalink
Merge pull request #569 from gbif/improve-error-messages-griscicoll
Browse files Browse the repository at this point in the history
Improving error message for creation of collections (https://github.c…
  • Loading branch information
ahakanzn authored May 7, 2024
2 parents e3fc0e6 + a1d92b1 commit 482c013
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,18 @@ public EntityOperationResponse allowedToCreateInstitution(
boolean allowedToModifyCountry = allowedToModifyCountry(authentication.getName(), country);
if (allowedToModifyCountry) {
return new EntityOperationResponse(true);
}
else {
return new EntityOperationResponse(false, "Not allowed to create institutions for the country: " + country);
} else {
return new EntityOperationResponse(
false, "Not allowed to create institutions for the country: " + country);
}
}

/**
* An editor or mediator can create collections if they have their institution or country in the
* scopes.
*/
public EntityOperationResponse allowedToCreateCollection(Collection collection, Authentication authentication) {
public EntityOperationResponse allowedToCreateCollection(
Collection collection, Authentication authentication) {
if (SecurityContextCheck.checkUserInRole(authentication, GRSCICOLL_ADMIN_ROLE)) {
return new EntityOperationResponse(true);
}
Expand All @@ -282,9 +283,13 @@ public EntityOperationResponse allowedToCreateCollection(Collection collection,

if (allowedToModifyCountry || allowedToModifyEntity) {
return new EntityOperationResponse(true, "");
}
else {
return new EntityOperationResponse(false, "Not allowed to create collections under the institution " + institutionKey + "or in the country " + country);
} else {
return new EntityOperationResponse(
false,
"Not allowed to create collections under the institution: "
+ institutionKey
+ " or in the country: "
+ country);
}
}

Expand All @@ -304,7 +309,9 @@ public boolean allowedToUpdateChangeSuggestion(

if (changeSuggestion.getType() == Type.CREATE) {
return allowedToCreateInstitution(
readEntity(changeSuggestion.getSuggestedEntity(), Institution.class), authentication).isAllowed();
readEntity(changeSuggestion.getSuggestedEntity(), Institution.class),
authentication)
.isAllowed();
} else if (changeSuggestion.getType() == Type.DELETE) {
return allowedToDeleteInstitution(authentication, changeSuggestion.getEntityKey());
} else if (changeSuggestion.getType() == Type.MERGE) {
Expand Down Expand Up @@ -375,8 +382,8 @@ public static class EntityOperationResponse {
private boolean allowed;
private String message;

public EntityOperationResponse(boolean allowed){
this(allowed,null);
public EntityOperationResponse(boolean allowed) {
this(allowed, null);
}
}
}

0 comments on commit 482c013

Please sign in to comment.