musician webapp edit options

This commit is contained in:
Jorge Pastor 2024-04-29 20:06:20 +02:00
parent fa1a130370
commit 4688605bc6
7 changed files with 53 additions and 48 deletions

View File

@ -16,6 +16,7 @@ from orchestra.contrib.webapps.options import AppOption
from orchestra.contrib.webapps.types import AppType
from . import api
from .settings import MUSICIAN_EDIT_ENABLE_PHP_OPTIONS
class LoginForm(AuthenticationForm):
@ -208,7 +209,7 @@ class SystemUsersChangePasswordForm(ChangePasswordForm):
model = SystemUser
class WebappOptionCreateForm(forms.ModelForm):
class WebappOptionForm(forms.ModelForm):
OPTIONS_HELP_TEXT = {
op.name: force_str(op.help_text) for op in AppOption.get_plugins()
@ -219,13 +220,27 @@ class WebappOptionCreateForm(forms.ModelForm):
fields = ("name", "value")
def __init__(self, *args, **kwargs):
self.webapp = kwargs.pop('webapp')
super().__init__(*args, **kwargs)
try:
self.webapp = kwargs.pop('webapp')
super().__init__(*args, **kwargs)
except:
super().__init__(*args, **kwargs)
self.webapp = self.instance.webapp
target = 'this.id.replace("name", "value")'
self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs
plugin = AppType.get(self.webapp.type)
self.fields['name'].widget.choices = plugin.get_group_options_choices()
choices = list(plugin.get_group_options_choices())
for grupo, opciones in enumerate(choices):
if isinstance(opciones[1], list):
nueva_lista = [opc for opc in opciones[1] if opc[0] in MUSICIAN_EDIT_ENABLE_PHP_OPTIONS]
choices[grupo] = (opciones[0], nueva_lista)
self.fields['name'].widget.choices = choices
class WebappOptionCreateForm(WebappOptionForm):
def save(self, commit=True):
instance = super().save(commit=False)
@ -234,21 +249,7 @@ class WebappOptionCreateForm(forms.ModelForm):
super().save(commit=True)
return instance
class WebappOptionUpdateForm(forms.ModelForm):
OPTIONS_HELP_TEXT = {
op.name: force_str(op.help_text) for op in AppOption.get_plugins()
}
class Meta:
model = WebAppOption
fields = ("name", "value")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.webapp = self.instance.webapp
target = 'this.id.replace("name", "value")'
self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs
plugin = AppType.get(self.webapp.type)
self.fields['name'].widget.choices = plugin.get_group_options_choices()
class WebappOptionUpdateForm(WebappOptionForm):
pass

View File

@ -1,3 +1,4 @@
from orchestra.contrib.settings import Setting
from collections import defaultdict
from django.conf import settings
@ -46,3 +47,14 @@ URL_SAAS_GITLAB = getsetting("URL_SAAS_GITLAB")
URL_SAAS_OWNCLOUD = getsetting("URL_SAAS_OWNCLOUD")
URL_SAAS_WORDPRESS = getsetting("URL_SAAS_WORDPRESS")
MUSICIAN_EDIT_ENABLE_PHP_OPTIONS = Setting('MUSICIAN_EDIT_ENABLE_PHP_OPTIONS', (
'public-root',
'timeout',
'max_input_time',
'max_input_vars',
'memory_limit',
'post_max_size',
'upload_max_filesize',
))

View File

@ -50,6 +50,7 @@
<div class="col-md-8">
{% with domain.websites.0 as website %}
{% with website.contents.0 as content %}
<a href="#domain-detail" class="btn btn-primary">{% trans "View DNS records" %}</a>
<button type="button" class="btn text-secondary" data-toggle="modal" data-target="#configDetailsModal"
data-domain="{{ domain.name }}" data-website="{{ website|yesno:'true,false' }}" data-webapp-type="{{ content.webapp.type }}" data-root-path="{{ content.path }}"
data-url="{% url 'musician:domain-detail' domain.id %}">

View File

@ -30,8 +30,10 @@
<td>{{ option.name }}</td>
<td>{{ option.value }}</td>
<td class="text-right">
{% if option.name in edit_allowed_PHP_options %}
<a href="{% url 'musician:webapp-update-option' object.pk option.pk %}">
<i class="ml-3 fas fa-edit"></i></a>
{% endif %}
<a href="{% url 'musician:webapp-delete-option' object.pk option.pk %}">
<i class="ml-3 text-danger fas fa-trash"></i></a>
</td>

View File

@ -1,7 +1,9 @@
{% extends "musician/base.html" %}
{% load bootstrap4 i18n %}
{% block content %}
<a class="btn-arrow-left" href="{% url 'musician:webapp-detail' view.kwargs.pk %}">{% trans "Go back" %}</a>
<h1 class="service-name">

View File

@ -49,7 +49,7 @@ from .models import Bill as BillService
from .models import DatabaseService
from .models import Mailbox as MailboxService
from .models import MailinglistService, SaasService
from .settings import ALLOWED_RESOURCES
from .settings import ALLOWED_RESOURCES, MUSICIAN_EDIT_ENABLE_PHP_OPTIONS
from .utils import get_bootstraped_percent
logger = logging.getLogger(__name__)
@ -680,6 +680,13 @@ class WebappDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView):
def get_queryset(self):
return WebApp.objects.filter(account=self.request.user)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
'edit_allowed_PHP_options': MUSICIAN_EDIT_ENABLE_PHP_OPTIONS
})
return context
class WebappAddOptionView(CustomContextMixin, UserTokenRequiredMixin, CreateView):
model = WebAppOption
form_class = WebappOptionCreateForm
@ -719,24 +726,3 @@ class WebappUpdateOptionView(CustomContextMixin, UserTokenRequiredMixin, UpdateV
def get_success_url(self):
return reverse_lazy("musician:webapp-detail", kwargs={"pk": self.kwargs["pk"]})
# from django.forms import inlineformset_factory
# class WebappUpdateOptionView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
# model = WebApp
# template_name = "musician/webapp_option_form.html"
# fields = '__all__'
# def get_context_data(self, **kwargs):
# context = super().get_context_data(**kwargs)
# webapp = self.object # Obtener el objeto de libro
# # Crear el inline formset para los autores
# OptionFormSet = inlineformset_factory(WebApp, WebAppOption, fields=('name','value'), extra=1)
# # Obtener el formset prellenado con los autores del libro
# formset = OptionFormSet(instance=webapp)
# # Agregar el formset al contexto
# context['option_formset'] = formset
# return context

View File

@ -77,12 +77,13 @@ class PublicRoot(AppOption):
def validate(self):
super().validate()
base_path = self.instance.webapp.get_base_path()
path = os.path.join(base_path, self.instance.value)
if not os.path.abspath(path).startswith(base_path):
raise ValidationError(
_("Public root path '%s' outside of webapp base path '%s'") % (path, base_path)
)
if self.instance.webapp_id is not None:
base_path = self.instance.webapp.get_base_path()
path = os.path.join(base_path, self.instance.value)
if not os.path.abspath(path).startswith(base_path):
raise ValidationError(
_("Public root path '%s' outside of webapp base path '%s'") % (path, base_path)
)
class Timeout(AppOption):