aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/dispatch/middleware.py18
-rw-r--r--app/dispatch/templates/dispatch/identity/create.html8
-rw-r--r--app/dispatch/templates/dispatch/nav.html6
-rw-r--r--app/dispatch/views.py12
-rw-r--r--app/dispatchAuth/admin.py2
5 files changed, 42 insertions, 4 deletions
diff --git a/app/dispatch/middleware.py b/app/dispatch/middleware.py
index 2b3e349..8ae0465 100644
--- a/app/dispatch/middleware.py
+++ b/app/dispatch/middleware.py
@@ -27,5 +27,21 @@ class LoginRequiredMiddleware(object):
if path not in EXEMPT_URLS:
login_uri = '%s?next=%s' % (settings.LOGIN_URL, request.path_info)
return HttpResponseRedirect(login_uri)
+ else:
+ # I don't really like this but I don't really see a better
+ # way of checking for this
+ try:
+ identity = request.user.identity
+ except:
+ allowed_paths = [ reverse('identity_create', kwargs={'user_id': request.user.pk}) ]
+ allowed_paths.extend(EXEMPT_URLS)
+ print(allowed_paths)
+ if request.path_info not in allowed_paths:
+ return HttpResponseRedirect(allowed_paths[0])
+
+ return self.get_response(request)
+
+
+ # TODO: Have the middleware automatically set the default identity
+ # if not set and a superuser creates one
- return self.get_response(request) \ No newline at end of file
diff --git a/app/dispatch/templates/dispatch/identity/create.html b/app/dispatch/templates/dispatch/identity/create.html
index 90cdd8e..ab7b805 100644
--- a/app/dispatch/templates/dispatch/identity/create.html
+++ b/app/dispatch/templates/dispatch/identity/create.html
@@ -8,6 +8,14 @@
</div>
</div>
+<div class="row">
+ <div class="col s12">
+ <p class="flow-text">
+ Your user account does not have a company identity. Please fill out the form to create one at this time.
+ </p>
+ </div>
+</div>
+
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" class="btn green" value="Save" />
diff --git a/app/dispatch/templates/dispatch/nav.html b/app/dispatch/templates/dispatch/nav.html
index a5f09e5..ef65d24 100644
--- a/app/dispatch/templates/dispatch/nav.html
+++ b/app/dispatch/templates/dispatch/nav.html
@@ -1,4 +1,8 @@
-{% if request.user.is_authenticated %}
+{% if False %} # Checking for user identity and limiting the nav if it doesn't exist {% endif %}
+
+{% if not request.user.identity %}
+ <li><a href="{% url 'logout' %}">Logout</a></li>
+{% elif request.user.is_authenticated %}
<li><a href="{% url 'load_list' %}">Loads</a></li>
<li><a href="{% url 'invoice_list' %}">Invoices</a></li>
{% if request.user.is_superuser %}
diff --git a/app/dispatch/views.py b/app/dispatch/views.py
index f52c372..c80607e 100644
--- a/app/dispatch/views.py
+++ b/app/dispatch/views.py
@@ -437,8 +437,9 @@ def SetDefaultIdentity(request, user_id, pk):
return redirect(reverse('driver_details', kwargs={'pk': user_id}))
+# class IdentityCreate(CreateView, UserPassesTestMixin):
class IdentityCreate(UserPassesTestMixin, CreateView):
- template_name = "dispatch/identity/edit.html"
+ template_name = "dispatch/identity/create.html"
model = Identity
fields = []
@@ -459,6 +460,15 @@ class IdentityCreate(UserPassesTestMixin, CreateView):
self.set_fields(request.user)
return super(IdentityCreate, self).get(request)
+ def get_object(self):
+ user_id = self.kwargs.get('user_id')
+ u = User.objects.get(pk=user_id)
+ return Identity(user=u)
+
+ def form_valid(self, form):
+ form.instance.user = self.request.user
+ return super(IdentityCreate, self).form_valid(form)
+
def test_func(self):
return self.request.user.is_superuser or \
self.get_object().user.pk is self.request.user.pk
diff --git a/app/dispatchAuth/admin.py b/app/dispatchAuth/admin.py
index 67b1170..38ec7a6 100644
--- a/app/dispatchAuth/admin.py
+++ b/app/dispatchAuth/admin.py
@@ -68,7 +68,7 @@ class UserAdmin(BaseUserAdmin):
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('first_name','last_name')}),
- ('Permissions', {'fields': ('is_superuser',)}),
+ ('Permissions', {'fields': ('is_superuser','is_active')}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.