Skip to content

Commit

Permalink
Merge pull request #28 from mikebryant/add-csp
Browse files Browse the repository at this point in the history
Add Content Security Policy support
  • Loading branch information
benbacardi committed Jul 26, 2016
2 parents 4ec83a5 + 4040987 commit a6afe10
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
11 changes: 11 additions & 0 deletions nuit/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@


SETTINGS = {
# For use with django-csp
'CSP_STYLE_SRC': (
"'self'",
# modernizr.js
"'sha256-CwE3Bg0VYQOIdNAkbB/Btdkhul49qZuwgNCMPgNY5zw='",
"'sha256-LpfmXS+4ZtL2uPRZgkoR29Ghbxcfime/CsD/4w5VujE='",
"'sha256-MZKTI0Eg1N13tshpFaVW65co/LeICXq4hyVx6GWVlK0='",
"'sha256-YJO/M9OgDKEBRKGqp4Zd07dzlagbB+qmKgThG52u/Mk='",
# jquery.js
"'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='",
),
'TEMPLATE_CONTEXT_PROCESSORS': [
'django.core.context_processors.request',
'nuit.context_processors.nuit',
Expand Down
3 changes: 3 additions & 0 deletions nuit/static/nuit/css/no-toggle-topbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.toggle-topbar {
display: none;
}
6 changes: 6 additions & 0 deletions nuit/static/nuit/js/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$(document).ready(function() {
$('#login-button').click(function() {
$(this).addClass('hide');
$('#login-loader').removeClass('hide');
});
});
8 changes: 2 additions & 6 deletions nuit/templates/nuit/bases/_error_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@

{% block css %}

<style type='text/css'>
{{ block.super }}

.toggle-topbar {
display: none;
}

</style>
<link rel='stylesheet' type='text/css' href='{% static 'nuit/css/no-toggle-topbar.css' %}' />

{% endblock css %}

Expand Down
23 changes: 6 additions & 17 deletions nuit/templates/nuit/generic/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@

{% block css %}

<style type='text/css'>
{{ block.super }}

.login-loader, .toggle-topbar {
display: none;
}

</style>
<link rel='stylesheet' type='text/css' href='{% static 'nuit/css/no-toggle-topbar.css' %}' />

{% endblock css %}

Expand Down Expand Up @@ -44,8 +40,8 @@ <h1>{{NUIT_GLOBAL_TITLE|default:'Nuit'}}</h1>
<input type='password' id='password' name='password' placeholder='Password'>

<div class='submit'>
<div class='login-loader'>{% include 'nuit/includes/loader.html' with size=48 %}</div>
<button class='button expand'>Login</button>
<div class='hide' id='login-loader'>{% include 'nuit/includes/loader.html' with size=48 %}</div>
<button class='button expand' id='login-button'>Login</button>
</div>

<input type='hidden' name='next' value='{{next}}' />
Expand All @@ -60,15 +56,8 @@ <h1>{{NUIT_GLOBAL_TITLE|default:'Nuit'}}</h1>

{% block scripts %}

<script type='text/javascript'>

$(document).ready(function() {
$('button').click(function() {
$(this).hide();
$('.login-loader').show();
});
});
{{ block.super }}

</script>
<script type='text/javascript' src='{% static 'nuit/js/login.js' %}'></script>

{% endblock scripts %}
2 changes: 1 addition & 1 deletion nuit/templatetags/nuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def set_active_menu(active_menu):
Inserts a span with a class of .nuit-active-menu that is picked up by Javascript
to highlight the correct menu item.
'''
return format_html("<span style='display: none' class='nuit-active-menu'>{}</span>", active_menu)
return format_html("<span class='hide nuit-active-menu'>{}</span>", active_menu)


class ExtendNode(ExtendsNode):
Expand Down
2 changes: 1 addition & 1 deletion nuit/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_set_active_menu(self):
output = soup(set_active_menu('bob')).find('span')
self.assertEqual('bob', output.text)
self.assertTrue('nuit-active-menu' in output.attrs['class'])
self.assertTrue('display: none' in output.attrs['style'])
self.assertTrue('hide' in output.attrs['class'])

def test_menu_item(self):

Expand Down

0 comments on commit a6afe10

Please sign in to comment.