Skip to content

Commit

Permalink
Rename to use credentials file
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Jul 24, 2024
1 parent ef8ff52 commit 39bf0e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions temba/channels/types/firebase/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setUp(self):
address="87654",
role="SR",
schemes=["fcm"],
config={"FCM_TITLE": "Title", "FCM_AUTH_JSON": {"foo": "bar", "project_id": "87654"}},
config={"FCM_TITLE": "Title", "FCM_CREDENTIALS_JSON": {"foo": "bar", "project_id": "87654"}},
)

@patch("requests.get")
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_claim(self, mock_get):
self.assertEqual(
channel.config,
{
"FCM_AUTH_JSON": {"foo": "bar", "baz": "abc", "project_id": "abcde12345"},
"FCM_CREDENTIALS_JSON": {"foo": "bar", "baz": "abc", "project_id": "abcde12345"},
"FCM_TITLE": "FCM Channel",
"FCM_NOTIFICATION": True,
},
Expand Down
11 changes: 2 additions & 9 deletions temba/channels/types/firebase/views.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import json

from smartmin.views import SmartFormView

from django import forms
from django.utils.translation import gettext_lazy as _

from temba.utils.fields import InputWidget
from temba.utils.fields import InputWidget, PrettyJSONEncoder

from ...models import Channel
from ...views import ClaimViewMixin


class PrettyJSONEncoder(json.JSONEncoder):
def __init__(self, *args, indent, sort_keys, **kwargs):
super().__init__(*args, indent=4, sort_keys=False, **kwargs)


class ClaimView(ClaimViewMixin, SmartFormView):
class Form(ClaimViewMixin.Form):
title = forms.CharField(label=_("Notification Title"))
Expand Down Expand Up @@ -43,7 +36,7 @@ def form_valid(self, form):
title = form.cleaned_data.get("title")
authentication_json = form.cleaned_data.get("authentication_json")
address = form.cleaned_data.get("address")
config = {"FCM_TITLE": title, "FCM_AUTH_JSON": authentication_json}
config = {"FCM_TITLE": title, "FCM_CREDENTIALS_JSON": authentication_json}

if form.cleaned_data.get("send_notification") == "True":
config["FCM_NOTIFICATION"] = True
Expand Down
5 changes: 5 additions & 0 deletions temba/utils/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,8 @@ def prepare_value(self, value):

def valid_value(self, value):
return True


class PrettyJSONEncoder(json.JSONEncoder): # pragma: needs cover
def __init__(self, *args, indent, sort_keys, **kwargs):
super().__init__(*args, indent=4, sort_keys=False, **kwargs)

0 comments on commit 39bf0e2

Please sign in to comment.