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

DS-4495 Restricted endpoints are sometimes the only HAL link path to public endpoints #2766

Merged
merged 2 commits into from Jun 4, 2020

Conversation

Micheleboychuk
Copy link
Contributor

@Micheleboychuk Micheleboychuk commented May 21, 2020

References

https://jira.lyrasis.org/browse/DS-4495

Description

A class has been added that allows to add the root endpoints the links to standard nested endpoint that are not discoverable due to limitation to access some resource collection endpoint via GET

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You need not complete this checklist prior to creating your PR (draft PRs are always welcome). If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & integration tests). Exceptions may be made if previously agreed upon.
  • My PR passes Checkstyle validation based on the Code Style Guide
  • My PR includes Javadoc for all new (or modified) public methods and classes. It also includes Javadoc for large or complex private methods.
  • My PR passes all tests and includes new/updated Unit or Integration Tests for any bug fixes, improvements or new features. A few reminders about what constitutes good tests:
    • Include tests for different user types, including: (1) Anonymous user, (2) Logged in user (non-admin), and (3) Administrator.
    • Include tests for known error scenarios and error codes (e.g. 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, etc)
    • For bug fixes, include a test that reproduces the bug and proves it is fixed. For clarity, it may be useful to provide the test in a separate commit from the bug fix.
  • [N/A If my PR includes new, third-party dependencies (in any pom.xml), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • N/A If my PR modifies the REST API, I've linked to the REST Contract page (or open PR) related to this change.

@abollini abollini added the interface: REST API v7+ REST API for v7 and later (dspace-server-webapp module) label May 21, 2020
Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

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

Overall, this looks fine to me. I'm OK with this route, but had a question inline. I haven't tested this yet though, as I'd like feedback from the Angular team (@artlowel perhaps) on whether this solves the issues they saw in DS-4495.

discoverableEndpointsService
.register(ResourcePolicyRestRepository.class , Arrays.asList(new Link("/api/"
+ ResourcePolicyRest.CATEGORY + "/" + ResourcePolicyRest.NAME + "/search",
ResourcePolicyRest.NAME + "-search")));
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming there's no way to do this in the RestRepository classes themselves? The code here looks reasonable, but it just seems slightly odd to me that we have to do this in a separate class instead of finding a way to register these endpoints in the class that creates them (for example, registering this endpoint from within the ResourcePolicyRestRespository which creates/generates this /search subpath).

That said, if this is the easiest route, I'm OK with this. We'll just need to remember to modify this class whenever a new nested link needs to be visible at the root level.

Copy link
Member

@artlowel artlowel left a comment

Choose a reason for hiding this comment

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

This approach will work for the UI. We will need some work to migrate to these endpoints, but as they're hardcoded right now, merging this PR shouldn't break anything.

I agree with @tdonohue's point about the location though. Preferably each Repository would register its own links rather than having them all in a single file

@abollini
Copy link
Member

@artlowel @tdonohue the endpoint can be registered in each Repository if liked. The reason why I have suggested to do that in a separated central class it to makes easier to understand / locate which endpoints have this special need. I would prefer to monitor these special cases, putting them in the different repository would imply a bit of code duplication (the after afterPropertiesSet, not an huge issue of course) but more relevant to me will make harder to monitor that developers not start to add addition unnecessary endpoint registration to the root. Also the testing would become a bit more expensive if distributed over different classes.

Anyway, let me know if you still want to split that over the different repositories

@tdonohue
Copy link
Member

@abollini : I'd prefer splitting this PR apart into the separate RestRepository (even though I agree there will be minor code duplication in doing so). I understand your desire to track these together, but I'm simply worried we'll forget to add to this separate class. I'm also not yet sure these are "special cases", as I'm noticing an obvious pattern here...

What I'm seeing is that (almost) anytime the findall() method in the RestRepository class returns a 405, we must ensure this afterPropertiesSet() method registers that RestRepository's public endpoints (if any). Looking at existing code, in most scenarios a 405 at the root seems to imply there's a /search subpath which is available...and since both the 405 and the /search subpath are defined in the RestRepository, it makes sense to have this afterPropertiesSet() appear there as well.

All in all, I think this will be much easier for reviewers to check future PRs if this code moves to the RestRepository class. Otherwise, I'm worried we'll accidentally recreate this same problem down the line if we forget to register public subpaths anytime we return a 405 at the root endpoint.

@Micheleboychuk
Copy link
Contributor Author

hi @tdonohue @artlowel it should be ready for a new review. Thanks

Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

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

Thanks @Micheleboychuk and @abollini ! Looks great now

@tdonohue tdonohue merged commit 3a1522c into DSpace:master Jun 4, 2020
@tdonohue tdonohue added this to the 7.0beta3 milestone Jun 23, 2020
@tdonohue tdonohue mentioned this pull request Jun 24, 2020
6 tasks
@tdonohue tdonohue added this to Needs Reviewers Assigned in DSpace 7 Beta 3 via automation Jun 30, 2020
@tdonohue tdonohue moved this from Needs Reviewers Assigned to Done in DSpace 7 Beta 3 Jun 30, 2020
@Micheleboychuk Micheleboychuk deleted the DS-4495_HAL_link branch February 22, 2022 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interface: REST API v7+ REST API for v7 and later (dspace-server-webapp module)
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants