forked from educates/educates-training-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport fix related to merging of redirection URL query string param…
…eters.
- Loading branch information
1 parent
0f012f2
commit c48b04f
Showing
5 changed files
with
138 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Version 2.7.4 | ||
============= | ||
|
||
Upcoming Changes | ||
---------------- | ||
|
||
For details on significant changes in future versions, including feature | ||
deprecations and removals which may necessitate updates to existing workshops, | ||
see [Upcoming changes](upcoming-changes). | ||
|
||
Backported Changes | ||
------------------ | ||
|
||
* When an index URL was supplied to the training portal in the `TrainingPortal` | ||
resource, or via the REST API, if the URL had query string parameters, the | ||
query string param added by the training platform with the notification | ||
message, was not being merged with the existing set of query string parameters | ||
and was instead being added to the value of the last query string parameter in | ||
the URL. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
training-portal/src/project/apps/workshops/views/helpers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Helper functions for dealing with URLs.""" | ||
|
||
from urllib.parse import urlparse, parse_qs, urlencode, urlunparse, urljoin | ||
|
||
|
||
def update_query_params(url, params): | ||
"""Update the query parameters of a URL with the given parameters. If the URL | ||
is malformed or cannot be parsed, the original URL is returned.""" | ||
|
||
try: | ||
# Parse the URL. | ||
|
||
parsed_url = urlparse(url) | ||
|
||
# Handle URLs with no scheme or netloc (e.g., paths like '/page'). | ||
|
||
if not parsed_url.scheme and not parsed_url.netloc: | ||
# Treat it as a relative path URL. | ||
|
||
base_url = "http://dummy" # Temporary base for relative path handling | ||
parsed_url = urlparse(urljoin(base_url, url)) | ||
|
||
# Parse existing query parameters. | ||
|
||
query_params = parse_qs(parsed_url.query) | ||
|
||
# Update or add the new parameters. | ||
|
||
query_params.update({key: [value] for key, value in params.items()}) | ||
|
||
# Reconstruct the URL with the updated query string. | ||
|
||
updated_query = urlencode(query_params, doseq=True) | ||
updated_url = urlunparse(parsed_url._replace(query=updated_query)) | ||
|
||
# If the URL was originally a path, strip out the dummy scheme and netloc. | ||
|
||
if parsed_url.scheme == "http" and parsed_url.netloc == "dummy": | ||
return updated_url.replace("http://dummy", "") | ||
|
||
return updated_url | ||
|
||
except Exception: # pylint: disable=broad-except | ||
# In case of any parsing errors, return the original URL. | ||
|
||
return url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters