rattail-demo/rattail_demo/web/views/people.py
Lance Edgar c5922c74ea Be smarter about how we prevent edit/delete for some people, employees
instead of just hard-coding UUID for 'chuck'
2020-08-06 01:53:45 -05:00

47 lines
1.3 KiB
Python

# -*- coding: utf-8; -*-
"""
Person views
"""
from tailbone.views import people as base
from tailbone_corepos.views import people as corepos_base
from tailbone.config import protected_usernames
class PersonView(corepos_base.PersonView):
"""
Prevent edit/delete for Chuck Norris
"""
def __init__(self, request, **kwargs):
super(PersonView, self).__init__(request, **kwargs)
self.protected_usernames = protected_usernames(self.rattail_config)
def is_person_protected(self, person):
if self.protected_usernames:
for user in person.users:
if user.username in self.protected_usernames:
return True
return False
def editable_instance(self, person):
if self.request.is_root:
return True
return not self.is_person_protected(person)
def deletable_instance(self, person):
if self.request.is_root:
return True
return not self.is_person_protected(person)
def includeme(config):
# autocomplete
config.add_route('people.autocomplete', '/people/autocomplete')
config.add_view(base.PeopleAutocomplete, route_name='people.autocomplete',
renderer='json', permission='people.list')
PersonView.defaults(config)
base.PersonNoteView.defaults(config)