From f023cb21c7de8f87a4a8c4da3d4f04a48af72a6d Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Wed, 22 Jan 2020 12:53:12 +0100 Subject: [PATCH 01/11] Add managers URLs as musician settings. --- musician/settings.py | 47 +++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/musician/settings.py b/musician/settings.py index 5581061..abc538a 100644 --- a/musician/settings.py +++ b/musician/settings.py @@ -1,14 +1,37 @@ -# allowed resources limit hardcoded because cannot be retrieved from the API. -ALLOWED_RESOURCES = { - 'INDIVIDUAL': - { - # 'disk': 1024, - # 'traffic': 2048, - 'mailbox': 2, +from django.conf import settings + + +def getsetting(name): + return getattr(settings, name, DEFAULTS.get(name)) + + +DEFAULTS = { + # allowed resources limit hardcoded because cannot be retrieved from the API. + "ALLOWED_RESOURCES": { + 'INDIVIDUAL': + { + # 'disk': 1024, + # 'traffic': 2048, + 'mailbox': 2, + }, + 'ASSOCIATION': { + # 'disk': 5 * 1024, + # 'traffic': 20 * 1024, + 'mailbox': 10, + } }, - 'ASSOCIATION': { - # 'disk': 5 * 1024, - # 'traffic': 20 * 1024, - 'mailbox': 10, - } + "URL_DB_PHPMYADMIN": "https://www.phpmyadmin.net/", + "URL_MAILTRAIN": "https://mailtrain.org/", + "URL_SAAS_WORDPRESS": "https://wordpress.org/", + "URL_SAAS_GITLAB": "https://gitlab.org/", } + +ALLOWED_RESOURCES = getsetting("ALLOWED_RESOURCES") + +URL_DB_PHPMYADMIN = getsetting("URL_DB_PHPMYADMIN") + +URL_MAILTRAIN = getsetting("URL_MAILTRAIN") + +URL_SAAS_WORDPRESS = getsetting("URL_SAAS_WORDPRESS") + +URL_SAAS_GITLAB = getsetting("URL_SAAS_GITLAB") From 09c16ab2ae04d9407fec353e033cb446773399ed Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Wed, 22 Jan 2020 13:03:23 +0100 Subject: [PATCH 02/11] Set mailtrain URL. --- musician/models.py | 7 ++++--- musician/templates/musician/mailinglists.html | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/musician/models.py b/musician/models.py index aa3ebd4..44bc731 100644 --- a/musician/models.py +++ b/musician/models.py @@ -5,6 +5,8 @@ from django.utils.dateparse import parse_datetime from django.utils.html import format_html from django.utils.translation import gettext_lazy as _ +from . import settings as musician_settings + logger = logging.getLogger(__name__) @@ -249,9 +251,8 @@ class MailinglistService(OrchestraModel): return "{}@{}".format(self.data['address_name'], self.data['address_domain']['name']) @property - def configure(self): - # TODO(@slamora): build mailtran absolute URL - return format_html('Mailtrain') + def manager_url(self): + return musician_settings.URL_MAILTRAIN class SaasService(OrchestraModel): diff --git a/musician/templates/musician/mailinglists.html b/musician/templates/musician/mailinglists.html index 22a1b87..d02f4b7 100644 --- a/musician/templates/musician/mailinglists.html +++ b/musician/templates/musician/mailinglists.html @@ -37,7 +37,7 @@ {% endif %} {{ resource.address_name}} {{ resource.admin_email }} - Mailtrain + Mailtrain {% endfor %} From 4da403c4aa6f58223c629b97090829a04e511d30 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 23 Jan 2020 16:12:40 +0100 Subject: [PATCH 03/11] Add OwnCloud manager url. --- musician/settings.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/musician/settings.py b/musician/settings.py index abc538a..ca9b560 100644 --- a/musician/settings.py +++ b/musician/settings.py @@ -22,8 +22,9 @@ DEFAULTS = { }, "URL_DB_PHPMYADMIN": "https://www.phpmyadmin.net/", "URL_MAILTRAIN": "https://mailtrain.org/", - "URL_SAAS_WORDPRESS": "https://wordpress.org/", "URL_SAAS_GITLAB": "https://gitlab.org/", + "URL_SAAS_OWNCLOUD": "https://owncloud.org/", + "URL_SAAS_WORDPRESS": "https://wordpress.org/", } ALLOWED_RESOURCES = getsetting("ALLOWED_RESOURCES") @@ -32,6 +33,8 @@ URL_DB_PHPMYADMIN = getsetting("URL_DB_PHPMYADMIN") URL_MAILTRAIN = getsetting("URL_MAILTRAIN") -URL_SAAS_WORDPRESS = getsetting("URL_SAAS_WORDPRESS") - URL_SAAS_GITLAB = getsetting("URL_SAAS_GITLAB") + +URL_SAAS_OWNCLOUD = getsetting("URL_SAAS_OWNCLOUD") + +URL_SAAS_WORDPRESS = getsetting("URL_SAAS_WORDPRESS") From d05c61defff9105431c5553aa1eed74b6411e09e Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 23 Jan 2020 16:13:23 +0100 Subject: [PATCH 04/11] Include link to SaaS service manager. --- musician/models.py | 11 +++++++++++ musician/templates/musician/saas.html | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/musician/models.py b/musician/models.py index 44bc731..a0c058f 100644 --- a/musician/models.py +++ b/musician/models.py @@ -267,6 +267,17 @@ class SaasService(OrchestraModel): } + @property + def manager_url(self): + URLS = { + 'gitlab': musician_settings.URL_SAAS_GITLAB, + 'owncloud': musician_settings.URL_SAAS_OWNCLOUD, + 'wordpress': musician_settings.URL_SAAS_WORDPRESS, + } + + return URLS.get(self.service, '#none') + + class WebSite(OrchestraModel): api_name = 'website' param_defaults = { diff --git a/musician/templates/musician/saas.html b/musician/templates/musician/saas.html index cff1e83..4da034f 100644 --- a/musician/templates/musician/saas.html +++ b/musician/templates/musician/saas.html @@ -34,7 +34,7 @@ From a71654cc5cedf9e5ed5d546cf1961c9e86c397e7 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 23 Jan 2020 16:14:18 +0100 Subject: [PATCH 05/11] Fix typo on variable name. Regression by 6980522d811e2ff9ff5e0be7e12c54a0863a5ba8 --- musician/templates/musician/dashboard.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/musician/templates/musician/dashboard.html b/musician/templates/musician/dashboard.html index 7988f31..69c9239 100644 --- a/musician/templates/musician/dashboard.html +++ b/musician/templates/musician/dashboard.html @@ -66,9 +66,9 @@

{{ domain.mails|length }} {% trans "mail addresses created" %} - {% if domain.address_left.alert_level %} + {% if domain.addresses_left.alert_level %}
- {{ domain.address_left.count }} mail address left + {{ domain.addresses_left.count }} mail address left {% endif %}

From 9060bc1590f764c34afea48edc779b14b4984877 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 23 Jan 2020 16:16:21 +0100 Subject: [PATCH 06/11] Add external-link icon to Mailtrain anchor. --- musician/templates/musician/mailinglists.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musician/templates/musician/mailinglists.html b/musician/templates/musician/mailinglists.html index d02f4b7..6ff509e 100644 --- a/musician/templates/musician/mailinglists.html +++ b/musician/templates/musician/mailinglists.html @@ -37,7 +37,7 @@ {% endif %} {{ resource.address_name}} {{ resource.admin_email }} - Mailtrain + Mailtrain {% endfor %} From 672b3298a76afb3807bfd5120a52bf4d1dd371b2 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 23 Jan 2020 16:32:36 +0100 Subject: [PATCH 07/11] Allow to configure managers URLs on project settings. --- musician/settings.py | 3 ++- userpanel/settings.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/musician/settings.py b/musician/settings.py index ca9b560..7dab46f 100644 --- a/musician/settings.py +++ b/musician/settings.py @@ -2,7 +2,8 @@ from django.conf import settings def getsetting(name): - return getattr(settings, name, DEFAULTS.get(name)) + value = getattr(settings, name, None) + return value or DEFAULTS.get(name) DEFAULTS = { diff --git a/userpanel/settings.py b/userpanel/settings.py index 4d45a17..d14b228 100644 --- a/userpanel/settings.py +++ b/userpanel/settings.py @@ -147,3 +147,15 @@ STATIC_ROOT = config('STATIC_ROOT') # Backend API configuration API_BASE_URL = config('API_BASE_URL') + + +# External services URLs +URL_DB_PHPMYADMIN = config('URL_DB_PHPMYADMIN', None) + +URL_MAILTRAIN = config('URL_MAILTRAIN', None) + +URL_SAAS_GITLAB = config('URL_SAAS_GITLAB', None) + +URL_SAAS_OWNCLOUD = config('URL_SAAS_OWNCLOUD', None) + +URL_SAAS_WORDPRESS = config('URL_SAAS_WORDPRESS', None) From 24729bf6b75ffb8e3ed40d0362967759586bc0ed Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 23 Jan 2020 17:28:53 +0100 Subject: [PATCH 08/11] Configure languages and enable Locale middleware --- userpanel/settings.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/userpanel/settings.py b/userpanel/settings.py index d14b228..cb5ce35 100644 --- a/userpanel/settings.py +++ b/userpanel/settings.py @@ -13,7 +13,10 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ import os from decouple import config, Csv +from django.utils.translation import gettext_lazy as _ from dj_database_url import parse as db_url + + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -56,6 +59,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -126,7 +130,13 @@ SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies" # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = config('LANGUAGE_CODE', 'en-us') + +LANGUAGES = [ + ('ca', _('Catalan')), + ('en', _('English')), + ('es', _('Spanish')), +] TIME_ZONE = 'UTC' From 9866f00d7fdd13ea15e22612170d32a09ae33afb Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 23 Jan 2020 17:37:08 +0100 Subject: [PATCH 09/11] Set user language as active language on login. --- musician/forms.py | 1 + musician/models.py | 8 +++++++- musician/views.py | 12 +++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/musician/forms.py b/musician/forms.py index 5fcafbe..7a66a00 100644 --- a/musician/forms.py +++ b/musician/forms.py @@ -17,5 +17,6 @@ class LoginForm(AuthenticationForm): else: self.username = username self.token = orchestra.auth_token + self.user = orchestra.retrieve_profile() return self.cleaned_data diff --git a/musician/models.py b/musician/models.py index a0c058f..a9b9698 100644 --- a/musician/models.py +++ b/musician/models.py @@ -109,14 +109,20 @@ class UserAccount(OrchestraModel): @classmethod def new_from_json(cls, data, **kwargs): billing = None + language = None last_login = None if 'billcontact' in data: billing = BillingContact.new_from_json(data['billcontact']) + # Django expects that language code is lowercase + if 'language' in data: + language = data['language'].lower() + if 'last_login' in data: last_login = parse_datetime(data['last_login']) - return super().new_from_json(data=data, billing=billing, last_login=last_login) + + return super().new_from_json(data=data, billing=billing, language=language, last_login=last_login) class DatabaseUser(OrchestraModel): diff --git a/musician/views.py b/musician/views.py index e96fa24..102a66d 100644 --- a/musician/views.py +++ b/musician/views.py @@ -1,9 +1,11 @@ from itertools import groupby +from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render from django.urls import reverse_lazy +from django.utils import translation from django.utils.http import is_safe_url from django.utils.translation import gettext_lazy as _ from django.views import View @@ -305,7 +307,15 @@ class LoginView(FormView): def form_valid(self, form): """Security check complete. Log the user in.""" auth_login(self.request, form.username, form.token) - return HttpResponseRedirect(self.get_success_url()) + + # set user language as active language + user_language = form.user.language + translation.activate(user_language) + + response = HttpResponseRedirect(self.get_success_url()) + response.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_language) + + return response def get_success_url(self): url = self.get_redirect_url() From 953415f7df802881612e57e055cb6d326a7a31bb Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 23 Jan 2020 17:41:35 +0100 Subject: [PATCH 10/11] Prepare profile and billing to be translated. --- musician/templates/musician/billing.html | 12 ++++++------ musician/templates/musician/profile.html | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/musician/templates/musician/billing.html b/musician/templates/musician/billing.html index 46d1396..f181341 100644 --- a/musician/templates/musician/billing.html +++ b/musician/templates/musician/billing.html @@ -4,7 +4,7 @@ {% block content %}

{% trans "Billing" %}

-

Little description of what to be expected...

+

{% trans "Little description of what billing section is." %}

@@ -16,11 +16,11 @@ - - - - - + + + + + diff --git a/musician/templates/musician/profile.html b/musician/templates/musician/profile.html index 6a49dd6..44c57ab 100644 --- a/musician/templates/musician/profile.html +++ b/musician/templates/musician/profile.html @@ -3,12 +3,12 @@ {% block content %} -

Profile

-

Little description of what to be expected...

+

{% trans "Profile" %}

+

{% trans "Little description of what profile section is." %}

-
User information
+
{% trans "User information" %}
@@ -18,12 +18,12 @@

{{ profile.username }}

{{ profile.type }}

-

Preferred language: {{ profile.language }}

+

{% trans "Preferred language:" %} {{ profile.language|language_name_local }}

{% comment %} {% endcomment %}
@@ -31,7 +31,7 @@ {% with profile.billing as contact %}
-
Billing information
+
{% trans "Billing information" %}
{{ contact.name }}
{{ contact.address }}
@@ -45,7 +45,7 @@
- payment method: {{ payment.method }} + {% trans "payment method:" %} {{ payment.method }}
{% if payment.method == 'SEPADirectDebit' %} From 6b0d37f854a4dbeaf5de62cbc68a946862a3e3df Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 23 Jan 2020 17:44:25 +0100 Subject: [PATCH 11/11] Fix sidebar position (avoid scrolling). Related to 3890fec1113077ad89536ac9586c453c362a9eb5 --- musician/static/musician/css/default.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/musician/static/musician/css/default.css b/musician/static/musician/css/default.css index a95a573..3fbe7da 100644 --- a/musician/static/musician/css/default.css +++ b/musician/static/musician/css/default.css @@ -43,6 +43,9 @@ a:hover { min-width: 280px; max-width: 280px; min-height: 100vh; + + position: fixed; + z-index: 999; display: flex; flex-direction: column; @@ -127,6 +130,7 @@ a:hover { background-position: right 5% top 10%; color: #343434; padding-left: 2rem; + margin-left: 280px; /** sidebar width **/ } /** services **/
NumberBill dateTypeTotalDownload PDF{% trans "Number" %}{% trans "Bill date" %}{% trans "Type" %}{% trans "Total" %}{% trans "Download PDF" %}