Avoid "detach person" logic if not supported by view class

This commit is contained in:
Lance Edgar 2021-09-28 16:12:33 -04:00
parent a6c89d7998
commit 03a569d9a3

View file

@ -221,7 +221,7 @@ class CustomerView(MasterView):
if self.viewing:
if use_buefy:
f.set_renderer('people', self.render_people_buefy)
elif self.has_perm('detach_person'):
elif self.people_detachable and self.has_perm('detach_person'):
f.set_renderer('people', self.render_people_removable)
else:
f.set_renderer('people', self.render_people)
@ -257,7 +257,7 @@ class CustomerView(MasterView):
customer = kwargs['instance']
people = []
for person in customer.people:
people.append({
data = {
'uuid': person.uuid,
'full_name': person.display_name,
'first_name': person.first_name,
@ -266,10 +266,13 @@ class CustomerView(MasterView):
uuid=person.uuid),
'_action_url_edit': self.request.route_url('people.edit',
uuid=person.uuid),
'_action_url_detach': self.request.route_url('customers.detach_person',
}
if self.people_detachable and self.has_perm('detach_person'):
data['_action_url_detach'] = self.request.route_url(
'customers.detach_person',
uuid=customer.uuid,
person_uuid=person.uuid),
})
person_uuid=person.uuid)
people.append(data)
kwargs['people_data'] = people
return kwargs
@ -365,7 +368,7 @@ class CustomerView(MasterView):
g.main_actions.append(self.make_action('view', icon='eye'))
if self.request.has_perm('people.edit'):
g.main_actions.append(self.make_action('edit', icon='edit'))
if self.has_perm('detach_person'):
if self.people_detachable and self.has_perm('detach_person'):
g.main_actions.append(self.make_action('detach', icon='minus-circle',
link_class='has-text-warning',
click_handler="$emit('detach-person', props.row._action_url_detach)"))