Raise 404 not found instead of error, when user is not employee

i.e. when they try to view "employee schedule" or "time sheet"
This commit is contained in:
Lance Edgar 2020-02-25 15:35:39 -06:00
parent 2b70ed1407
commit 5f8dc20312
2 changed files with 5 additions and 1 deletions

View file

@ -158,8 +158,8 @@ class TimeSheetView(View):
# force current user if not allowed to view all data # force current user if not allowed to view all data
if not self.request.has_perm('{}.viewall'.format(self.key)): if not self.request.has_perm('{}.viewall'.format(self.key)):
employee = self.request.user.employee employee = self.request.user.employee
assert employee
# note that employee may still be None, e.g. if current user is not employee
return {'date': date, 'employee': employee} return {'date': date, 'employee': employee}
def process_filter_form(self, form): def process_filter_form(self, form):
@ -257,6 +257,8 @@ class TimeSheetView(View):
View time sheet for single employee. View time sheet for single employee.
""" """
context = self.get_employee_context() context = self.get_employee_context()
if not context['employee']:
raise self.notfound()
form = self.make_employee_filter_form(context) form = self.make_employee_filter_form(context)
self.process_employee_filter_form(form) self.process_employee_filter_form(form)
context['form'] = form context['form'] = form

View file

@ -49,6 +49,8 @@ class TimeSheetView(BaseTimeSheetView):
""" """
# process filters; redirect if any were received # process filters; redirect if any were received
context = self.get_employee_context() context = self.get_employee_context()
if not context['employee']:
raise self.notfound()
form = self.make_employee_filter_form(context) form = self.make_employee_filter_form(context)
self.process_employee_filter_form(form) self.process_employee_filter_form(form)