From 5f4b10cb82402548013f109f2ab13460652f2a8d Mon Sep 17 00:00:00 2001 From: Amal Elshihaby Date: Fri, 10 Sep 2021 09:58:42 +0200 Subject: [PATCH] NextCloud Integration --- matrixhosting/forms.py | 55 +- .../migrations/0014_alter_vminstance_order.py | 20 + matrixhosting/models.py | 14 +- .../matrixhosting/includes/_navbar.html | 4 +- .../matrixhosting/order_details.html | 4 +- .../{matrixhosting => uncloud_pay}/bills.html | 8 +- .../{matrixhosting => uncloud_pay}/cards.html | 0 .../order_success.html | 4 +- .../payments.html | 12 +- matrixhosting/tests.py | 14 + matrixhosting/urls.py | 6 +- matrixhosting/utils.py | 64 +- matrixhosting/views.py | 151 +- nextcloud/__init__.py | 0 nextcloud/admin.py | 4 + nextcloud/apps.py | 9 + nextcloud/forms.py | 29 + nextcloud/models.py | 90 + nextcloud/serializers.py | 8 + nextcloud/signals.py | 2 + .../nextcloud/css/bootstrap-select.min.css | 6 + .../static/nextcloud/css/bootstrap.min.css | 7 + nextcloud/static/nextcloud/css/common.css | 1346 +++++ .../nextcloud/css/fontawesome-all.min.css | 1 + nextcloud/static/nextcloud/css/hosting.css | 618 ++ .../static/nextcloud/css/owl.carousel.min.css | 6 + nextcloud/static/nextcloud/css/theme.css | 3508 ++++++++++++ .../nextcloud/images/background-image.jpg | Bin 0 -> 1497208 bytes nextcloud/static/nextcloud/images/call.png | Bin 0 -> 3507 bytes .../static/nextcloud/images/company-large.jpg | Bin 0 -> 40282 bytes .../static/nextcloud/images/company-small.jpg | Bin 0 -> 14046 bytes nextcloud/static/nextcloud/images/favicon.png | Bin 0 -> 1789 bytes .../static/nextcloud/images/logo-light.png | Bin 0 -> 5016 bytes nextcloud/static/nextcloud/images/logo.png | Bin 0 -> 7126 bytes .../static/nextcloud/images/mastercard.png | Bin 0 -> 5170 bytes nextcloud/static/nextcloud/images/visa.png | Bin 0 -> 4423 bytes .../nextcloud/js/bootstrap-select.min.js | 9 + .../nextcloud/js/bootstrap.bundle.min.js | 7 + nextcloud/static/nextcloud/js/main.js | 47 + nextcloud/static/nextcloud/js/order.js | 32 + .../static/nextcloud/js/owl.carousel.min.js | 7 + nextcloud/static/nextcloud/js/payment.js | 178 + nextcloud/static/nextcloud/js/stripe.js | 79 + nextcloud/static/nextcloud/js/switcher.min.js | 1 + nextcloud/static/nextcloud/js/table.js | 6 + nextcloud/static/nextcloud/js/theme.js | 168 + .../nextcloud/webfonts/fa-brands-400.eot | Bin 0 -> 134346 bytes .../nextcloud/webfonts/fa-brands-400.svg | 3717 ++++++++++++ .../nextcloud/webfonts/fa-brands-400.ttf | Bin 0 -> 134040 bytes .../nextcloud/webfonts/fa-brands-400.woff | Bin 0 -> 90060 bytes .../nextcloud/webfonts/fa-brands-400.woff2 | Bin 0 -> 76736 bytes .../nextcloud/webfonts/fa-regular-400.eot | Bin 0 -> 34034 bytes .../nextcloud/webfonts/fa-regular-400.svg | 801 +++ .../nextcloud/webfonts/fa-regular-400.ttf | Bin 0 -> 33736 bytes .../nextcloud/webfonts/fa-regular-400.woff | Bin 0 -> 16276 bytes .../nextcloud/webfonts/fa-regular-400.woff2 | Bin 0 -> 13264 bytes .../nextcloud/webfonts/fa-solid-900.eot | Bin 0 -> 203030 bytes .../nextcloud/webfonts/fa-solid-900.svg | 5034 +++++++++++++++++ .../nextcloud/webfonts/fa-solid-900.ttf | Bin 0 -> 202744 bytes .../nextcloud/webfonts/fa-solid-900.woff | Bin 0 -> 101652 bytes .../nextcloud/webfonts/fa-solid-900.woff2 | Bin 0 -> 78212 bytes nextcloud/tasks.py | 64 + nextcloud/templates/account/base.html | 112 + nextcloud/templates/nextcloud/base.html | 94 + .../nextcloud/emails/renewal_warning.html | 13 + .../nextcloud/includes/_calculator_form.html | 64 + .../templates/nextcloud}/includes/_card.html | 0 .../templates/nextcloud/includes/_footer.html | 65 + .../templates/nextcloud/includes/_navbar.html | 88 + .../nextcloud/includes/invoice_footer.html | 78 + nextcloud/templates/nextcloud/index.html | 53 + nextcloud/templates/nextcloud/instances.html | 57 + .../nextcloud/order_confirmation.html | 210 + .../templates/nextcloud/order_details.html | 268 + nextcloud/templates/nextcloud/orders.html | 144 + nextcloud/templates/nextcloud/pricing.html | 7 + nextcloud/templates/uncloud_pay/bills.html | 190 + nextcloud/templates/uncloud_pay/cards.html | 210 + .../templates/uncloud_pay/order_success.html | 51 + nextcloud/templates/uncloud_pay/payments.html | 124 + nextcloud/tests.py | 102 + nextcloud/urls.py | 15 + nextcloud/utils.py | 89 + nextcloud/views.py | 289 + requirements.txt | 3 + uncloud/.env | 9 +- uncloud/forms.py | 27 + uncloud/settings.py | 9 +- uncloud/urls.py | 16 +- uncloud/validators.py | 34 + uncloud_auth/templates/account/email.html | 74 + .../templates/account/email_confirm.html | 30 + uncloud_auth/templates/account/login.html | 43 + uncloud_auth/templates/account/logout.html | 18 + .../templates/account/password_reset.html | 29 + .../account/password_reset_from_key.html | 37 + uncloud_auth/templates/account/signup.html | 57 + uncloud_auth/ungleich_ldap.py | 3 +- uncloud_pay/forms.py | 8 + uncloud_pay/models.py | 10 +- uncloud_pay/selectors.py | 2 +- .../static/uncloud_pay/css/invoice.css | 114 + .../static/uncloud_pay/images/call.png | Bin 0 -> 3507 bytes .../uncloud_pay/images/company-small.jpg | Bin 0 -> 14046 bytes .../static/uncloud_pay/images/home.png | Bin 0 -> 3643 bytes uncloud_pay/static/uncloud_pay/images/msg.png | Bin 0 -> 4654 bytes .../static/uncloud_pay/images/twitter.png | Bin 0 -> 4821 bytes .../uncloud_pay/webfonts/Avenir-Book.ttf | Bin 0 -> 79516 bytes .../templates/uncloud_pay/includes/_card.html | 33 + .../uncloud_pay/includes/invoice_footer.html | 78 + .../templates/uncloud_pay}/invoice.html | 6 +- uncloud_pay/urls.py | 5 + uncloud_pay/views.py | 119 +- 113 files changed, 18992 insertions(+), 235 deletions(-) create mode 100644 matrixhosting/migrations/0014_alter_vminstance_order.py rename matrixhosting/templates/{matrixhosting => uncloud_pay}/bills.html (97%) rename matrixhosting/templates/{matrixhosting => uncloud_pay}/cards.html (100%) rename matrixhosting/templates/{matrixhosting => uncloud_pay}/order_success.html (84%) rename matrixhosting/templates/{matrixhosting => uncloud_pay}/payments.html (92%) create mode 100644 nextcloud/__init__.py create mode 100644 nextcloud/admin.py create mode 100644 nextcloud/apps.py create mode 100644 nextcloud/forms.py create mode 100644 nextcloud/models.py create mode 100644 nextcloud/serializers.py create mode 100644 nextcloud/signals.py create mode 100644 nextcloud/static/nextcloud/css/bootstrap-select.min.css create mode 100644 nextcloud/static/nextcloud/css/bootstrap.min.css create mode 100644 nextcloud/static/nextcloud/css/common.css create mode 100644 nextcloud/static/nextcloud/css/fontawesome-all.min.css create mode 100644 nextcloud/static/nextcloud/css/hosting.css create mode 100644 nextcloud/static/nextcloud/css/owl.carousel.min.css create mode 100644 nextcloud/static/nextcloud/css/theme.css create mode 100644 nextcloud/static/nextcloud/images/background-image.jpg create mode 100644 nextcloud/static/nextcloud/images/call.png create mode 100644 nextcloud/static/nextcloud/images/company-large.jpg create mode 100644 nextcloud/static/nextcloud/images/company-small.jpg create mode 100644 nextcloud/static/nextcloud/images/favicon.png create mode 100644 nextcloud/static/nextcloud/images/logo-light.png create mode 100644 nextcloud/static/nextcloud/images/logo.png create mode 100644 nextcloud/static/nextcloud/images/mastercard.png create mode 100644 nextcloud/static/nextcloud/images/visa.png create mode 100644 nextcloud/static/nextcloud/js/bootstrap-select.min.js create mode 100644 nextcloud/static/nextcloud/js/bootstrap.bundle.min.js create mode 100644 nextcloud/static/nextcloud/js/main.js create mode 100644 nextcloud/static/nextcloud/js/order.js create mode 100644 nextcloud/static/nextcloud/js/owl.carousel.min.js create mode 100644 nextcloud/static/nextcloud/js/payment.js create mode 100644 nextcloud/static/nextcloud/js/stripe.js create mode 100644 nextcloud/static/nextcloud/js/switcher.min.js create mode 100644 nextcloud/static/nextcloud/js/table.js create mode 100644 nextcloud/static/nextcloud/js/theme.js create mode 100644 nextcloud/static/nextcloud/webfonts/fa-brands-400.eot create mode 100644 nextcloud/static/nextcloud/webfonts/fa-brands-400.svg create mode 100644 nextcloud/static/nextcloud/webfonts/fa-brands-400.ttf create mode 100644 nextcloud/static/nextcloud/webfonts/fa-brands-400.woff create mode 100644 nextcloud/static/nextcloud/webfonts/fa-brands-400.woff2 create mode 100644 nextcloud/static/nextcloud/webfonts/fa-regular-400.eot create mode 100644 nextcloud/static/nextcloud/webfonts/fa-regular-400.svg create mode 100644 nextcloud/static/nextcloud/webfonts/fa-regular-400.ttf create mode 100644 nextcloud/static/nextcloud/webfonts/fa-regular-400.woff create mode 100644 nextcloud/static/nextcloud/webfonts/fa-regular-400.woff2 create mode 100644 nextcloud/static/nextcloud/webfonts/fa-solid-900.eot create mode 100644 nextcloud/static/nextcloud/webfonts/fa-solid-900.svg create mode 100644 nextcloud/static/nextcloud/webfonts/fa-solid-900.ttf create mode 100644 nextcloud/static/nextcloud/webfonts/fa-solid-900.woff create mode 100644 nextcloud/static/nextcloud/webfonts/fa-solid-900.woff2 create mode 100644 nextcloud/tasks.py create mode 100644 nextcloud/templates/account/base.html create mode 100644 nextcloud/templates/nextcloud/base.html create mode 100644 nextcloud/templates/nextcloud/emails/renewal_warning.html create mode 100644 nextcloud/templates/nextcloud/includes/_calculator_form.html rename {matrixhosting/templates/matrixhosting => nextcloud/templates/nextcloud}/includes/_card.html (100%) create mode 100644 nextcloud/templates/nextcloud/includes/_footer.html create mode 100644 nextcloud/templates/nextcloud/includes/_navbar.html create mode 100644 nextcloud/templates/nextcloud/includes/invoice_footer.html create mode 100644 nextcloud/templates/nextcloud/index.html create mode 100644 nextcloud/templates/nextcloud/instances.html create mode 100644 nextcloud/templates/nextcloud/order_confirmation.html create mode 100644 nextcloud/templates/nextcloud/order_details.html create mode 100644 nextcloud/templates/nextcloud/orders.html create mode 100644 nextcloud/templates/nextcloud/pricing.html create mode 100644 nextcloud/templates/uncloud_pay/bills.html create mode 100644 nextcloud/templates/uncloud_pay/cards.html create mode 100644 nextcloud/templates/uncloud_pay/order_success.html create mode 100644 nextcloud/templates/uncloud_pay/payments.html create mode 100644 nextcloud/tests.py create mode 100644 nextcloud/urls.py create mode 100644 nextcloud/utils.py create mode 100644 nextcloud/views.py create mode 100644 uncloud/validators.py create mode 100644 uncloud_auth/templates/account/email.html create mode 100644 uncloud_auth/templates/account/email_confirm.html create mode 100644 uncloud_auth/templates/account/login.html create mode 100644 uncloud_auth/templates/account/logout.html create mode 100644 uncloud_auth/templates/account/password_reset.html create mode 100644 uncloud_auth/templates/account/password_reset_from_key.html create mode 100644 uncloud_auth/templates/account/signup.html create mode 100644 uncloud_pay/forms.py create mode 100644 uncloud_pay/static/uncloud_pay/css/invoice.css create mode 100644 uncloud_pay/static/uncloud_pay/images/call.png create mode 100644 uncloud_pay/static/uncloud_pay/images/company-small.jpg create mode 100644 uncloud_pay/static/uncloud_pay/images/home.png create mode 100644 uncloud_pay/static/uncloud_pay/images/msg.png create mode 100644 uncloud_pay/static/uncloud_pay/images/twitter.png create mode 100644 uncloud_pay/static/uncloud_pay/webfonts/Avenir-Book.ttf create mode 100644 uncloud_pay/templates/uncloud_pay/includes/_card.html create mode 100644 uncloud_pay/templates/uncloud_pay/includes/invoice_footer.html rename {matrixhosting/templates/matrixhosting => uncloud_pay/templates/uncloud_pay}/invoice.html (93%) diff --git a/matrixhosting/forms.py b/matrixhosting/forms.py index 691da27..5521c3d 100644 --- a/matrixhosting/forms.py +++ b/matrixhosting/forms.py @@ -1,35 +1,8 @@ -import tldextract - from django import forms -from django.forms import ModelForm from django.utils.translation import get_language, ugettext_lazy as _ from django.core.exceptions import ValidationError -from .validators import domain_name_validator from .models import VMInstance -from uncloud_pay.models import BillingAddress - - -class DomainNameField(forms.CharField): - description = 'Domain name form field' - default_validators = [domain_name_validator, ] - - def __init__(self, *args, **kwargs): - super(DomainNameField, self).__init__(*args, **kwargs) - -class MainModelForm(ModelForm): - def __init__(self, *args, **kwargs): - super(MainModelForm, self).__init__(*args, **kwargs) - for visible in self.visible_fields(): - visible.field.widget.attrs['class'] = 'form-control' - -class MainForm(forms.Form): - def __init__(self, *args, **kwargs): - super(MainForm, self).__init__(*args, **kwargs) - for visible in self.visible_fields(): - if (isinstance(visible.field.widget, forms.TextInput)): - visible.field.widget.attrs['class'] = 'form-control' - elif (isinstance(visible.field.widget, forms.CheckboxInput)): - visible.field.widget.attrs['class'] = 'custom-control-input' +from uncloud.forms import MainForm, MainModelForm, DomainNameField class InitialRequestForm(MainForm): @@ -55,30 +28,4 @@ class RequestDomainsNamesForm(MainForm): raise ValidationError("webclient name already exists") return webclient_name -class RequestDomainsForm(MainForm): - matrix_domain = DomainNameField(required=True, widget=forms.TextInput(attrs={'placeholder': 'Matrix Domain *'})) - homeserver_domain = DomainNameField(required=True, widget=forms.TextInput(attrs={'placeholder': 'Homeserver Domain *'})) - webclient_domain = DomainNameField(required=True, widget=forms.TextInput(attrs={'placeholder': 'Webclient Domain *'})) - is_open_registration = forms.BooleanField(required=False, initial=False) - - def clean(self): - homeserver_domain = self.cleaned_data.get('homeserver_domain', False) - webclient_domain = self.cleaned_data.get('webclient_domain', False) - if homeserver_domain and webclient_domain: - # Homserver-Domain and Webclient-Domain cannot be below the same second level domain (i.e. homeserver.abc.ch and webclient.def.cloud are ok, - # homeserver.abc.ch and webclient.abc.ch are not ok - homeserver_base = tldextract.extract(homeserver_domain).domain - webclient_base = tldextract.extract(webclient_domain).domain - if homeserver_base == webclient_base: - self._errors['webclient_domain'] = self.error_class([ - 'Homserver-Domain and Webclient-Domain cannot be below the same second level domain']) - return self.cleaned_data - - -class BillingAddressForm(MainModelForm): - class Meta: - model = BillingAddress - fields = ['full_name', 'street', - 'city', 'postal_code', 'country', 'vat_number', 'active', 'owner'] - diff --git a/matrixhosting/migrations/0014_alter_vminstance_order.py b/matrixhosting/migrations/0014_alter_vminstance_order.py new file mode 100644 index 0000000..bf4b6e4 --- /dev/null +++ b/matrixhosting/migrations/0014_alter_vminstance_order.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.4 on 2021-09-06 08:06 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0031_auto_20210819_1304'), + ('matrixhosting', '0013_auto_20210808_1652'), + ] + + operations = [ + migrations.AlterField( + model_name='vminstance', + name='order', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='matrix_instance_id', to='uncloud_pay.order'), + ), + ] diff --git a/matrixhosting/models.py b/matrixhosting/models.py index 1cabb0f..3c08ebc 100644 --- a/matrixhosting/models.py +++ b/matrixhosting/models.py @@ -1,6 +1,5 @@ import logging -import uuid -import os +import datetime import json import sys import gitlab @@ -17,6 +16,7 @@ from uncloud_pay.models import Order, BillRecord # Initialize logger. logger = logging.getLogger(__name__) + class VMInstance(models.Model): owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, @@ -30,7 +30,7 @@ class VMInstance(models.Model): config = models.JSONField(null=False, blank=False) - order = models.OneToOneField(Order, on_delete=models.CASCADE, related_name='instance_id') + order = models.OneToOneField(Order, on_delete=models.CASCADE, related_name='matrix_instance_id') creation_date = models.DateTimeField(auto_now_add=True) @@ -43,12 +43,12 @@ class VMInstance(models.Model): result = yaml.dump(self.config) gl = gitlab.Gitlab(settings.GITLAB_SERVER, oauth_token=settings.GITLAB_OAUTH_TOKEN) project = gl.projects.get(settings.GITLAB_PROJECT_ID) - project.files.create({'file_path': settings.GITLAB_YAML_DIR + f'matrix-{self.vm_name}.yaml', + project.files.create({'file_path': settings.GITLAB_YAML_DIR + f'matrix/{self.vm_name}.yaml', 'branch': 'master', 'content': result, 'author_email': settings.GITLAB_AUTHOR_EMAIL, 'author_name': settings.GITLAB_AUTHOR_NAME, - 'commit_message': f'Add New Deployment for matrix-{self.vm_name}'}) + 'commit_message': f'Add New Deployment for matrix/{self.vm_name}'}) super().save(*args, **kwargs) def delete(self, *args, **kwargs): @@ -58,11 +58,11 @@ class VMInstance(models.Model): return super().delete(*args, **kwargs) gl = gitlab.Gitlab(settings.GITLAB_SERVER, oauth_token=settings.GITLAB_OAUTH_TOKEN) project = gl.projects.get(settings.GITLAB_PROJECT_ID) - f_path = settings.GITLAB_YAML_DIR + f'matrix-{self.vm_name}.yaml' + f_path = settings.GITLAB_YAML_DIR + f'matrix/{self.vm_name}.yaml' file = project.files.get(file_path=f_path, ref='master') if file: project.files.delete(file_path=f_path, - commit_message=f'Delete matrix-{self.vm_name}', branch='master', + commit_message=f'Delete matrix/{self.vm_name}', branch='master', author_email=settings.GITLAB_AUTHOR_EMAIL, author_name=settings.GITLAB_AUTHOR_NAME) diff --git a/matrixhosting/templates/matrixhosting/includes/_navbar.html b/matrixhosting/templates/matrixhosting/includes/_navbar.html index 01aca4f..edddc61 100644 --- a/matrixhosting/templates/matrixhosting/includes/_navbar.html +++ b/matrixhosting/templates/matrixhosting/includes/_navbar.html @@ -19,7 +19,7 @@ {% url 'matrix:index' as index_url %} {% url 'matrix:orders' as orders_url %} {% url 'matrix:instances' as instances_url %} - {% url 'matrix:billing' as payments_url %} + {% url 'uncloud_pay:billing' as payments_url %} {% url 'matrix:pricing' as pricing_url %}