environment: add mecanism to CRUD services variables (#64924)
gitea/hobo/pipeline/head This commit looks good
Details
gitea/hobo/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e635dd1818
commit
9761c8fec4
|
@ -2,12 +2,20 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block appbar %}
|
||||
<h2>{% trans 'Variables' %}</h2>
|
||||
{% if service %}
|
||||
<h2>{% trans 'Variables for' %} {{service.name}} <small>[{{service.slug}}, <a href="{{service.base_url}}">{{service.base_url}}</a>]</small></h2<>
|
||||
{% else %}
|
||||
<h2>{% trans 'Variables' %}</h2>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{{ block.super }}
|
||||
<a href="{% url 'environment-variables' %}">{% trans 'Variables' %}</a>
|
||||
{% if service %}
|
||||
<a href="{% url 'edit-variable-service' service=service.Extra.service_id slug=service.slug %}">{% trans 'Variables for' %} {{service.name}} ({{service.slug}})</a>
|
||||
{% else %}
|
||||
<a href="{% url 'environment-variables' %}">{% trans 'Variables' %}</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -20,7 +28,11 @@
|
|||
<a rel="popup" class="icon-remove-sign" href="{% url 'delete-variable' pk=variable.id %}" title="{% trans 'Delete variable' %}"></a>
|
||||
</p>
|
||||
{% endfor %}
|
||||
<a rel="popup" class="button" href="{% url 'new-variable' %}">{% trans 'Add new variable' %}</a>
|
||||
{% if service %}
|
||||
<a rel="popup" class="button" href="{% url 'new-variable-service' service=service.Extra.service_id slug=service.slug %}">{% trans 'Add new variable' %}</a>
|
||||
{% else %}
|
||||
<a rel="popup" class="button" href="{% url 'new-variable' %}">{% trans 'Add new variable' %}</a>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -21,6 +21,11 @@ from . import views
|
|||
urlpatterns = [
|
||||
path('', views.HomeView.as_view(), name='environment-home'),
|
||||
path('variables', views.VariablesView.as_view(), name='environment-variables'),
|
||||
re_path(
|
||||
r'^variables-(?P<service>\w+)/(?P<slug>[\w-]+)$',
|
||||
views.VariablesView.as_view(),
|
||||
name='edit-variable-service',
|
||||
),
|
||||
path(
|
||||
'new-variable',
|
||||
views.VariableCreateView.as_view(),
|
||||
|
|
|
@ -61,7 +61,22 @@ class VariablesView(TemplateView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['variables'] = Variable.objects.filter(auto=False, service_pk__isnull=True).order_by('label')
|
||||
if 'service' in self.kwargs:
|
||||
service_id = self.kwargs.pop('service')
|
||||
service_slug = self.kwargs.pop('slug')
|
||||
for service in AVAILABLE_SERVICES:
|
||||
if service.Extra.service_id == service_id:
|
||||
context['service'] = service.objects.get(slug=service_slug)
|
||||
break
|
||||
context['variables'] = Variable.objects.filter(
|
||||
auto=False, service_pk=context['service'].pk
|
||||
).order_by('label')
|
||||
else:
|
||||
context['variables'] = Variable.objects.filter(auto=False, service_pk__isnull=True).order_by(
|
||||
'label'
|
||||
)
|
||||
context['service'] = None
|
||||
context['service_id'] = None
|
||||
return context
|
||||
|
||||
|
||||
|
@ -101,7 +116,10 @@ class VariableCreateView(CreateView):
|
|||
def get_success_url(self):
|
||||
if self.object.service is None:
|
||||
return reverse_lazy('environment-variables')
|
||||
return reverse_lazy('environment-home')
|
||||
return reverse_lazy(
|
||||
'edit-variable-service',
|
||||
kwargs={'service': self.object.service.Extra.service_id, 'slug': self.object.service.slug},
|
||||
)
|
||||
|
||||
|
||||
class VariableUpdateView(UpdateView):
|
||||
|
@ -111,7 +129,10 @@ class VariableUpdateView(UpdateView):
|
|||
def get_success_url(self):
|
||||
if self.object.service is None:
|
||||
return reverse_lazy('environment-variables')
|
||||
return reverse_lazy('environment-home')
|
||||
return reverse_lazy(
|
||||
'edit-variable-service',
|
||||
kwargs={'service': self.object.service.Extra.service_id, 'slug': self.object.service.slug},
|
||||
)
|
||||
|
||||
|
||||
class VariableDeleteView(DeleteView):
|
||||
|
@ -121,7 +142,10 @@ class VariableDeleteView(DeleteView):
|
|||
def get_success_url(self):
|
||||
if self.object.service is None:
|
||||
return reverse_lazy('environment-variables')
|
||||
return reverse_lazy('environment-home')
|
||||
return reverse_lazy(
|
||||
'edit-variable-service',
|
||||
kwargs={'service': self.object.service.Extra.service_id, 'slug': self.object.service.slug},
|
||||
)
|
||||
|
||||
|
||||
class ServiceSelectCreateView(TemplateView):
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
<a class="extra-actions-menu-opener"></a>
|
||||
<ul class="extra-actions-menu">
|
||||
<li><a rel="popup" href="{% url 'save-service' service=service.Extra.service_id slug=service.slug %}">{% trans 'Edit' %}</a></li>
|
||||
<li><a href="{% url 'edit-variable-service' service=service.Extra.service_id slug=service.slug %}">{% trans 'Variables' %}</a></li>
|
||||
|
||||
{% if not service.is_operational and not service.wants_frequent_checks %}
|
||||
<li><a rel="popup" href="{% url 'delete-service' service=service.Extra.service_id slug=service.slug %}">{% trans 'Delete service' %}</a></li>
|
||||
|
|
|
@ -298,7 +298,7 @@ def test_new_variable_templated_value(app, admin_user):
|
|||
|
||||
def test_new_variable_service_view(app, admin_user):
|
||||
app = login(app)
|
||||
Combo.objects.create(
|
||||
service = Combo.objects.create(
|
||||
base_url='https://combo.agglo.love', template_name='...portal-user...', slug='portal'
|
||||
)
|
||||
response = app.get('/sites/new-variable-combo/portal')
|
||||
|
@ -306,7 +306,9 @@ def test_new_variable_service_view(app, admin_user):
|
|||
response.form['label'] = 'bar'
|
||||
response.form['value'] = 'barbar'
|
||||
response = response.form.submit()
|
||||
assert response.location == '/sites/'
|
||||
assert response.location == reverse(
|
||||
'edit-variable-service', kwargs={'service': service.Extra.service_id, 'slug': service.slug}
|
||||
)
|
||||
assert Variable.objects.all()[0].name == 'foo'
|
||||
assert Variable.objects.all()[0].label == 'bar'
|
||||
assert Variable.objects.all()[0].value == 'barbar'
|
||||
|
@ -323,6 +325,20 @@ def test_variable_update_view(app, admin_user):
|
|||
assert response.location == '/sites/variables'
|
||||
assert Variable.objects.all()[0].value == 'barbar'
|
||||
|
||||
service = Combo.objects.create(
|
||||
base_url='https://combo.agglo.love', template_name='...portal-user...', slug='portal'
|
||||
)
|
||||
var = Variable.objects.create(name='foo', value='bar', label='foobar', service=service)
|
||||
response = app.get('/sites/update-variable/%s' % var.pk)
|
||||
assert response.html.find('input', {'name': 'name'})['value'] == 'foo'
|
||||
assert response.html.find('textarea').text == '\nbar'
|
||||
response.form['value'] = 'foofoobarbar'
|
||||
response = response.form.submit()
|
||||
assert response.location == reverse(
|
||||
'edit-variable-service', kwargs={'service': service.Extra.service_id, 'slug': service.slug}
|
||||
)
|
||||
assert Variable.objects.get(pk=var.pk).value == 'foofoobarbar'
|
||||
|
||||
|
||||
def test_variable_delete_view(app, admin_user):
|
||||
app = login(app)
|
||||
|
|
Loading…
Reference in New Issue