2020-03-16 19:47:17 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2016-12-07 22:07:12 -06:00
|
|
|
"""
|
|
|
|
Person views
|
|
|
|
"""
|
|
|
|
|
|
|
|
from tailbone.views import people as base
|
2020-03-16 19:47:17 -05:00
|
|
|
from tailbone_corepos.views import people as corepos_base
|
2020-08-06 01:53:45 -05:00
|
|
|
from tailbone.config import protected_usernames
|
2016-12-07 22:07:12 -06:00
|
|
|
|
|
|
|
|
2020-03-16 19:47:17 -05:00
|
|
|
class PersonView(corepos_base.PersonView):
|
2016-12-07 22:07:12 -06:00
|
|
|
"""
|
|
|
|
Prevent edit/delete for Chuck Norris
|
|
|
|
"""
|
|
|
|
|
2020-08-06 01:53:45 -05:00
|
|
|
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
|
|
|
|
|
2016-12-07 22:07:12 -06:00
|
|
|
def editable_instance(self, person):
|
2020-08-06 01:53:45 -05:00
|
|
|
if self.request.is_root:
|
|
|
|
return True
|
|
|
|
return not self.is_person_protected(person)
|
2016-12-07 22:07:12 -06:00
|
|
|
|
|
|
|
def deletable_instance(self, person):
|
2020-08-06 01:53:45 -05:00
|
|
|
if self.request.is_root:
|
|
|
|
return True
|
|
|
|
return not self.is_person_protected(person)
|
2016-12-07 22:07:12 -06:00
|
|
|
|
|
|
|
|
|
|
|
def includeme(config):
|
2016-12-10 10:15:41 -06:00
|
|
|
|
|
|
|
# autocomplete
|
|
|
|
config.add_route('people.autocomplete', '/people/autocomplete')
|
|
|
|
config.add_view(base.PeopleAutocomplete, route_name='people.autocomplete',
|
|
|
|
renderer='json', permission='people.list')
|
|
|
|
|
2020-03-16 19:47:17 -05:00
|
|
|
PersonView.defaults(config)
|
2019-06-15 15:31:09 -05:00
|
|
|
base.PersonNoteView.defaults(config)
|