ansible / django-ansible-base

Apache License 2.0
11 stars 43 forks source link

Adding get_relative_url and get_fully_qualified_url #505

Closed john-westcott-iv closed 1 month ago

john-westcott-iv commented 2 months ago

AAP-26819

We somewhat arbitrarily used DRF reverse along with Django reverse. The difference is that Django reverse produces a relative URL and DRF reverse looks at the request and returns a fully qualified url.

This PR adds two functions: get_fully_qualifed_url and get_relative_url to ansible_base.lib.utils.response. This PR also converts all references to both reverse methods to our new method.

The get_fully_qualified_url will look for a setting called FRONT_END_URL and use that as the protocol://server:port portion of the URL if defined. If undefined it will allow DRF to attempt to do its normal reverse.

In most places in the API we should be using relative URLs. Hover, if we need a fully qualified URL for any reason we should attempt to use get_fully_qualified_url. These functions both take a view name and *args and **kwargs similar to the existing reverse methods.

In addition to being more explicit, this will help us to have a common method and seeing for constructing fully qualified URLs.

Dostonbek1 commented 1 month ago

@john-westcott-iv not sure if I asked this before, but would this be a breaking change for services (e.g. EDA) using DAB?

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud