Skip to content

Commit

Permalink
Merge pull request #5647 from nyaruka/more-headers
Browse files Browse the repository at this point in the history
Fix issues with inconsistent header names
  • Loading branch information
rowanseymour authored Nov 11, 2024
2 parents 8f066da + d310e62 commit 856da72
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@nyaruka/flow-editor": "1.36.0",
"@nyaruka/temba-components": "0.111.4",
"@nyaruka/temba-components": "0.111.5",
"codemirror": "5.18.2",
"colorette": "1.2.2",
"fa-icons": "0.2.0",
Expand Down
4 changes: 4 additions & 0 deletions static/css/frame.css
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,7 @@ temba-menu.servicing {
background: var(--color-widget-bg-focused);
box-shadow: var(--widget-box-shadow-focused);
}

#error-dialog {
display: none;
}
4 changes: 2 additions & 2 deletions static/js/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function fetchAjax(url, options) {
addToHistory(url);
}

const toasts = response.headers.get('x-temba-toasts');
const toasts = response.headers.get('X-Temba-Toasts');
if (toasts) {
const toastEle = document.querySelector('temba-toast');
if (toastEle) {
Expand Down Expand Up @@ -337,7 +337,7 @@ function fetchAjax(url, options) {
// special case for spa content, break out into a full page load
if (
container === '.spa-content' &&
response.headers.get('x-temba-content-only') != 1
response.headers.get('X-Temba-Content-Only') != 1
) {
document.location.href = response.url;
return;
Expand Down
1 change: 1 addition & 0 deletions static/js/temba.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function showLightbox(evt, url) {

function showErrorDialog() {
var dialog = document.querySelector('#error-dialog');
dialog.style = 'display:block';
dialog.width = 'initial';
dialog.buttons = [{ type: 'secondary', name: 'Ok', closes: true }];
dialog.open = true;
Expand Down
2 changes: 1 addition & 1 deletion temba/channels/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ def test_delete(self):
response = self.assertDeleteSubmit(
delete_url, self.admin, object_deactivated=self.ex_channel, success_status=200
)
self.assertEqual("/org/workspace/", response["Temba-Success"])
self.assertEqual("/org/workspace/", response["X-Temba-Success"])

# reactivate
self.ex_channel.is_active = True
Expand Down
4 changes: 2 additions & 2 deletions temba/channels/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def post(self, request, *args, **kwargs):
)

response = HttpResponse()
response["Temba-Success"] = self.cancel_url
response["X-Temba-Success"] = self.cancel_url
return response

# override success message for Twilio channels
Expand All @@ -730,7 +730,7 @@ def post(self, request, *args, **kwargs):
messages.info(request, self.success_message)

response = HttpResponse()
response["Temba-Success"] = self.get_success_url()
response["X-Temba-Success"] = self.get_success_url()
return response

class Update(ComponentFormMixin, ModalFormMixin, OrgObjPermsMixin, SmartUpdateView):
Expand Down
4 changes: 2 additions & 2 deletions temba/classifiers/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_delete(self):
self.assertContains(response, "You are about to delete")

response = self.assertDeleteSubmit(delete_url, self.admin, object_deactivated=self.c2, success_status=200)
self.assertEqual("/org/workspace/", response["Temba-Success"])
self.assertEqual("/org/workspace/", response["X-Temba-Success"])

# should see warning if global is being used
delete_url = reverse("classifiers.classifier_delete", args=[self.c1.uuid])
Expand All @@ -176,7 +176,7 @@ def test_delete(self):
self.assertContains(response, "Color Flow")

response = self.assertDeleteSubmit(delete_url, self.admin, object_deactivated=self.c1, success_status=200)
self.assertEqual("/org/workspace/", response["Temba-Success"])
self.assertEqual("/org/workspace/", response["X-Temba-Success"])

self.flow.refresh_from_db()
self.assertTrue(self.flow.has_issues)
Expand Down
4 changes: 2 additions & 2 deletions temba/flows/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3179,7 +3179,7 @@ def test_export_and_download_translation(self):
# submit with no language
response = self.assertUpdateSubmit(export_url, self.admin, {}, success_status=200)

download_url = response["Temba-Success"]
download_url = response["X-Temba-Success"]
self.assertEqual(f"/flow/download_translation/?flow={flow.id}&language=", download_url)

# check fetching the PO from the download link
Expand All @@ -3195,7 +3195,7 @@ def test_export_and_download_translation(self):
# submit with a language
response = self.assertUpdateSubmit(export_url, self.admin, {"language": "spa"}, success_status=200)

download_url = response["Temba-Success"]
download_url = response["X-Temba-Success"]
self.assertEqual(f"/flow/download_translation/?flow={flow.id}&language=spa", download_url)

# check fetching the PO from the download link
Expand Down
4 changes: 2 additions & 2 deletions temba/globals/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_delete(self):
self.assertContains(response, "You are about to delete")

response = self.assertDeleteSubmit(delete_url, self.admin, object_deactivated=self.global2, success_status=200)
self.assertEqual("/global/", response["Temba-Success"])
self.assertEqual("/global/", response["X-Temba-Success"])

# should see warning if global is being used
delete_url = reverse("globals.global_delete", args=[self.global1.uuid])
Expand All @@ -216,7 +216,7 @@ def test_delete(self):
self.assertContains(response, "Color Flow")

response = self.assertDeleteSubmit(delete_url, self.admin, object_deactivated=self.global1, success_status=200)
self.assertEqual("/global/", response["Temba-Success"])
self.assertEqual("/global/", response["X-Temba-Success"])

self.flow.refresh_from_db()
self.assertTrue(self.flow.has_issues)
Expand Down
4 changes: 2 additions & 2 deletions temba/msgs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2572,7 +2572,7 @@ def test_scheduled_delete(self):

# submit the delete modal
response = self.assertDeleteSubmit(delete_url, self.admin, object_deactivated=broadcast, success_status=200)
self.assertEqual("/broadcast/scheduled/", response["Temba-Success"])
self.assertEqual("/broadcast/scheduled/", response["X-Temba-Success"])

broadcast.refresh_from_db()

Expand Down Expand Up @@ -2806,7 +2806,7 @@ def test_delete(self):

# submit to delete it
response = self.assertDeleteSubmit(delete_url, self.admin, object_deactivated=label, success_status=200)
self.assertEqual("/msg/", response["Temba-Success"])
self.assertEqual("/msg/", response["X-Temba-Success"])

# reactivate
label.is_active = True
Expand Down
2 changes: 1 addition & 1 deletion temba/msgs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def post(self, request, *args, **kwargs):
self.get_object().delete(self.request.user, soft=True)

response = HttpResponse()
response["Temba-Success"] = self.get_success_url()
response["X-Temba-Success"] = self.get_success_url()
return response

class Preview(OrgPermsMixin, SmartCreateView):
Expand Down
2 changes: 1 addition & 1 deletion temba/orgs/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,5 +367,5 @@ def post(self, request, *args, **kwargs):

messages.info(request, self.derive_success_message())
response = HttpResponse()
response["Temba-Success"] = self.get_success_url()
response["X-Temba-Success"] = self.get_success_url()
return response
2 changes: 1 addition & 1 deletion temba/orgs/views/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ def test_delete(self):

# go through with it, redirects to workspaces list page
response = self.client.post(delete_url)
self.assertEqual(reverse("orgs.org_list"), response["Temba-Success"])
self.assertEqual(reverse("orgs.org_list"), response["X-Temba-Success"])

child.refresh_from_db()
self.assertFalse(child.is_active)
Expand Down
2 changes: 1 addition & 1 deletion temba/orgs/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ def form_valid(self, form):
)
)

response["Temba-Success"] = success_url
response["X-Temba-Success"] = success_url
return response

class Start(SmartTemplateView):
Expand Down
2 changes: 1 addition & 1 deletion temba/staff/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def test_delete(self, mr_mocks):
self.assertContains(response, "Nyaruka")

response = self.requestView(delete_url, self.customer_support, post_data={})
self.assertEqual(reverse("staff.user_list"), response["Temba-Success"])
self.assertEqual(reverse("staff.user_list"), response["X-Temba-Success"])

self.editor.refresh_from_db()
self.assertFalse(self.editor.is_active)
Expand Down
4 changes: 2 additions & 2 deletions temba/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class Meta:
fields = ("name", "features", "is_anon")

form_class = Form
success_url = "hide"
success_url = "id@staff.org_read"

def derive_title(self):
return None
Expand Down Expand Up @@ -337,7 +337,7 @@ def post(self, request, *args, **kwargs):

messages.info(request, self.derive_success_message())
response = HttpResponse()
response["Temba-Success"] = reverse("staff.user_list")
response["X-Temba-Success"] = reverse("staff.user_list")
return response

class List(StaffOnlyMixin, SpaMixin, SmartListView):
Expand Down
4 changes: 2 additions & 2 deletions temba/utils/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def render_modal_response(self, form=None):
)
)

response["Temba-Success"] = success_url
response["X-Temba-Success"] = success_url
return response

def form_valid(self, form):
Expand All @@ -264,7 +264,7 @@ def form_valid(self, form):

messages.success(self.request, self.derive_success_message())

if "HTTP_X_TEBMA_PJAX" not in self.request.META:
if "HTTP_X_PJAX" not in self.request.META:
return HttpResponseRedirect(self.get_success_url())
else: # pragma: no cover
return self.render_modal_response(form)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@
serialize-javascript "^6.0.2"
tiny-lru "^11.2.5"

"@nyaruka/temba-components@0.111.4":
version "0.111.4"
resolved "https://registry.yarnpkg.com/@nyaruka/temba-components/-/temba-components-0.111.4.tgz#e26df69ca56356d63f12e08660d2228ef90d0333"
integrity sha512-vERkH+PQxDN+CoCGZkSua7/u9hTLWgBdOyciEjAFpx54R/VdNjwHc+OnVAifVqqeq8b2KpjkuChEzCwc4AqWmA==
"@nyaruka/temba-components@0.111.5":
version "0.111.5"
resolved "https://registry.yarnpkg.com/@nyaruka/temba-components/-/temba-components-0.111.5.tgz#eb9f426dcc829aaa3899d13a04a7a636481e53dd"
integrity sha512-suiCzQoZfWy9vjVRzDAjf5mCoEDYbwXozRvcIac07zeteorBFOhOQheWAlYYEnoWOK1mmw9kUQGirZ7xIk0qoA==
dependencies:
"@lit/localize" "^0.12.1"
color-hash "^2.0.2"
Expand Down

0 comments on commit 856da72

Please sign in to comment.