Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add namespaces check in synchronization configuration feature #5192

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model) {
@PutMapping(value = "/apps/{appId}/namespaces/{namespaceName}/items", consumes = {"application/json"})
public ResponseEntity<Void> update(@PathVariable String appId, @PathVariable String namespaceName,
@RequestBody NamespaceSyncModel model) {
checkModel(!model.isInvalid());
checkModel(!model.isInvalid() && model.syncToNamespacesValid(appId, namespaceName));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Add unit tests to verify the new validation logic.

The code changes are approved. Ensure to add unit tests to verify the new validation logic in the update method.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

boolean hasPermission = permissionValidator.hasModifyNamespacePermission(appId, namespaceName);
Env envNoPermission = null;
// if uses has ModifyNamespace permission then he has permission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public boolean isInvalid() {
return false;
}

public boolean syncToNamespacesValid(String appId, String namespaceName) {
for (NamespaceIdentifier namespaceIdentifier : syncToNamespaces) {
if (appId.equals(namespaceIdentifier.getAppId()) && namespaceName.equals(
namespaceIdentifier.getNamespaceName())) {
continue;
}
return false;
}
return true;
Comment on lines +44 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using stream and allMatch for better readability.

The current implementation is functional but can be improved for readability and conciseness.

public boolean syncToNamespacesValid(String appId, String namespaceName) {
  return syncToNamespaces.stream()
    .allMatch(namespaceIdentifier -> appId.equals(namespaceIdentifier.getAppId()) && namespaceName.equals(namespaceIdentifier.getNamespaceName()));
}

}

public List<NamespaceIdentifier> getSyncToNamespaces() {
return syncToNamespaces;
}
Expand Down
Loading