From 34faf13dc6488acf84d18e18e135cfe1c98118dd Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 14 Jan 2020 13:10:16 +0100 Subject: [PATCH 01/16] Hide database.domain until is provided by orchestra --- musician/templates/musician/databases.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/musician/templates/musician/databases.html b/musician/templates/musician/databases.html index 33403bc..f660026 100644 --- a/musician/templates/musician/databases.html +++ b/musician/templates/musician/databases.html @@ -17,7 +17,9 @@ {% trans "Type" %}: {{ database.type }}
+ {% comment "@slamora: orchestra doesn't provide this information [won't fix] See issue #3" %} {% trans "associated to" %}: {{ database.domain|default:"-" }} + {% endcomment %}
From 160e0b059f141d48f85f6af915aabf401a06d55b Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 14 Jan 2020 13:50:17 +0100 Subject: [PATCH 02/16] Bugfix: handle users that has never logged into Regression introduced by 669600f4da2b46645064a0a5cb50aa93680096b6 --- musician/models.py | 1 + musician/templates/musician/dashboard.html | 4 ++++ musician/tests.py | 25 ++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/musician/models.py b/musician/models.py index 2f43e28..683d7aa 100644 --- a/musician/models.py +++ b/musician/models.py @@ -107,6 +107,7 @@ class UserAccount(OrchestraModel): @classmethod def new_from_json(cls, data, **kwargs): billing = None + last_login = None if 'billcontact' in data: billing = BillingContact.new_from_json(data['billcontact']) diff --git a/musician/templates/musician/dashboard.html b/musician/templates/musician/dashboard.html index 375fbe3..90c8811 100644 --- a/musician/templates/musician/dashboard.html +++ b/musician/templates/musician/dashboard.html @@ -4,7 +4,11 @@ {% block content %}

{% trans "Welcome back" %} {{ profile.username }}

+{% if profile.last_login %}

{% blocktrans with last_login=profile.last_login|date:"SHORT_DATE_FORMAT" %}Last time you logged in was: {{ last_login }}{% endblocktrans %}

+{% else %} +

{% trans "It's the first time you log into the system, welcome on board!" %}

+{% endif %}
{% for resource, usage in resource_usage.items %} diff --git a/musician/tests.py b/musician/tests.py index b25e23a..805ff05 100644 --- a/musician/tests.py +++ b/musician/tests.py @@ -1,5 +1,7 @@ from django.test import TestCase +from .models import UserAccount + class DomainsTestCase(TestCase): def test_domain_not_found(self): @@ -12,3 +14,26 @@ class DomainsTestCase(TestCase): response = self.client.get('/domains/3/') self.assertEqual(404, response.status_code) + + +class UserAccountTest(TestCase): + def test_user_never_logged(self): + data = { + 'billcontact': {'address': 'foo', + 'city': 'Barcelona', + 'country': 'ES', + 'name': '', + 'vat': '12345678Z', + 'zipcode': '08080'}, + 'date_joined': '2020-01-14T12:38:31.684495Z', + 'full_name': 'Pep', + 'id': 2, + 'is_active': True, + 'language': 'EN', + 'short_name': '', + 'type': 'INDIVIDUAL', + 'url': 'http://example.org/api/accounts/2/', + 'username': 'pepe' + } + account = UserAccount.new_from_json(data) + self.assertIsNone(account.last_login) From 90ad13e61a0ec688b3b87888d78f1733729b7438 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 20 Jan 2020 10:15:27 +0100 Subject: [PATCH 03/16] Define WebSite orchestra resource. --- musician/models.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/musician/models.py b/musician/models.py index 683d7aa..58d5d0c 100644 --- a/musician/models.py +++ b/musician/models.py @@ -263,3 +263,23 @@ class SaasService(OrchestraModel): 'is_active': True, 'data': {}, } + + +class WebSite(OrchestraModel): + api_name = 'website' + param_defaults = { + "id": None, + "name": None, + "protocol": None, + "is_active": True, + "domains": [], + "contents": [], + } + + @classmethod + def new_from_json(cls, data, **kwargs): + domains = cls.param_defaults.get("domains") + if 'domains' in data: + domains = [Domain.new_from_json(domain_data) for domain_data in data['domains']] + + return super().new_from_json(data=data, domains=domains) From 6980522d811e2ff9ff5e0be7e12c54a0863a5ba8 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 20 Jan 2020 10:20:26 +0100 Subject: [PATCH 04/16] Make more descriptive variable names. --- musician/templates/musician/dashboard.html | 4 ++-- musician/views.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/musician/templates/musician/dashboard.html b/musician/templates/musician/dashboard.html index 90c8811..c6de4e3 100644 --- a/musician/templates/musician/dashboard.html +++ b/musician/templates/musician/dashboard.html @@ -62,9 +62,9 @@

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

diff --git a/musician/views.py b/musician/views.py index bbff6a0..e96fa24 100644 --- a/musician/views.py +++ b/musician/views.py @@ -66,16 +66,16 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): # TODO(@slamora): validate concept of limits with Pangea profile_type = context['profile'].type for domain in domains: - address_left = ALLOWED_RESOURCES[profile_type]['mailbox'] - len(domain.mails) - alert = None - if address_left == 1: - alert = 'warning' - elif address_left < 1: - alert = 'danger' + addresses_left = ALLOWED_RESOURCES[profile_type]['mailbox'] - len(domain.mails) + alert_level = None + if addresses_left == 1: + alert_level = 'warning' + elif addresses_left < 1: + alert_level = 'danger' - domain.address_left = { - 'count': address_left, - 'alert': alert, + domain.addresses_left = { + 'count': addresses_left, + 'alert_level': alert_level, } context.update({ From 81fa9b57fde5ccab427816475540d91049337d5b Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 20 Jan 2020 10:45:18 +0100 Subject: [PATCH 05/16] Retrieve websites associated to a domain --- musician/api.py | 22 +++++++++++++++++++++- musician/models.py | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/musician/api.py b/musician/api.py index 8b4139c..bbf77a5 100644 --- a/musician/api.py +++ b/musician/api.py @@ -6,7 +6,7 @@ from django.http import Http404 from django.urls.exceptions import NoReverseMatch from django.utils.translation import gettext_lazy as _ -from .models import Domain, DatabaseService, MailService, SaasService, UserAccount +from .models import Domain, DatabaseService, MailService, SaasService, UserAccount, WebSite DOMAINS_PATH = 'domains/' @@ -25,6 +25,7 @@ API_PATHS = { 'mailbox-list': 'mailboxes/', 'mailinglist-list': 'lists/', 'saas-list': 'saas/', + 'website-list': 'websites/', # other 'bill-list': 'bills/', @@ -118,6 +119,8 @@ class Orchestra(object): def retrieve_domain_list(self): output = self.retrieve_service_list(Domain.api_name) + websites = self.retrieve_website_list() + domains = [] for domain_json in output: # filter querystring @@ -126,6 +129,10 @@ class Orchestra(object): # retrieve services associated to a domain domain_json['mails'] = self.retrieve_service_list( MailService.api_name, querystring) + + # retrieve websites (as they cannot be filtered by domain on the API we should do it here) + domain_json['websites'] = self.filter_websites_by_domain(websites, domain_json['id']) + # TODO(@slamora): databases and sass are not related to a domain, so cannot be filtered # domain_json['databases'] = self.retrieve_service_list(DatabaseService.api_name, querystring) # domain_json['saas'] = self.retrieve_service_list(SaasService.api_name, querystring) @@ -143,6 +150,19 @@ class Orchestra(object): return domains + def retrieve_website_list(self): + output = self.retrieve_service_list(WebSite.api_name) + return [WebSite.new_from_json(website_data) for website_data in output] + + def filter_websites_by_domain(self, websites, domain_id): + matching = [] + for website in websites: + web_domains = [web_domain.id for web_domain in website.domains] + if domain_id in web_domains: + matching.append(website) + + return matching + def verify_credentials(self): """ Returns: diff --git a/musician/models.py b/musician/models.py index 58d5d0c..aa3ebd4 100644 --- a/musician/models.py +++ b/musician/models.py @@ -162,6 +162,7 @@ class Domain(OrchestraModel): "records": [], "mails": [], "usage": {}, + "websites": [], } @classmethod From b277b9a2e4e0da9a04418806a0b410ba6b35747d Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 20 Jan 2020 17:27:11 +0100 Subject: [PATCH 06/16] Show website information related to each domain. --- musician/templates/musician/dashboard.html | 44 ++++++++++++++++------ 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/musician/templates/musician/dashboard.html b/musician/templates/musician/dashboard.html index c6de4e3..55fd5b5 100644 --- a/musician/templates/musician/dashboard.html +++ b/musician/templates/musician/dashboard.html @@ -43,11 +43,15 @@ {{ domain.name }}
+ {% with domain.websites.0 as website %} + {% with website.contents.0 as content %} + {% endwith %} + {% endwith %}
{% comment "@slamora: orchestra doesn't have this information [won't fix] See issue #2" %} @@ -117,13 +121,22 @@
+
From 442c2a3d19297b4ed36eb3375001b0f78f063460 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 20 Jan 2020 17:59:49 +0100 Subject: [PATCH 08/16] Code template when no database exists. --- musician/templates/musician/databases.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/musician/templates/musician/databases.html b/musician/templates/musician/databases.html index f660026..95e1c34 100644 --- a/musician/templates/musician/databases.html +++ b/musician/templates/musician/databases.html @@ -48,7 +48,21 @@ - {% endfor %} +{% empty %} +
+
+
+
+

+ {# Translators: database page when there isn't any database. #} +
{% trans "Ooops! Looks like there is nothing here!" %}
+
+
+
+
+{% endfor %} + {% if object_list|length > 0 %} {% include "musician/components/paginator.html" %} + {% endif %} {% endblock %} From 5495808d9c7f0d8f7a715796ef7d81e328e99e81 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 20 Jan 2020 18:17:37 +0100 Subject: [PATCH 09/16] Set sidebar paddings. --- musician/static/musician/css/default.css | 18 ++++++++++++++++-- musician/templates/musician/base.html | 24 +++++++++++------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/musician/static/musician/css/default.css b/musician/static/musician/css/default.css index ecb1ff2..6d9efee 100644 --- a/musician/static/musician/css/default.css +++ b/musician/static/musician/css/default.css @@ -40,8 +40,8 @@ a:hover { } #sidebar { - min-width: 250px; - max-width: 250px; + min-width: 280px; + max-width: 280px; min-height: 100vh; } @@ -49,6 +49,19 @@ a:hover { margin-left: -250px; } +#sidebar .sidebar-branding { + padding-left: 2rem; + padding-right: 2rem; +} +#sidebar #sidebar-services { + padding-left: 1rem; + padding-right: 1rem; +} + +#sidebar #user-profile-menu { + background: rgba(255, 255, 255, 0.3); +} + #sidebar ul.components { padding: 20px 0; } @@ -107,6 +120,7 @@ a:hover { background: #ECECEB no-repeat url("../images/logo-pangea-light-gray-bg.svg"); background-position: right 5% top 10%; color: #343434; + padding-left: 2rem; } /** services **/ diff --git a/musician/templates/musician/base.html b/musician/templates/musician/base.html index 42158a5..8a531e3 100644 --- a/musician/templates/musician/base.html +++ b/musician/templates/musician/base.html @@ -34,14 +34,15 @@
- - - + {% endblock sidebar %} From d43b849d491aebd161196a817b5ff720cb93e7d4 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 20 Jan 2020 18:19:55 +0100 Subject: [PATCH 10/16] Code template when no saas exists. --- musician/templates/musician/saas.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/musician/templates/musician/saas.html b/musician/templates/musician/saas.html index eaad20a..2dc932a 100644 --- a/musician/templates/musician/saas.html +++ b/musician/templates/musician/saas.html @@ -38,6 +38,18 @@ + {% empty %} +
+
+
+
+

+ {# Translators: saas page when there isn't any saas. #} +
{% trans "Ooops! Looks like there is nothing here!" %}
+
+
+
+
{% endfor %} {% endblock %} From 36b0033b11c3074f50b71b711686226b04d893a4 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 20 Jan 2020 18:33:33 +0100 Subject: [PATCH 11/16] Move version to top & fix services_menu list. --- musician/templates/musician/base.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/musician/templates/musician/base.html b/musician/templates/musician/base.html index 8a531e3..dbd0ee0 100644 --- a/musician/templates/musician/base.html +++ b/musician/templates/musician/base.html @@ -38,19 +38,19 @@ Pangea.org - Internet etic i solidari - {{ version }} + {# #} - {% for item in services_menu %} - {% endfor %} {# #} +
+ Panel Version {{ version }} +
{% endblock sidebar %}
From 3890fec1113077ad89536ac9586c453c362a9eb5 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Mon, 20 Jan 2020 18:34:00 +0100 Subject: [PATCH 12/16] Push to bottom profile menu on sidebar. --- musician/static/musician/css/default.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/musician/static/musician/css/default.css b/musician/static/musician/css/default.css index 6d9efee..197878d 100644 --- a/musician/static/musician/css/default.css +++ b/musician/static/musician/css/default.css @@ -43,6 +43,12 @@ a:hover { min-width: 280px; max-width: 280px; min-height: 100vh; + + display: flex; + flex-direction: column; +} +#sidebar #sidebar-services { + flex-grow: 1; } #sidebar.active { From 5595ae6fd6b459b1f1d784378c400abc3e7deced Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 21 Jan 2020 12:30:37 +0100 Subject: [PATCH 13/16] Fix profile menu background color. --- musician/static/musician/css/default.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musician/static/musician/css/default.css b/musician/static/musician/css/default.css index 197878d..a95a573 100644 --- a/musician/static/musician/css/default.css +++ b/musician/static/musician/css/default.css @@ -65,7 +65,7 @@ a:hover { } #sidebar #user-profile-menu { - background: rgba(255, 255, 255, 0.3); + background:rgba(254, 251, 242, 0.25); } #sidebar ul.components { From 7dbf55f495d1dc128b7553aeabc604237da08b1d Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 21 Jan 2020 13:10:12 +0100 Subject: [PATCH 14/16] Add link to billing on profile page. --- musician/templates/musician/profile.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/musician/templates/musician/profile.html b/musician/templates/musician/profile.html index c820007..6a49dd6 100644 --- a/musician/templates/musician/profile.html +++ b/musician/templates/musician/profile.html @@ -55,7 +55,9 @@ Details: {{ payment.data }} {% endif %}
- + From d2d0832d6ba5b6d63b2ea8eb0fec2cfb75e95952 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 21 Jan 2020 13:20:28 +0100 Subject: [PATCH 15/16] Show & lay SaaS details out. --- musician/templates/musician/saas.html | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/musician/templates/musician/saas.html b/musician/templates/musician/saas.html index 2dc932a..ca12f2d 100644 --- a/musician/templates/musician/saas.html +++ b/musician/templates/musician/saas.html @@ -24,12 +24,11 @@

-

{% trans "Service info" %}

-

{% trans "Active" %}: {{ saas.is_active|yesno }}

- {# TODO (@slamora): implement saas details #} -
-                {{ saas.data }}
-            
+

{% trans "Service info" %}

+ {{ saas.is_active|yesno }}
+ {% for key, value in saas.data.items %} + {{ value }}
+ {% endfor %}