Skip to content

Commit a5b333d

Browse files
authored
Merge pull request #313 from patriknordlen/master
Migrate application settings to model
2 parents 1ce74c5 + 73a1a65 commit a5b333d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+388
-194
lines changed

ansible/dev-install/templates/settings.py.j2

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ LOGIN_REDIRECT_URL = '/'
99
SESSION_COOKIE_HTTPONLY = True
1010
CSRF_COOKIE_HTTPONLY = True
1111
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
12-
ENABLE_DEDUPLICATION = False
13-
ENABLE_JIRA = False
14-
# True will display S0, S1, S2, ect in most places
15-
# False will display Critical, High, Medium, etc
16-
S_FINDING_SEVERITY_NAMING = False
1712
URL_PREFIX = ''
1813

1914
# Uncomment this line if you enable SSL

docs/upgrading.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,27 @@ The following needs to be added to settings.py: ::
7171
]
7272

7373
Once all these steps are completed your installation of DefectDojo will be running under Django 1.11
74+
75+
76+
July 6th 2017 - New location for system settings
77+
================================================
78+
79+
Pull request #313 moves a number of system settings previously located in the application's settings.py
80+
to a model that can be used and changed within the web application under "Configuration -> System Settings".
81+
82+
If you're using a custom ``URL_PREFIX`` you will need to set this in the model after upgrading by
83+
editing ``dojo/fixtures/system_settings.json`` and setting your URL prefix in the ``url_prefix`` value there.
84+
Then issue the command ``./manage.py loaddata system_settings.json`` to load your settings into the database.
85+
86+
If you're not using a custom ``URL_PREFIX``, after upgrading simply go to the System Settings page and review
87+
which values you want to set for each setting, as they're not automatically migrated from settings.py.
88+
89+
If you like you can then remove the following settings from settings.py to avoid confusion:
90+
91+
* ``ENABLE_DEDUPLICATION``
92+
* ``ENABLE_JIRA``
93+
* ``S_FINDING_SEVERITY_NAMING``
94+
* ``URL_PREFIX``
95+
* ``TIME_ZONE``
96+
* ``TEAM_NAME``
97+

dojo/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
ScanSettingsForm, FindingForm, StubFindingForm, FindingTemplateForm, \
2525
ImportScanForm, SEVERITY_CHOICES
2626
from dojo.tools.factory import import_parser_factory
27-
27+
from dojo.utils import get_system_setting
2828
from datetime import datetime
2929

30-
localtz = timezone(settings.TIME_ZONE)
30+
localtz = timezone(get_system_setting('time_zone'))
3131

3232
"""
3333
Setup logging for the api

dojo/cred/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
from dojo.forms import *
2727
from dojo.tasks import *
2828
from dojo.forms import *
29-
from dojo.utils import dojo_crypto_encrypt, prepare_for_view, FileIterWrapper
29+
from dojo.utils import dojo_crypto_encrypt, prepare_for_view, FileIterWrapper, get_system_setting
3030
from dojo.product import views as ds
3131

32-
localtz = timezone(settings.TIME_ZONE)
32+
localtz = timezone(get_system_setting('time_zone'))
3333

3434
logging.basicConfig(
3535
level=logging.DEBUG,

dojo/development_environment/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from dojo.filters import DevelopmentEnvironmentFilter
1313
from dojo.forms import Development_EnvironmentForm
1414
from dojo.models import Development_Environment
15-
from dojo.utils import get_page_items, add_breadcrumb
15+
from dojo.utils import get_page_items, add_breadcrumb, get_system_setting
1616

17-
localtz = timezone(settings.TIME_ZONE)
17+
localtz = timezone(get_system_setting('time_zone'))
1818

1919
logging.basicConfig(
2020
level=logging.DEBUG,

dojo/endpoint/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
from dojo.forms import EditEndpointForm, \
1818
DeleteEndpointForm, AddEndpointForm, EndpointMetaDataForm
1919
from dojo.models import Product, Endpoint, Finding
20-
from dojo.utils import get_page_items, add_breadcrumb, get_period_counts
20+
from dojo.utils import get_page_items, add_breadcrumb, get_period_counts, get_system_setting
2121
from django.contrib.contenttypes.models import ContentType
2222
from custom_field.models import CustomFieldValue, CustomField
2323

24-
localtz = timezone(settings.TIME_ZONE)
24+
localtz = timezone(get_system_setting('time_zone'))
2525

2626
logging.basicConfig(
2727
level=logging.DEBUG,

dojo/engagement/views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
JIRA_PKey, JIRA_Conf, JIRA_Issue, Cred_User, Cred_Mapping
2727
from dojo.tools.factory import import_parser_factory
2828
from dojo.utils import get_page_items, add_breadcrumb, handle_uploaded_threat, \
29-
FileIterWrapper, get_cal_event, message
29+
FileIterWrapper, get_cal_event, message, get_system_setting
3030
from dojo.tasks import update_epic_task, add_epic_task, close_epic_task
3131

32-
localtz = timezone(settings.TIME_ZONE)
32+
localtz = timezone(get_system_setting('time_zone'))
3333

3434
logging.basicConfig(
3535
level=logging.DEBUG,
@@ -141,12 +141,12 @@ def edit_engagement(request, eid):
141141
except:
142142
enabled = False
143143
pass
144-
if hasattr(settings, "ENABLE_JIRA"):
145-
if settings.ENABLE_JIRA:
146-
if JIRA_PKey.objects.filter(product=eng.product).count() != 0:
147-
jform = JIRAFindingForm(prefix='jiraform', enabled=enabled)
148-
else:
149-
jform = None
144+
145+
if get_system_setting('enable_jira') and JIRA_PKey.objects.filter(product=eng.product).count() != 0:
146+
jform = JIRAFindingForm(prefix='jiraform', enabled=enabled)
147+
else:
148+
jform = None
149+
150150
form.initial['tags'] = [tag.name for tag in eng.tags]
151151
add_breadcrumb(parent=eng, title="Edit Engagement", top_level=False, request=request)
152152
return render(request, 'dojo/new_eng.html',

dojo/filters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
MultipleChoiceFilter
1515
from django_filters.filters import ChoiceFilter, _truncate, DateTimeFilter
1616
from pytz import timezone
17+
from dojo.utils import get_system_setting
18+
19+
local_tz = timezone(get_system_setting('time_zone'))
1720

18-
local_tz = timezone(settings.TIME_ZONE)
1921
SEVERITY_CHOICES = (('Info', 'Info'), ('Low', 'Low'), ('Medium', 'Medium'),
2022
('High', 'High'), ('Critical', 'Critical'))
2123
BOOLEAN_CHOICES = (('false', 'No'), ('true', 'Yes'),)

dojo/finding/views.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
FindingImageAccessToken, JIRA_Issue, JIRA_PKey, JIRA_Conf, Dojo_User, Cred_User, Cred_Mapping, Test
3434
from dojo.utils import get_page_items, add_breadcrumb, FileIterWrapper, send_review_email, process_notifications, \
3535
add_comment, add_epic, add_issue, update_epic, update_issue, close_epic, jira_get_resolution_id, \
36-
jira_change_resolution_id, get_jira_connection
36+
jira_change_resolution_id, get_jira_connection, get_system_setting
3737

3838
from dojo.tasks import add_issue_task, update_issue_task, add_comment_task
3939

40-
localtz = timezone(settings.TIME_ZONE)
40+
localtz = timezone(get_system_setting('time_zone'))
4141

4242
logging.basicConfig(
4343
level=logging.DEBUG,
@@ -357,11 +357,11 @@ def edit_finding(request, fid):
357357
enabled = True
358358
except:
359359
enabled = False
360-
pass
361-
if hasattr(settings, 'ENABLE_JIRA'):
362-
if settings.ENABLE_JIRA:
363-
if JIRA_PKey.objects.filter(product=finding.test.engagement.product) != 0:
364-
jform = JIRAFindingForm(enabled=enabled, prefix='jiraform')
360+
pass
361+
362+
if get_system_setting('enable_jira') and JIRA_PKey.objects.filter(product=finding.test.engagement.product) != 0:
363+
jform = JIRAFindingForm(enabled=enabled, prefix='jiraform')
364+
365365
if request.method == 'POST':
366366
form = FindingForm(request.POST, instance=finding)
367367
if form.is_valid():
@@ -649,14 +649,14 @@ def promote_to_finding(request, fid):
649649
test = finding.test
650650
form_error = False
651651
jira_available = False
652-
if hasattr(settings, 'ENABLE_JIRA'):
653-
if settings.ENABLE_JIRA:
654-
if JIRA_PKey.objects.filter(product=test.engagement.product) != 0:
655-
jform = JIRAFindingForm(request.POST, prefix='jiraform',
656-
enabled=JIRA_PKey.objects.get(product=test.engagement.product).push_all_issues)
657-
jira_available = True
652+
653+
if get_system_setting('enable_jira') and JIRA_PKey.objects.filter(product=test.engagement.product) != 0:
654+
jform = JIRAFindingForm(request.POST, prefix='jiraform',
655+
enabled=JIRA_PKey.objects.get(product=test.engagement.product).push_all_issues)
656+
jira_available = True
658657
else:
659-
jform = None
658+
jform = None
659+
660660
form = PromoteFindingForm(initial={'title': finding.title,
661661
'date': finding.date,
662662
'severity': finding.severity,

dojo/fixtures/system_settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"model": "dojo.system_settings",
4+
"pk": 1,
5+
"fields": {
6+
"enable_deduplication": false,
7+
"enable_jira": false,
8+
"s_finding_severity_naming": false,
9+
"url_prefix": "",
10+
"time_zone": "UTC"
11+
}
12+
}
13+
]

0 commit comments

Comments
 (0)