Skip to content

Commit

Permalink
Add admin rest API changes to support environment visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Naduni Pamudika committed Jan 6, 2025
1 parent c4d9496 commit 7194e8a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5033,14 +5033,21 @@ public static Set<String> extractEnvironmentsForAPI(String environments) throws
public static Set<String> extractVisibleEnvironmentsForUser(List<Environment> environments, String organization, String userName) throws APIManagementException {

Set<String> environmentStringSet = new HashSet<String>();
String[] userRoles = APIUtil.getListOfRoles(userName);
List<String> userRolesList;
if (userName == null) {
userRolesList = new ArrayList<String>() {{
add(APIConstants.NULL_USER_ROLE_LIST);
}};
} else {
userRolesList = new ArrayList<String>(Arrays.asList(APIUtil.getListOfRoles(userName)));
}
if (environments != null) {
for (Environment environment : environments) {
String[] permittedRoles = environment.getVisibilityRoles();
if (permittedRoles[0].equals("all")) {
environmentStringSet.add(environment.toString());
} else {
for (String role : userRoles) {
for (String role : userRolesList) {
for (String permission : permittedRoles) {
if (role.equals(permission)) {
environmentStringSet.add(environment.toString());
Expand All @@ -5056,7 +5063,7 @@ public static Set<String> extractVisibleEnvironmentsForUser(List<Environment> en
if (permittedRoles != null && permittedRoles[0].equals("all")) {
environmentStringSet.add(environment.toString());
} else if (permittedRoles != null) {
for (String role : userRoles) {
for (String role : userRolesList) {
for (String permission : permittedRoles) {
if (role.equals(permission)) {
environmentStringSet.add(environment.toString());
Expand All @@ -5074,14 +5081,21 @@ public static Set<String> extractVisibleEnvironmentsForUser(List<Environment> en
public static Map<String, Environment> extractVisibleEnvironmentsForUser(String organization, String userName) throws APIManagementException {

Map<String, Environment> returnEnvironments = new LinkedHashMap<>();
String[] userRoles = APIUtil.getListOfRoles(userName);
List<String> userRolesList;
if (userName == null) {
userRolesList = new ArrayList<String>() {{
add(APIConstants.NULL_USER_ROLE_LIST);
}};
} else {
userRolesList = new ArrayList<String>(Arrays.asList(APIUtil.getListOfRoles(userName)));
}
Map<String, Environment> environmentsMap = getEnvironments(organization);
for (Environment environment : environmentsMap.values()) {
String[] permittedRoles = environment.getVisibilityRoles();
if (permittedRoles != null && permittedRoles[0].equals("all")) {
returnEnvironments.put(environment.getName(), environment);
} else if (permittedRoles != null) {
for (String role : userRoles) {
for (String role : userRolesList) {
for (String permission : permittedRoles) {
if (role.equals(permission)) {
returnEnvironments.put(environment.getName(), environment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class EnvironmentDTO {
private String displayName = null;
private String provider = null;
private String type = "hybrid";
private String visibility = "all";
private String gatewayType = "Regular";
private String description = null;
private Boolean isReadOnly = null;
Expand Down Expand Up @@ -123,6 +124,23 @@ public void setType(String type) {
this.type = type;
}

/**
**/
public EnvironmentDTO visibility(String visibility) {
this.visibility = visibility;
return this;
}


@ApiModelProperty(example = "role1, role2", value = "")
@JsonProperty("visibility")
public String getVisibility() {
return visibility;
}
public void setVisibility(String visibility) {
this.visibility = visibility;
}

/**
**/
public EnvironmentDTO gatewayType(String gatewayType) {
Expand Down Expand Up @@ -244,6 +262,7 @@ public boolean equals(java.lang.Object o) {
Objects.equals(displayName, environment.displayName) &&
Objects.equals(provider, environment.provider) &&
Objects.equals(type, environment.type) &&
Objects.equals(visibility, environment.visibility) &&
Objects.equals(gatewayType, environment.gatewayType) &&
Objects.equals(description, environment.description) &&
Objects.equals(isReadOnly, environment.isReadOnly) &&
Expand All @@ -254,7 +273,7 @@ public boolean equals(java.lang.Object o) {

@Override
public int hashCode() {
return Objects.hash(id, name, displayName, provider, type, gatewayType, description, isReadOnly, vhosts, endpointURIs, additionalProperties);
return Objects.hash(id, name, displayName, provider, type, visibility, gatewayType, description, isReadOnly, vhosts, endpointURIs, additionalProperties);
}

@Override
Expand All @@ -267,6 +286,7 @@ public String toString() {
sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n");
sb.append(" provider: ").append(toIndentedString(provider)).append("\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" visibility: ").append(toIndentedString(visibility)).append("\n");
sb.append(" gatewayType: ").append(toIndentedString(gatewayType)).append("\n");
sb.append(" description: ").append(toIndentedString(description)).append("\n");
sb.append(" isReadOnly: ").append(toIndentedString(isReadOnly)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static EnvironmentDTO fromEnvToEnvDTO(Environment env) {
envDTO.setDescription(env.getDescription());
envDTO.setProvider(env.getProvider());
envDTO.setGatewayType(env.getGatewayType());
envDTO.setVisibility(env.getVisibility());
envDTO.setIsReadOnly(env.isReadOnly());
envDTO.setVhosts(env.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostToVHostDTO)
.collect(Collectors.toList()));
Expand Down Expand Up @@ -134,6 +135,7 @@ public static Environment fromEnvDtoToEnv(EnvironmentDTO envDTO) {
env.setDescription(envDTO.getDescription());
env.setProvider(envDTO.getProvider());
env.setGatewayType(envDTO.getGatewayType());
env.setVisibility(envDTO.getVisibility());
env.setReadOnly(false);
env.setVhosts(envDTO.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostDtoToVHost)
.collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4674,6 +4674,10 @@ components:
type: string
default: hybrid
example: hybrid
visibility:
type: string
default: all
example: role1, role2
gatewayType:
type: string
example: Regular
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4674,6 +4674,10 @@ components:
type: string
default: hybrid
example: hybrid
visibility:
type: string
default: all
example: role1, role2
gatewayType:
type: string
example: Regular
Expand Down

0 comments on commit 7194e8a

Please sign in to comment.