Skip to content

Commit

Permalink
modifications to accommodate hardware plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
AsLogd committed Sep 17, 2018
1 parent 83ff533 commit aaea667
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app/hackathon_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@
# This allows to store an extra cookie in the browser to be shared with other application on the same domain
LOGGED_IN_COOKIE_DOMAIN = '.gerard.space'
LOGGED_IN_COOKIE_KEY = 'hackassistant_logged_in'

# Hardware configuration
HARDWARE_ENABLED = False
#Hardware request time length (in minutes)
HARDWARE_REQUEST_TIME = 15
3 changes: 3 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
if REIMBURSEMENT_ENABLED:
INSTALLED_APPS.append('reimbursement')

if HARDWARE_ENABLED:
INSTALLED_APPS.append('hardware')

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
Expand Down
3 changes: 3 additions & 0 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
<a href="{% url 'reimbursement_list' %}">Reimbursements</a></li>
{% endif %}
{% endif %}
{% if h_hw_enabled %}
{% include 'include/hardware_tab.html' %}
{% endif %}
{% if request.user.is_organizer or request.user.is_volunteer %}
<li class="{% if 'checkin' in request.build_absolute_uri %}active{% endif %}">
<a href="{% url 'check_in_list' %}">Check-in</a></li>
Expand Down
3 changes: 3 additions & 0 deletions app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
if settings.REIMBURSEMENT_ENABLED:
urlpatterns.append(url(r'^reimbursement/', include('reimbursement.urls')))

if settings.HARDWARE_ENABLED:
urlpatterns.append(url(r'^hardware/', include('hardware.urls')))

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
1 change: 1 addition & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def get_substitutions_templates():
'h_r_requirements': getattr(settings, 'REIMBURSEMENT_REQUIREMENTS', None),
'h_r_days': getattr(settings, 'REIMBURSEMENT_EXPIRY_DAYS', None),
'h_r_enabled': getattr(settings, 'REIMBURSEMENT_ENABLED', False),
'h_hw_enabled': getattr(settings, 'HARDWARE_ENABLED', False),
}


Expand Down
18 changes: 15 additions & 3 deletions user/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.contrib import admin
# Register your models here.
from django.contrib.admin.forms import AdminPasswordChangeForm
Expand All @@ -11,15 +12,26 @@ class UserAdmin(admin.ModelAdmin):
form = UserChangeForm
change_password_form = AdminPasswordChangeForm

display_fields = ['email', 'name', 'is_organizer', 'is_volunteer', 'is_director']
filter_fields = ['is_volunteer', 'is_director', 'is_organizer', 'is_admin', 'email_verified']
permission_fields = ['is_volunteer', 'is_director', 'is_organizer', 'is_admin', 'email_verified']

if settings.HARDWARE_ENABLED:
display_fields.append('is_hardware_admin')
filter_fields.append('is_hardware_admin')
permission_fields.insert(4, 'is_hardware_admin')

# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
list_display = ('email', 'name', 'is_organizer', 'is_volunteer', 'is_director')
list_filter = ('is_volunteer', 'is_director', 'is_organizer', 'is_admin', 'email_verified')
list_display = tuple(display_fields)
list_filter = tuple(filter_fields)
permission_fields = tuple(permission_fields)

fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('name',)}),
('Permissions', {'fields': ('is_volunteer', 'is_director', 'is_organizer', 'is_admin', 'email_verified')}),
('Permissions', {'fields': permission_fields}),
('Important dates', {'fields': ('last_login',)}),
)
add_fieldsets = (
Expand Down
20 changes: 20 additions & 0 deletions user/migrations/0006_user_is_hardware_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2018-09-17 19:28
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('user', '0005_makeemailfield'),
]

operations = [
migrations.AddField(
model_name='user',
name='is_hardware_admin',
field=models.BooleanField(default=False),
),
]
10 changes: 10 additions & 0 deletions user/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def test_func(self):
self.request.user.is_authenticated and self.request.user.is_director


class IsHardwareAdminMixin(UserPassesTestMixin):
raise_exception = True

def test_func(self):
if not self.request.user.is_authenticated:
return False
if not self.request.user.email_verified:
return False
return self.request.user.is_hardware_admin or self.request.user.is_organizer

def is_organizer(f, raise_exception=True):
"""
Decorator for views that checks whether a user is an organizer or not
Expand Down
2 changes: 2 additions & 0 deletions user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def create_superuser(self, email, name, password):
user.is_admin = True
user.email_verified = True
user.is_volunteer = True
user.is_hardware_admin = True
user.save(using=self._db)
return user

Expand All @@ -50,6 +51,7 @@ class User(AbstractBaseUser):
is_organizer = models.BooleanField(default=False)
is_director = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
is_hardware_admin = models.BooleanField(default=False)
created_time = models.DateTimeField(default=timezone.now)

objects = UserManager()
Expand Down

0 comments on commit aaea667

Please sign in to comment.