misc: add sms configuration (#46444)
This commit is contained in:
parent
e311e2611a
commit
538963b8ba
|
@ -7,6 +7,7 @@ recursive-include hobo/seo/templates *.html *.txt
|
|||
recursive-include hobo/theme/templates *.html *.txt
|
||||
recursive-include hobo/environment/templates *.html *.txt
|
||||
recursive-include hobo/emails/templates *.html *.txt
|
||||
recursive-include hobo/sms/templates *.html *.txt
|
||||
recursive-include hobo/matomo/templates *.html
|
||||
recursive-include hobo/locale *.po *.mo
|
||||
recursive-include hobo/environment/locale *.po *.mo
|
||||
|
|
|
@ -52,6 +52,8 @@ AUTO_VARIABLES = (
|
|||
'robots_txt',
|
||||
'meta_description',
|
||||
'meta_keywords',
|
||||
'sms_url',
|
||||
'sms_sender',
|
||||
)
|
||||
|
||||
class Variable(models.Model):
|
||||
|
|
|
@ -191,6 +191,8 @@ class TemplateVars(FileBaseSettingsLoader):
|
|||
tenant_settings.DEFAULT_FROM_EMAIL = variables['default_from_email']
|
||||
|
||||
tenant_settings.USER_PROFILE_CONFIG = hobo_json.get('profile')
|
||||
tenant_settings.SMS_URL = variables.get('sms_url', '')
|
||||
tenant_settings.SMS_SENDER = variables.get('sms_sender', '')
|
||||
|
||||
|
||||
class SettingsVars(SettingsDictUpdateMixin, FileBaseSettingsLoader):
|
||||
|
|
|
@ -50,6 +50,7 @@ INSTALLED_APPS = (
|
|||
'hobo.theme',
|
||||
'hobo.emails',
|
||||
'hobo.deploy',
|
||||
'hobo.sms',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# hobo - portal to configure and deploy applications
|
||||
# Copyright (C) 2015-2020 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from django import forms
|
||||
from django.core.validators import RegexValidator
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class SMSForm(forms.Form):
|
||||
sms_url = forms.URLField(label=_('SMS URL'), help_text=_('URL that can receive POST data to send SMS.'))
|
||||
sms_sender = forms.CharField(
|
||||
label=_('Sender'),
|
||||
max_length=11,
|
||||
validators=[RegexValidator('^[A-Za-z0-9 ]{0,11}$', _('Only alphanumeric characters and spaces are allowed.'))],
|
||||
help_text=_('Sender name or phone number. It must neither exceed 11 characters nor contain special characters.')
|
||||
)
|
|
@ -0,0 +1,24 @@
|
|||
{% extends "hobo/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{{ block.super }}
|
||||
<a href="{% url 'sms-home' %}">{% trans 'SMS' %}</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>{% trans 'SMS' %}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form action="." method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<div class="buttons">
|
||||
<button>{% trans "Submit" %}</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
# hobo - portal to configure and deploy applications
|
||||
# Copyright (C) 2015-2020 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.home, name='sms-home'),
|
||||
]
|
|
@ -0,0 +1,31 @@
|
|||
# hobo - portal to configure and deploy applications
|
||||
# Copyright (C) 2015-2020 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from hobo.environment.forms import VariablesFormMixin
|
||||
from .forms import SMSForm
|
||||
|
||||
|
||||
class HomeView(VariablesFormMixin, TemplateView):
|
||||
template_name = 'hobo/sms_home.html'
|
||||
variables = ['sms_url', 'sms_sender']
|
||||
form_class = SMSForm
|
||||
success_message = _('SMS settings have been updated. It will take a few seconds to be effective.')
|
||||
|
||||
home = HomeView.as_view()
|
|
@ -11,6 +11,7 @@
|
|||
{% endif %}
|
||||
<li><a href="{% url 'theme-home' %}">{% trans 'Theme' %}</a></li>
|
||||
<li><a href="{% url 'emails-home' %}">{% trans 'Emails' %}</a></li>
|
||||
<li><a href="{% url 'sms-home' %}">{% trans 'SMS' %}</a></li>
|
||||
{% if has_authentic %}
|
||||
<li><a href="{% url 'franceconnect-home' %}">FranceConnect</a></li>
|
||||
{% endif %}
|
||||
|
|
|
@ -29,6 +29,7 @@ from .theme.urls import urlpatterns as theme_urls
|
|||
from .emails.urls import urlpatterns as emails_urls
|
||||
from .debug.urls import urlpatterns as debug_urls
|
||||
from .seo.urls import urlpatterns as seo_urls
|
||||
from .sms.urls import urlpatterns as sms_urls
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
|
@ -41,6 +42,7 @@ urlpatterns = [
|
|||
url(r'^theme/', decorated_includes(admin_required, include(theme_urls))),
|
||||
url(r'^emails/', decorated_includes(admin_required, include(emails_urls))),
|
||||
url(r'^seo/', decorated_includes(admin_required, include(seo_urls))),
|
||||
url(r'^sms/', decorated_includes(admin_required, include(sms_urls))),
|
||||
url(r'^debug/', decorated_includes(admin_required, include(debug_urls))),
|
||||
url(r'^api/health/$', health_json, name='health-json'),
|
||||
url(r'^menu.json$', menu_json, name='menu_json'),
|
||||
|
|
|
@ -130,3 +130,16 @@ def test_email_update_settings_from_path(tmpdir):
|
|||
tenant_settings.DEFAULT_FROM_EMAIL = '<webmaster@hobo.example.org>'
|
||||
update_settings({'services': [], 'variables': {'global_title': 'Publik'}})
|
||||
assert tenant_settings.DEFAULT_FROM_EMAIL == '<webmaster@hobo.example.org>'
|
||||
|
||||
|
||||
def test_sms_update_settings_from_path(tmpdir):
|
||||
tenant_settings = UserSettingsHolder({})
|
||||
loader = TemplateVars()
|
||||
|
||||
variables = {'sms_url': 'https://example.com/send/', 'sms_sender': 'Sender'}
|
||||
env = {'services': [], 'variables': variables}
|
||||
path = os.path.join(str(tmpdir), 'hobo.json')
|
||||
json.dump(env, open(path, 'w'))
|
||||
loader.update_settings_from_path(tenant_settings, path)
|
||||
assert tenant_settings.SMS_URL == 'https://example.com/send/'
|
||||
assert tenant_settings.SMS_SENDER == 'Sender'
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
from hobo.environment.models import Variable
|
||||
|
||||
from test_manager import login
|
||||
|
||||
|
||||
def test_sms_view(app, admin_user):
|
||||
app = login(app)
|
||||
resp = app.get('/')
|
||||
resp = resp.click('SMS')
|
||||
resp.form['sms_url'] = 'https://example.com/send/'
|
||||
resp.form['sms_sender'] = 'Sender Name'
|
||||
resp = resp.form.submit().follow()
|
||||
|
||||
assert Variable.objects.filter(name='sms_url')[0].value == 'https://example.com/send/'
|
||||
assert Variable.objects.filter(name='sms_sender')[0].value == 'Sender Name'
|
||||
|
||||
resp.form['sms_sender'] = 'Entr\'ouvert'
|
||||
resp = resp.form.submit()
|
||||
assert 'Only alphanumeric' in resp.text
|
Loading…
Reference in New Issue