Add permission for viewing "all" employees

previously we showed all if user had "edit" perm
This commit is contained in:
Lance Edgar 2021-11-11 12:30:00 -06:00
parent 1ceb1e4434
commit f1fd003dca

View file

@ -83,6 +83,7 @@ class EmployeeView(MasterView):
def configure_grid(self, g): def configure_grid(self, g):
super(EmployeeView, self).configure_grid(g) super(EmployeeView, self).configure_grid(g)
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
use_buefy = self.get_use_buefy()
# phone # phone
g.set_joiner('phone', lambda q: q.outerjoin(model.EmployeePhoneNumber, sa.and_( g.set_joiner('phone', lambda q: q.outerjoin(model.EmployeePhoneNumber, sa.and_(
@ -114,21 +115,23 @@ class EmployeeView(MasterView):
g.hide_column('username') g.hide_column('username')
# id # id
if self.request.has_perm('{}.edit'.format(route_prefix)): if self.has_perm('edit'):
g.set_link('id') g.set_link('id')
else: else:
g.hide_column('id') g.remove('id')
del g.filters['id'] del g.filters['id']
# status # status
if self.request.has_perm('{}.edit'.format(route_prefix)): if self.has_perm('view_all'):
g.set_enum('status', self.enum.EMPLOYEE_STATUS) g.set_enum('status', self.enum.EMPLOYEE_STATUS)
g.filters['status'].default_active = True g.filters['status'].default_active = True
g.filters['status'].default_verb = 'equal' g.filters['status'].default_verb = 'equal'
# TODO: why must we set unicode string value here? if use_buefy:
g.filters['status'].default_value = six.text_type(self.enum.EMPLOYEE_STATUS_CURRENT) g.filters['status'].default_value = six.text_type(self.enum.EMPLOYEE_STATUS_CURRENT)
else: else:
g.hide_column('status') g.filters['status'].default_value = self.enum.EMPLOYEE_STATUS_CURRENT
else:
g.remove('status')
del g.filters['status'] del g.filters['status']
g.filters['first_name'].default_active = True g.filters['first_name'].default_active = True
@ -151,7 +154,7 @@ class EmployeeView(MasterView):
def query(self, session): def query(self, session):
q = session.query(model.Employee).join(model.Person) q = session.query(model.Employee).join(model.Person)
if not self.request.has_perm('employees.edit'): if not self.has_perm('view_all'):
q = q.filter(model.Employee.status == self.enum.EMPLOYEE_STATUS_CURRENT) q = q.filter(model.Employee.status == self.enum.EMPLOYEE_STATUS_CURRENT)
return q return q
@ -310,6 +313,21 @@ class EmployeeView(MasterView):
(model.EmployeeDepartment, 'employee_uuid'), (model.EmployeeDepartment, 'employee_uuid'),
] ]
@classmethod
def defaults(cls, config):
cls._defaults(config)
cls._employee_defaults(config)
@classmethod
def _employee_defaults(cls, config):
permission_prefix = cls.get_permission_prefix()
model_title_plural = cls.get_model_title_plural()
# view *all* employees
config.add_tailbone_permission(permission_prefix,
'{}.view_all'.format(permission_prefix),
"View *all* (not just current) {}".format(model_title_plural))
def includeme(config): def includeme(config):
EmployeeView.defaults(config) EmployeeView.defaults(config)