Change how we protect certain person, employee records

This commit is contained in:
Lance Edgar 2020-09-23 16:39:44 -05:00
parent 746db72046
commit 24cc4b4272
2 changed files with 24 additions and 12 deletions

View file

@ -164,15 +164,21 @@ class EmployeesView(MasterView):
if employee.status == self.enum.EMPLOYEE_STATUS_FORMER:
return 'warning'
def editable_instance(self, employee):
if self.rattail_config.demo():
return not bool(employee.user and employee.user.username == 'chuck')
def is_employee_protected(self, employee):
for user in employee.person.users:
if self.user_is_protected(user):
return True
return False
def editable_instance(self, employee):
if self.request.is_root:
return True
return not self.is_employee_protected(employee)
def deletable_instance(self, employee):
if self.rattail_config.demo():
return not bool(employee.user and employee.user.username == 'chuck')
if self.request.is_root:
return True
return not self.is_employee_protected(employee)
def configure_form(self, f):
super(EmployeesView, self).configure_form(f)

View file

@ -145,15 +145,21 @@ class PeopleView(MasterView):
return instance.person
raise HTTPNotFound
def editable_instance(self, person):
if self.rattail_config.demo():
return not bool(person.user and person.user.username == 'chuck')
def is_person_protected(self, person):
for user in person.users:
if self.user_is_protected(user):
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.rattail_config.demo():
return not bool(person.user and person.user.username == 'chuck')
if self.request.is_root:
return True
return not self.is_person_protected(person)
def delete_instance(self, person):
"""