Repository: mozmeao/snippets-service

Issue:
Country required for Non-SMS S2D Snippets
Hi @glogiotatidis. 

I am updating Send to Device snippets for the F100 Snippet experience. I notice the new Snippet Admin tool requires a country code for all Send to Device snippets, even when SMS is not checked off.

Right now, when left blank, the country code defaults to `US`. And when I remove it, I get an error notice. This is even when SMS is unchecked. Perhaps this requirement needs to be conditional when SMS capabilites are checked. 
 

We have two types of send to device snippets.
- SMS and Email
-Email Only

Since we don't support SMS in all locales, we allow users to email themselves a download link. The requirement of a country code, prevents us from reaching all users and would require us to create a snippet for each country

Please see the example here: 
https://snippets-admin.mozilla.org/admin/base/asrsnippet/11428/change/?_changelist_filters=q%3D_week12_%2B_de_

SnippetID: 11428
Locale: DE

See screenshots.

![Screen Shot 2019-03-28 at 11 30 23 AM](https://user-images.githubusercontent.com/47153345/55183384-ea31b000-514c-11e9-9efa-7f8ffb7bc327.png)

![Screen Shot 2019-03-28 at 11 21 23 AM](https://user-images.githubusercontent.com/47153345/55183393-ebfb7380-514c-11e9-81d8-3358dd78b214.png)

Thank you!


Discussion:
I updated my original comment, since I forgot to add screenshots and an example. Thank you Giorgos!
Thanks Steve. This will be fixed within next week, but until then you can still just fill the field with something like `us`. If you don't check `include sms` the value of the `country` field doesn't make any difference.


Thank you, Giorgos! 
> within next week

maybe that take a bit longer, since we have a workaround. Let me know if that's an issue. thanks!
No urgency. I intended to run snippetsthat required this, but no problem. I plan to schedule them for whenever this is fixed. Thank you!
Please go ahead and schedule the snippets with the default `us` in the field. This field is only considered when the sms checkbox is checked. 
Ah, ok. That makes sense. Thank you for clarifying.
@glogiotatidis (and maybe @k88hudson?) - if we make the `country` field optional here, will the [default specified in the snippet template](https://github.com/mozilla/activity-stream/blob/master/content-src/asrouter/templates/SendToDeviceSnippet/SendToDeviceSnippet.schema.json#L27-L30) be used? or will the admin send over an empty value, thereby [overwriting the default](https://github.com/mozilla/activity-stream/blob/master/content-src/asrouter/templates/SendToDeviceSnippet/SendToDeviceSnippet.jsx#L52-L55)?

basically wondering if we'll need to add additional checks on the AS side if we make this field optional in the admin.
> @glogiotatidis (and maybe @k88hudson?) - if we make the `country` field optional here, will the [default specified in the snippet template](https://github.com/mozilla/activity-stream/blob/master/content-src/asrouter/templates/SendToDeviceSnippet/SendToDeviceSnippet.schema.json#L27-L30) be used? or will the admin send over an empty value, thereby [overwriting the default](https://github.com/mozilla/activity-stream/blob/master/content-src/asrouter/templates/SendToDeviceSnippet/SendToDeviceSnippet.jsx#L52-L55)?

Hmmm good point. Since [we don't send empty strings](https://github.com/mozmeao/snippets-service/blob/master/snippets/base/models.py#L716), after AS requesting not to do so, I believe the default in AS will be used. Maybe that's why I coded as it's now. 

That said ideally we would add more checks in AS but as first step we can data check on the snippets service
since this is largely a UI/UX issue for snippet creators, maybe i'm overthinking it. perhaps a JS/CSS solution to hide the country field unless/until "Include SMS" is checked will be better here. would have less technical impact. thoughts?

Resolving patch:
diff --git a/snippets/base/admin/adminmodels.py b/snippets/base/admin/adminmodels.py
--- a/snippets/base/admin/adminmodels.py
+++ b/snippets/base/admin/adminmodels.py
@@ -456,8 +456,8 @@ class SendToDeviceTemplateInline(admin.StackedInline):
                 'scene2_dismiss_button_text',
 
                 'locale',
-                'country',
                 ('include_sms', 'message_id_sms',),
+                'country',
                 'message_id_email',
                 'success_title',
                 'success_text',
diff --git a/snippets/base/forms.py b/snippets/base/forms.py
--- a/snippets/base/forms.py
+++ b/snippets/base/forms.py
@@ -601,6 +601,15 @@ class Meta:
         model = models.SendToDeviceTemplate
         exclude = []
 
+    class Media:
+        css = {
+            'all': ('css/admin/sms-country-toggle.css',),
+        }
+
+        js = [
+            'js/admin/sms-country-toggle.js',
+        ]
+
 
 class SimpleBelowSearchTemplateForm(forms.ModelForm):
 


Test patch: