musician webapp edit options
This commit is contained in:
parent
fa1a130370
commit
4688605bc6
|
@ -16,6 +16,7 @@ from orchestra.contrib.webapps.options import AppOption
|
||||||
from orchestra.contrib.webapps.types import AppType
|
from orchestra.contrib.webapps.types import AppType
|
||||||
|
|
||||||
from . import api
|
from . import api
|
||||||
|
from .settings import MUSICIAN_EDIT_ENABLE_PHP_OPTIONS
|
||||||
|
|
||||||
|
|
||||||
class LoginForm(AuthenticationForm):
|
class LoginForm(AuthenticationForm):
|
||||||
|
@ -208,7 +209,7 @@ class SystemUsersChangePasswordForm(ChangePasswordForm):
|
||||||
model = SystemUser
|
model = SystemUser
|
||||||
|
|
||||||
|
|
||||||
class WebappOptionCreateForm(forms.ModelForm):
|
class WebappOptionForm(forms.ModelForm):
|
||||||
|
|
||||||
OPTIONS_HELP_TEXT = {
|
OPTIONS_HELP_TEXT = {
|
||||||
op.name: force_str(op.help_text) for op in AppOption.get_plugins()
|
op.name: force_str(op.help_text) for op in AppOption.get_plugins()
|
||||||
|
@ -219,13 +220,27 @@ class WebappOptionCreateForm(forms.ModelForm):
|
||||||
fields = ("name", "value")
|
fields = ("name", "value")
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
try:
|
||||||
self.webapp = kwargs.pop('webapp')
|
self.webapp = kwargs.pop('webapp')
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
except:
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.webapp = self.instance.webapp
|
||||||
|
|
||||||
|
|
||||||
target = 'this.id.replace("name", "value")'
|
target = 'this.id.replace("name", "value")'
|
||||||
self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs
|
self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs
|
||||||
|
|
||||||
plugin = AppType.get(self.webapp.type)
|
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):
|
def save(self, commit=True):
|
||||||
instance = super().save(commit=False)
|
instance = super().save(commit=False)
|
||||||
|
@ -234,21 +249,7 @@ class WebappOptionCreateForm(forms.ModelForm):
|
||||||
super().save(commit=True)
|
super().save(commit=True)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
class WebappOptionUpdateForm(forms.ModelForm):
|
|
||||||
|
|
||||||
OPTIONS_HELP_TEXT = {
|
class WebappOptionUpdateForm(WebappOptionForm):
|
||||||
op.name: force_str(op.help_text) for op in AppOption.get_plugins()
|
pass
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from orchestra.contrib.settings import Setting
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from django.conf import settings
|
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_OWNCLOUD = getsetting("URL_SAAS_OWNCLOUD")
|
||||||
|
|
||||||
URL_SAAS_WORDPRESS = getsetting("URL_SAAS_WORDPRESS")
|
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',
|
||||||
|
))
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
{% with domain.websites.0 as website %}
|
{% with domain.websites.0 as website %}
|
||||||
{% with website.contents.0 as content %}
|
{% 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"
|
<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-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 %}">
|
data-url="{% url 'musician:domain-detail' domain.id %}">
|
||||||
|
|
|
@ -30,8 +30,10 @@
|
||||||
<td>{{ option.name }}</td>
|
<td>{{ option.name }}</td>
|
||||||
<td>{{ option.value }}</td>
|
<td>{{ option.value }}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
|
{% if option.name in edit_allowed_PHP_options %}
|
||||||
<a href="{% url 'musician:webapp-update-option' object.pk option.pk %}">
|
<a href="{% url 'musician:webapp-update-option' object.pk option.pk %}">
|
||||||
<i class="ml-3 fas fa-edit"></i></a>
|
<i class="ml-3 fas fa-edit"></i></a>
|
||||||
|
{% endif %}
|
||||||
<a href="{% url 'musician:webapp-delete-option' object.pk option.pk %}">
|
<a href="{% url 'musician:webapp-delete-option' object.pk option.pk %}">
|
||||||
<i class="ml-3 text-danger fas fa-trash"></i></a>
|
<i class="ml-3 text-danger fas fa-trash"></i></a>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
{% extends "musician/base.html" %}
|
{% extends "musician/base.html" %}
|
||||||
{% load bootstrap4 i18n %}
|
{% load bootstrap4 i18n %}
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<a class="btn-arrow-left" href="{% url 'musician:webapp-detail' view.kwargs.pk %}">{% trans "Go back" %}</a>
|
<a class="btn-arrow-left" href="{% url 'musician:webapp-detail' view.kwargs.pk %}">{% trans "Go back" %}</a>
|
||||||
|
|
||||||
<h1 class="service-name">
|
<h1 class="service-name">
|
||||||
|
|
|
@ -49,7 +49,7 @@ from .models import Bill as BillService
|
||||||
from .models import DatabaseService
|
from .models import DatabaseService
|
||||||
from .models import Mailbox as MailboxService
|
from .models import Mailbox as MailboxService
|
||||||
from .models import MailinglistService, SaasService
|
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
|
from .utils import get_bootstraped_percent
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -680,6 +680,13 @@ class WebappDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return WebApp.objects.filter(account=self.request.user)
|
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):
|
class WebappAddOptionView(CustomContextMixin, UserTokenRequiredMixin, CreateView):
|
||||||
model = WebAppOption
|
model = WebAppOption
|
||||||
form_class = WebappOptionCreateForm
|
form_class = WebappOptionCreateForm
|
||||||
|
@ -719,24 +726,3 @@ class WebappUpdateOptionView(CustomContextMixin, UserTokenRequiredMixin, UpdateV
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse_lazy("musician:webapp-detail", kwargs={"pk": self.kwargs["pk"]})
|
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
|
|
|
@ -77,6 +77,7 @@ class PublicRoot(AppOption):
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super().validate()
|
super().validate()
|
||||||
|
if self.instance.webapp_id is not None:
|
||||||
base_path = self.instance.webapp.get_base_path()
|
base_path = self.instance.webapp.get_base_path()
|
||||||
path = os.path.join(base_path, self.instance.value)
|
path = os.path.join(base_path, self.instance.value)
|
||||||
if not os.path.abspath(path).startswith(base_path):
|
if not os.path.abspath(path).startswith(base_path):
|
||||||
|
|
Loading…
Reference in New Issue