diff --git a/orchestra/contrib/musician/api.py b/orchestra/contrib/musician/api.py
index de1ab265..f68a430c 100644
--- a/orchestra/contrib/musician/api.py
+++ b/orchestra/contrib/musician/api.py
@@ -30,7 +30,7 @@ API_PATHS = {
'mailbox-detail': 'mailboxes/{pk}/',
'mailbox-password': 'mailboxes/{pk}/set_password/',
'mailinglist-list': 'lists/',
- 'saas-list': 'saas/',
+ # 'saas-list': 'saas/',
'website-list': 'websites/',
# other
diff --git a/orchestra/contrib/musician/saas/forms.py b/orchestra/contrib/musician/saas/forms.py
index 5bf9dfb8..0c77d16d 100644
--- a/orchestra/contrib/musician/saas/forms.py
+++ b/orchestra/contrib/musician/saas/forms.py
@@ -4,6 +4,7 @@ from orchestra.forms.widgets import SpanWidget
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from orchestra.utils.python import random_ascii
+from django.core.exceptions import ValidationError
from django.forms.widgets import HiddenInput
@@ -92,3 +93,50 @@ class NextcloudChangePasswordForm(ChangePasswordForm):
password = self.cleaned_data.get("password")
self.fields['password'] = password
self.instance.set_password(password)
+
+
+class NextcloudCreateForm(forms.ModelForm):
+ error_messages = {
+ 'password_mismatch': _('The two password fields didn’t match.'),
+ }
+ password = forms.CharField(
+ label=_("Password"),
+ strip=False,
+ widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
+ )
+ password2 = forms.CharField(
+ label=_("Password confirmation"),
+ widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
+ strip=False,
+ help_text=_("Enter the same password as before, for verification."),
+ )
+
+ class Meta:
+ fields = ("service", "name", "password", "password2", "account")
+ model = SaaS
+
+ def __init__(self, *args, **kwargs):
+ user = kwargs.pop('user')
+ super().__init__(*args, **kwargs)
+ self.fields['account'].initial = user
+ self.fields['account'].widget = HiddenInput()
+ self.fields['service'].choices = [("nextcloud","nextCloud")]
+ self.fields['password'].help_text = _("Suggestion: %s") % random_ascii(20)
+
+
+
+ def clean_password2(self):
+ password = self.cleaned_data.get("password")
+ password2 = self.cleaned_data.get("password2")
+ if password and password2 and password != password2:
+ raise ValidationError(
+ self.error_messages['password_mismatch'],
+ code='password_mismatch',
+ )
+ return password
+
+ def clean_password(self):
+ password = self.cleaned_data.get("password")
+ self.fields['password'] = password
+ self.instance.set_password(password)
+
diff --git a/orchestra/contrib/musician/saas/views.py b/orchestra/contrib/musician/saas/views.py
index c2b49f17..aecab50d 100644
--- a/orchestra/contrib/musician/saas/views.py
+++ b/orchestra/contrib/musician/saas/views.py
@@ -12,7 +12,7 @@ from orchestra.contrib.musician.mixins import (CustomContextMixin, ExtendedPagin
UserTokenRequiredMixin)
from .forms import ( NextcloudChangePasswordForm, SaasNextcloudUpdateForm,
- SaasWordpressUpdateForm )
+ SaasWordpressUpdateForm, NextcloudCreateForm )
from orchestra.contrib.saas.models import SaaS
@@ -88,10 +88,23 @@ class NextcloudChangePasswordView(CustomContextMixin, UserTokenRequiredMixin, Up
def get_queryset(self):
return self.model.objects.filter(account=self.request.user)
+
class SaasDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
template_name = "musician/saas_check_delete.html"
model = SaaS
success_url = reverse_lazy("musician:saas-nextcloud-list")
def get_queryset(self):
- return self.model.objects.filter(account=self.request.user)
\ No newline at end of file
+ return self.model.objects.filter(account=self.request.user)
+
+
+class NextcloudCreateView(CustomContextMixin, UserTokenRequiredMixin, CreateView):
+ model = SaaS
+ template_name = "musician/saas_nextcloud_form.html"
+ form_class = NextcloudCreateForm
+ success_url = reverse_lazy("musician:saas-nextcloud-list")
+
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs['user'] = self.request.user
+ return kwargs
diff --git a/orchestra/contrib/musician/templates/musician/saas_nextcloud_list.html b/orchestra/contrib/musician/templates/musician/saas_nextcloud_list.html
index 41e1952e..fd0a9f09 100644
--- a/orchestra/contrib/musician/templates/musician/saas_nextcloud_list.html
+++ b/orchestra/contrib/musician/templates/musician/saas_nextcloud_list.html
@@ -54,4 +54,5 @@
+{% trans "New user" %}
{% endblock %}
diff --git a/orchestra/contrib/musician/urls.py b/orchestra/contrib/musician/urls.py
index 747a2392..f3078656 100644
--- a/orchestra/contrib/musician/urls.py
+++ b/orchestra/contrib/musician/urls.py
@@ -53,6 +53,7 @@ urlpatterns = [
path('saas/nextcloud/', views.SaasNextcloudListView.as_view(), name='saas-nextcloud-list'),
path('saas/nextcloud//', views.SaasNextcloudUpdateView.as_view(), name='saas-nextcloud-update'),
path('saas//nextcloud-change-password/', views.NextcloudChangePasswordView.as_view(), name='nextcloud-password'),
+ path('saas/nextcloud/new/', views.NextcloudCreateView.as_view(), name='saas-nextcloud-create'),
path('saas/wordpress/', views.SaasWordpressListView.as_view(), name='saas-wordpress-list'),
path('saas/wordpress//', views.SaasWordpressUpdateView.as_view(), name='saas-wordpress-update'),
path('saas//delete/', views.SaasDeleteView.as_view(), name='saas-delete'),