Skip to content
Permalink
Browse files

Login page banner (#1723)

Text banner on login page
  • Loading branch information
madchap committed Jan 2, 2020
1 parent c6c9c54 commit 4821f0b558046e0a39d9dfe3bcc1fef015276d6d
@@ -45,6 +45,7 @@ User.objects.create_superuser(
)
EOD

python3 manage.py loaddata initial_banner_conf
python3 manage.py loaddata product_type
python3 manage.py loaddata test_type
python3 manage.py loaddata development_environment
@@ -28,6 +28,7 @@ if [ ! -f "/opt/django-DefectDojo/static/docker_complete" ]; then
--email='admin@localhost' && \
./docker/setup-superuser.expect

python3 manage.py loaddata initial_banner_conf
python3 manage.py loaddata product_type
python3 manage.py loaddata test_type
python3 manage.py loaddata development_environment
No changes.
@@ -0,0 +1,7 @@
from django.conf.urls import url
from dojo.banner import views

urlpatterns = [
url(r'^configure_banner$', views.configure_banner,
name='configure_banner'),
]
@@ -0,0 +1,43 @@
import logging

from django.contrib.auth.decorators import user_passes_test
from django.shortcuts import render, get_object_or_404
from django.contrib import messages
from django.urls import reverse
from django.http import HttpResponseRedirect
from dojo.utils import add_breadcrumb

from dojo.forms import LoginBanner
from dojo.models import BannerConf

logger = logging.getLogger(__name__)


@user_passes_test(lambda u: u.is_superuser)
def configure_banner(request):
banner_config = get_object_or_404(BannerConf, id=1)
if request.method == 'POST':
form = LoginBanner(request.POST)
if form.is_valid():
banner_config.banner_enable = form.cleaned_data['banner_enable']
banner_config.banner_message = form.cleaned_data['banner_message']
banner_config.save()
messages.add_message(
request,
messages.SUCCESS,
'Banner updated successfully.',
extra_tags="alert-success",
)
return HttpResponseRedirect(reverse("configure_banner"))
else:
# List the banner configuration
form = LoginBanner(initial={
'banner_enable': banner_config.banner_enable,
'banner_message': banner_config.banner_message
})

add_breadcrumb(title="Banner Configuration", top_level=True, request=request)
return render(request, 'dojo/banner.html', {
'form': form,
'banner_message': banner_config.banner_message
})
@@ -0,0 +1,21 @@
# Generated by Django 2.2.4 on 2019-12-23 13:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dojo', '0025_jira_security_issuetype'),
]

operations = [
migrations.CreateModel(
name='BannerConf',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('banner_enable', models.BooleanField(blank=True, default=False, null=True)),
('banner_message', models.CharField(default='', help_text='This message will be displayed on the login page', max_length=500)),
],
),
]
@@ -0,0 +1,10 @@
[
{
"model": "dojo.bannerconf",
"pk": 1,
"fields": {
"banner_enable": false,
"banner_message": ""
}
}
]
@@ -363,8 +363,6 @@ class ImportScanForm(forms.Form):
("Xanitizer Scan", "Xanitizer Scan"),
("Trivy Scan", "Trivy Scan"))



SORTED_SCAN_TYPE_CHOICES = sorted(SCAN_TYPE_CHOICES, key=lambda x: x[1])
scan_date = forms.DateTimeField(
required=True,
@@ -1950,3 +1948,21 @@ def __init__(self, *args, **kwargs):
self.fields['Protect ' + i.name] = forms.BooleanField(initial=True, required=True, disabled=True)
else:
self.fields['Protect ' + i.name] = forms.BooleanField(initial=False, required=False)


class LoginBanner(forms.Form):
banner_enable = forms.BooleanField(
label="Enable login banner",
initial=False,
required=False,
help_text='Tick this box to enable a text banner on the login page'
)

banner_message = forms.CharField(
required=False,
label="Message to display on the login page"
)

def clean(self):
cleaned_data = super().clean()
return cleaned_data
@@ -1937,6 +1937,11 @@ def save(self, *args, **kwargs):
return super(FindingImageAccessToken, self).save(*args, **kwargs)


class BannerConf(models.Model):
banner_enable = models.BooleanField(default=False, null=True, blank=True)
banner_message = models.CharField(max_length=500, help_text="This message will be displayed on the login page", default='')


class JIRA_Conf(models.Model):
configuration_name = models.CharField(max_length=2000, help_text="Enter a name to give to this configuration", default='')
url = models.URLField(max_length=2000, verbose_name="JIRA URL", help_text="For configuring Jira, view: https://defectdojo.readthedocs.io/en/latest/features.html#jira-integration")
@@ -301,6 +301,7 @@
<li><a href="{% url 'system_settings' %}">System Settings </a></li>
<li><a href="{% url 'note_type' %}">Note Types </a></li>
<li><a href="{% url 'configure_google_sheets' %}">Google Sheets Sync</a></li>
<li><a href="{% url 'configure_banner' %}">Login banner</a></li>
{% endif %}
</ul>
</li>
@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block content %}
<form class="form-horizontal" action="{% url 'configure_banner' %}" method="post" enctype="multipart/form-data">{% csrf_token %}
{% include "dojo/form_fields.html" with form=form %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input aria-label="Update" class="btn btn-primary" name="update" type="submit" value="Submit"/>
</div>
</div>
</form>
{% endblock %}
@@ -1,8 +1,14 @@
{% extends "base.html" %}
{% load get_banner %}
{% block content %}
<h3>Login</h3>
<form class="form-horizontal" method="POST"> {% csrf_token %}
<fieldset class="col-md-offset-3 col-md-6">
{% if "banner_enable"|get_banner %}
<div class="well">
{{ "banner_message"|get_banner }}
</div>
{% endif %}
{% include "dojo/form_fields.html" with form=form %}
<!-- Button -->
<div class="form-group">
@@ -0,0 +1,17 @@

from django import template
from dojo.models import BannerConf

register = template.Library()


@register.filter
def get_banner(banner_conf):
try:
banner_config = BannerConf.objects.get()
if getattr(banner_config, banner_conf, None):
return getattr(banner_config, banner_conf, None)
else:
return False
except Exception:
return False
@@ -56,6 +56,7 @@
from dojo.notes.urls import urlpatterns as notes_urls
from dojo.note_type.urls import urlpatterns as note_type_urls
from dojo.google_sheet.urls import urlpatterns as google_sheets_urls
from dojo.banner.urls import urlpatterns as banner_urls

admin.autodiscover()

@@ -144,6 +145,7 @@
ur += notes_urls
ur += note_type_urls
ur += google_sheets_urls
ur += banner_urls

swagger_urls = [
url(r'^$', SwaggerView.as_view(), name='index'),
@@ -500,6 +500,7 @@ function install_app() {
if [ "$AUTO_DOCKER" == "yes" ]; then
python manage.py loaddata dojo/fixtures/defect_dojo_sample_data.json
else
python manage.py loaddata initial_banner_conf
python manage.py loaddata product_type
python manage.py loaddata test_type
python manage.py loaddata development_environment
@@ -273,6 +273,7 @@ function ubuntu_dojo_install() {
python manage.py loaddata language_type
python manage.py loaddata objects_review
python manage.py loaddata regulation
python manage.py loaddata initial_banner_conf

python manage.py installwatson
python manage.py buildwatson
@@ -109,6 +109,7 @@ function setupdb() {
python manage.py makemigrations --merge --noinput
python manage.py migrate
python manage.py syncdb --noinput
python manage.py loaddata initial_banner_conf
python manage.py loaddata product_type
python manage.py loaddata test_type
python manage.py loaddata development_environment
@@ -387,6 +387,7 @@ function ubuntu_dojo_install() {
python3 manage.py loaddata dojo/fixtures/defect_dojo_sample_data.json
fi

$PY manage.py loaddata initial_banner_conf
$PY manage.py loaddata product_type
$PY manage.py loaddata test_type
$PY manage.py loaddata development_environment

0 comments on commit 4821f0b

Please sign in to comment.
You can’t perform that action at this time.