Skip to content

Commit

Permalink
Conditionally append slashes to chosen URLs to avoid invisible redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
ababic committed Jul 29, 2024
1 parent 89be14e commit 35e4157
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class BynderChooserModalOnloadHandlerFactory {
this.assetType = opts?.assetType || null;
this.chosenMultipleUrl = opts?.chosenMultipleUrl || "/";
this.chosenSingleUrl = opts?.chosenSingleUrl || "/";
this.chosenUrlAppendSlash = window.chosenUrlappendSlash || true;
}

onLoadChooseStep(modal) {
Expand Down Expand Up @@ -49,6 +50,9 @@ class BynderChooserModalOnloadHandlerFactory {
}
else {
url = chosenSingleUrl + assets[0].databaseId;
if (chosenUrlAppendSlash) {
url += "/";
}
}
modal.loadUrl(url, params);
return false;
Expand Down
1 change: 1 addition & 0 deletions src/wagtail_bynder/templates/wagtailadmin/admin_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<script>
window.bynderAPIToken = '{% bynder_compactview_api_token %}';
window.bynderDomain = '{% bynder_domain %}';
window.chosenUrlAppendSlash = {% get_append_slash %};
window.imageChosenBaseUrl = "{% get_image_chosen_base_url %}";
window.documentChosenBaseUrl = "{% get_document_chosen_base_url %}";
window.videoChosenBaseUrl = "{% get_video_chosen_base_url %}";
Expand Down
5 changes: 5 additions & 0 deletions src/wagtail_bynder/templatetags/bynder_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ def get_video_chosen_base_url():
url += "/"
return url
return ""


@register.simple_tag
def get_append_slash():
return str(bool(settings.APPEND_SLASH)).lower()

0 comments on commit 35e4157

Please sign in to comment.