musician saas edit/delete only nextcloud

This commit is contained in:
Jorge Pastor 2024-10-29 19:14:43 +01:00
parent 4879eec69e
commit b346d5403b
7 changed files with 135 additions and 1 deletions

View file

@ -2,12 +2,14 @@ from django import forms
from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.forms import AuthenticationForm
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.forms.widgets import HiddenInput
from django.contrib.auth.hashers import make_password from django.contrib.auth.hashers import make_password
from orchestra.contrib.domains.models import Domain, Record from orchestra.contrib.domains.models import Domain, Record
from orchestra.contrib.mailboxes.models import Address, Mailbox from orchestra.contrib.mailboxes.models import Address, Mailbox
from orchestra.contrib.systemusers.models import WebappUsers, SystemUser from orchestra.contrib.systemusers.models import WebappUsers, SystemUser
from orchestra.contrib.saas.models import SaaS
from orchestra.contrib.musician.validators import ValidateZoneMixin from orchestra.contrib.musician.validators import ValidateZoneMixin
from . import api from . import api
@ -202,3 +204,22 @@ class SystemUsersChangePasswordForm(ChangePasswordForm):
fields = ("password",) fields = ("password",)
model = SystemUser model = SystemUser
class SaasUpdateForm(forms.ModelForm):
class Meta:
model = SaaS
fields = ("is_active", "service", "name", "data", "custom_url")
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user')
super().__init__(*args, **kwargs)
self.fields['name'].widget.attrs['readonly'] = True
self.fields['service'].widget.attrs['disabled'] = 'disabled'
self.fields['data'].widget = HiddenInput()
self.fields["custom_url"].widget = HiddenInput()
class NextcloudChangePasswordForm(ChangePasswordForm):
class Meta:
fields = ("password",)
model = SaaS

View file

@ -0,0 +1,15 @@
{% extends "musician/base.html" %}
{% load bootstrap4 i18n %}
{% block content %}
<h1 class="service-name">{% trans "Change password" %}: <span class="font-weight-light">{{ object.name }}</span></h1>
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<a class="btn btn-light mr-2" href="{% url 'musician:saas-list' %}">{% trans "Cancel" %}</a>
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
{% endbuttons %}
</form>
{% endblock %}

View file

@ -0,0 +1,12 @@
{% extends "musician/base.html" %}
{% load i18n %}
{% block content %}
<form method="post">
{% csrf_token %}
<p>{% blocktrans %}Are you sure that you want remove the SaaS:{% endblocktrans %} {{ saas }} ?</p>
<p class="alert alert-warning"><strong>{% trans 'WARNING: This action cannot be undone.' %}</strong></p>
<a class="btn btn-light mr-2" href="{% url 'musician:saas-list' %}">{% trans 'Cancel' %}</a>
<input class="btn btn-danger" type="submit" value="{% trans 'Delete' %}">
</form>
{% endblock %}

View file

@ -0,0 +1,41 @@
{% extends "musician/base.html" %}
{% load bootstrap4 i18n %}
{% block content %}
<style>
.form-check{
background-color: #fff;
padding: .375rem 2.0rem;
border: 1px solid #ced4da;
border-radius: 5px;
}
</style>
<a class="btn-arrow-left" href="{% url 'musician:saas-list' %}">{% trans "Go back" %}</a>
<h1 class="service-name">
{% if form.instance.pk %}
{% trans "Update SaaS" %} <span class="font-weight-light">{{ saas.name }}</span>
{% else %}
{% trans "Create SaaS" %}
{% endif %}
</h1>
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<a class="btn btn-light mr-2" href="{% url 'musician:saas-list' %}">{% trans "Cancel" %}</a>
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
{% if form.instance.pk %}
<div class="float-right">
<a class="btn btn-outline-warning" href="{% url 'musician:nextcloud-password' form.instance.pk %}"><i class="fas fa-key"></i> {% trans "Change password" %}</a>
<a class="btn btn-danger" href="{% url 'musician:saas-delete' view.kwargs.pk %}">{% trans "Delete" %}</a>
</div>
{% endif %}
{% endbuttons %}
</form>
{% endblock %}

View file

@ -20,6 +20,7 @@
<th scope="col">{% trans "Status" %}</th> <th scope="col">{% trans "Status" %}</th>
<th scope="col">{% trans "Service" %}</th> <th scope="col">{% trans "Service" %}</th>
<th scope="col">{% trans "Service info" %}</th> <th scope="col">{% trans "Service info" %}</th>
<th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -43,6 +44,12 @@
<label>{{ key }}:</label> <strong>{{ value }}</strong><br/> <label>{{ key }}:</label> <strong>{{ value }}</strong><br/>
{% endfor %} {% endfor %}
</td> </td>
<td class="text-right">
<a class="btn btn-outline-warning" role="button" href="{% url 'musician:saas-update' saas.id %}">
<i class="fas fa-tools"></i></a>
<a class="btn btn-outline-danger" role="button" href="{% url 'musician:saas-delete' saas.id %}">
<i class="text-danger fas fa-trash"></i></a>
</td>
</tr> </tr>
{% empty %} {% empty %}
<tr> <tr>
@ -59,4 +66,5 @@
{% include "musician/components/table_paginator.html" %} {% include "musician/components/table_paginator.html" %}
</table> </table>
</div> </div>
<a class="btn btn-primary mt-4 mb-4" href="#">{% trans "New SaaS" %}</a>
{% endblock %} {% endblock %}

View file

@ -51,6 +51,9 @@ urlpatterns = [
path('databases/', views.DatabaseListView.as_view(), name='database-list'), path('databases/', views.DatabaseListView.as_view(), name='database-list'),
path('saas/', views.SaasListView.as_view(), name='saas-list'), path('saas/', views.SaasListView.as_view(), name='saas-list'),
path('saas/<int:pk>/', views.SaasUpdateView.as_view(), name='saas-update'),
path('saas/<int:pk>/delete/', views.SaasDeleteView.as_view(), name='saas-delete'),
path('saas/<int:pk>/nextcloud-change-password/', views.NextcloudChangePasswordView.as_view(), name='nextcloud-password'),
path('webappusers/', views.WebappUserListView.as_view(), name='webappuser-list'), path('webappusers/', views.WebappUserListView.as_view(), name='webappuser-list'),
path('webappuser/<int:pk>/change-password/', views.WebappUserChangePasswordView.as_view(), name='webappuser-password'), path('webappuser/<int:pk>/change-password/', views.WebappUserChangePasswordView.as_view(), name='webappuser-password'),

View file

@ -42,7 +42,7 @@ from .auth import logout as auth_logout
from .forms import (LoginForm, MailboxChangePasswordForm, MailboxCreateForm, from .forms import (LoginForm, MailboxChangePasswordForm, MailboxCreateForm,
MailboxSearchForm, MailboxUpdateForm, MailForm, MailboxSearchForm, MailboxUpdateForm, MailForm,
RecordCreateForm, RecordUpdateForm, WebappUsersChangePasswordForm, RecordCreateForm, RecordUpdateForm, WebappUsersChangePasswordForm,
SystemUsersChangePasswordForm) SystemUsersChangePasswordForm, SaasUpdateForm, NextcloudChangePasswordForm)
from .mixins import (CustomContextMixin, ExtendedPaginationMixin, from .mixins import (CustomContextMixin, ExtendedPaginationMixin,
UserTokenRequiredMixin) UserTokenRequiredMixin)
from .models import Address as AddressService from .models import Address as AddressService
@ -623,6 +623,40 @@ class SaasListView(ServiceListView):
'title': _('Software as a Service'), 'title': _('Software as a Service'),
} }
class SaasUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
model = SaaS
form_class = SaasUpdateForm
template_name = "musician/saas_form.html"
def get_queryset(self):
qs = SaaS.objects.filter(account=self.request.user)
return qs
def get_success_url(self):
return reverse_lazy("musician:saas-list")
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["user"] = self.request.user
return kwargs
class NextcloudChangePasswordView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
template_name = "musician/nextcloud_change_password.html"
model = SaaS
form_class = NextcloudChangePasswordForm
success_url = reverse_lazy("musician:saas-list")
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-list")
def get_queryset(self):
return self.model.objects.filter(account=self.request.user)
class DomainDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView): class DomainDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView):
template_name = "musician/domain_detail.html" template_name = "musician/domain_detail.html"