2020-08-06 01:53:45 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2016-12-10 16:04:34 -06:00
|
|
|
"""
|
|
|
|
Employee views
|
|
|
|
"""
|
|
|
|
|
|
|
|
from tailbone.views import employees as base
|
2020-08-06 01:53:45 -05:00
|
|
|
from tailbone.config import protected_usernames
|
2016-12-10 16:04:34 -06:00
|
|
|
|
|
|
|
|
2020-08-06 01:53:45 -05:00
|
|
|
class EmployeeView(base.EmployeesView):
|
2016-12-10 16:04:34 -06:00
|
|
|
"""
|
|
|
|
Prevent edit/delete for Chuck Norris
|
|
|
|
"""
|
|
|
|
|
2020-08-06 01:53:45 -05:00
|
|
|
def __init__(self, request, **kwargs):
|
|
|
|
super(EmployeeView, self).__init__(request, **kwargs)
|
|
|
|
self.protected_usernames = protected_usernames(self.rattail_config)
|
|
|
|
|
|
|
|
def is_employee_protected(self, employee):
|
|
|
|
if self.protected_usernames:
|
|
|
|
for user in employee.person.users:
|
|
|
|
if user.username in self.protected_usernames:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2016-12-10 16:04:34 -06:00
|
|
|
def editable_instance(self, employee):
|
2020-08-06 01:53:45 -05:00
|
|
|
if self.request.is_root:
|
|
|
|
return True
|
|
|
|
return not self.is_employee_protected(employee)
|
2016-12-10 16:04:34 -06:00
|
|
|
|
|
|
|
def deletable_instance(self, employee):
|
2020-08-06 01:53:45 -05:00
|
|
|
if self.request.is_root:
|
|
|
|
return True
|
|
|
|
return not self.is_employee_protected(employee)
|
2016-12-10 16:04:34 -06:00
|
|
|
|
|
|
|
|
|
|
|
def includeme(config):
|
|
|
|
|
|
|
|
# autocomplete
|
|
|
|
config.add_route('employees.autocomplete', '/employees/autocomplete')
|
|
|
|
config.add_view(base.EmployeesAutocomplete, route_name='employees.autocomplete',
|
|
|
|
renderer='json', permission='employees.list')
|
|
|
|
|
2020-08-06 01:53:45 -05:00
|
|
|
EmployeeView.defaults(config)
|