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

SO-5566 Version API search restrictions #1226

Open
wants to merge 10 commits into
base: 9.x
Choose a base branch
from

Conversation

AAAlinaaa
Copy link
Contributor

No description provided.

@AAAlinaaa AAAlinaaa self-assigned this Oct 6, 2023
@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (e57082a) 47.96% compared to head (0fdc6f4) 48.00%.

Files Patch % Lines
...owl/core/request/version/VersionSearchRequest.java 76.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                9.x    #1226      +/-   ##
============================================
+ Coverage     47.96%   48.00%   +0.03%     
- Complexity    13831    13861      +30     
============================================
  Files          1942     1942              
  Lines         94946    94971      +25     
  Branches      10955    10961       +6     
============================================
+ Hits          45541    45588      +47     
+ Misses        46378    46353      -25     
- Partials       3027     3030       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Set<String> accessibleResources = authz.getAccessibleResources(context, context.service(User.class));

resourceIds.removeIf(resourceId -> !accessibleResources.contains(resourceId));
queryBuilder.filter(VersionDocument.Expressions.resourceIds(resourceIds));
Copy link
Member

Choose a reason for hiding this comment

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

If resourceIds becomes empty after authorization check, the search request can return quickly by throwing a NoResultException.

if (containsKey(OptionKey.RESOURCE)) {
Collection<String> resources = getCollection(OptionKey.RESOURCE, String.class);
Collection<String> resourceIds = resources.stream()
.map(resource -> resource.contains("/") ? new ResourceURI(resource).getResourceId() : resource)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.map(resource -> resource.contains("/") ? new ResourceURI(resource).getResourceId() : resource)
.map(resource -> resource.contains(Branch.SEPARATOR) ? new ResourceURI(resource).getResourceId() : resource)

.map(resource -> resource.contains("/") ? new ResourceURI(resource).getResourceId() : resource)
.toList();

if (user.isAdministrator()) {
Copy link
Member

Choose a reason for hiding this comment

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

Not just the administrator user can access all resources, any user with the browse:* permission can do that, please fix and create test cases for the various scenarios. Thanks!

@@ -172,6 +172,7 @@ public String getResourceId() {
return getResource().getResourceId();
}

@JsonIgnore
Copy link
Member

Choose a reason for hiding this comment

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

This is a valid API response property. Please remove this JsonIgnore annotation.

@AAAlinaaa AAAlinaaa force-pushed the issue/SO-5566-version-api-search-restrictions branch from 6bec14a to 0fdc6f4 Compare December 6, 2023 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants