Projet

Général

Profil

0001-sms-add-description-to-send-endpoint-45829.patch

Nicolas Roche, 11 août 2020 15:44

Télécharger (2,71 ko)

Voir les différences:

Subject: [PATCH] sms: add description to send endpoint (#45829)

 passerelle/sms/models.py                              | 11 ++++++++++-
 .../passerelle/manage/messages_service_view.html      |  4 +---
 2 files changed, 11 insertions(+), 4 deletions(-)
passerelle/sms/models.py
56 56
            elif number.startswith(self.default_trunk_prefix):
57 57
                number = '00' + self.default_country_code + number[len(self.default_trunk_prefix):]
58 58
            else:
59 59
                raise APIError('phone number %r is unsupported (no international prefix, '
60 60
                               'no local trunk prefix)' % number)
61 61
            numbers.append(number)
62 62
        return numbers
63 63

  
64
    @endpoint(perm='can_send_messages', methods=['post'])
64
    @endpoint(perm='can_send_messages', methods=['post'],
65
              description=_('Send a SMS message'),
66
              parameters={
67
                  'message': {'description': _('String message'), 'example_value': 'Hello'},
68
                  'from': {'description': _('Sender number'), 'example_value': '33699999999'},
69
                  'to': {'description': _('Destination numbers'),
70
                         'type': 'list of string',
71
                         'example_value': '["+33688888888", "+33677777777"]',
72
                  },
73
              })
65 74
    def send(self, request, *args, **kwargs):
66 75
        try:
67 76
            data = json_loads(request.body)
68 77
            assert isinstance(data, dict), 'JSON payload is not a dict'
69 78
            assert 'message' in data, 'missing "message" in JSON payload'
70 79
            assert 'from' in data, 'missing "from" in JSON payload'
71 80
            assert 'to' in data, 'missing "to" in JSON payload'
72 81
            assert isinstance(data['message'], six.text_type), 'message is not a string'
passerelle/sms/templates/passerelle/manage/messages_service_view.html
1 1
{% extends "passerelle/manage/service_view.html" %}
2 2
{% load i18n passerelle %}
3 3

  
4 4
{% block endpoints %}
5
<ul>
6
 <li>{% trans 'Sending a message:' %} <a href="send" >{{ site_base_uri }}{{ object.get_absolute_url }}send</a> (POST)</li>
7
</ul>
5
{{ block.super }}
8 6
{% endblock %}
9
-