541 |
541 |
template_name = 'authentic2/manager/homepage.html'
|
542 |
542 |
permissions = ['a2_rbac.search_role', 'a2_rbac.search_organizationalunit',
|
543 |
543 |
'auth.search_group', 'custom_user.search_user']
|
|
544 |
default_entries = [
|
|
545 |
{
|
|
546 |
'class': 'icon-organizational-units',
|
|
547 |
'href': reverse_lazy('a2-manager-ous'),
|
|
548 |
'label': _('Organizational units'),
|
|
549 |
'order': -1,
|
|
550 |
'permission': 'a2_rbac.search_organizationalunit',
|
|
551 |
},
|
|
552 |
{
|
|
553 |
'class': 'icon-users',
|
|
554 |
'href': reverse_lazy('a2-manager-users'),
|
|
555 |
'label': _('Users'),
|
|
556 |
'order': -1,
|
|
557 |
'permission': 'a2_rbac.search_user',
|
|
558 |
},
|
|
559 |
{
|
|
560 |
'class': 'icon-roles',
|
|
561 |
'href': reverse_lazy('a2-manager-roles'),
|
|
562 |
'label': _('Roles'),
|
|
563 |
'order': -1,
|
|
564 |
'permission': 'a2_rbac.search_role',
|
|
565 |
},
|
|
566 |
{
|
|
567 |
'class': 'icon-services',
|
|
568 |
'href': reverse_lazy('a2-manager-services'),
|
|
569 |
'label': _('Services'),
|
|
570 |
'order': -1,
|
|
571 |
'permission': 'a2_rbac.search_service',
|
|
572 |
},
|
|
573 |
]
|
544 |
574 |
|
545 |
575 |
def dispatch(self, request, *args, **kwargs):
|
546 |
576 |
if app_settings.HOMEPAGE_URL:
|
547 |
577 |
return redirect(request, app_settings.HOMEPAGE_URL)
|
548 |
578 |
return super(HomepageView, self).dispatch(request, *args, **kwargs)
|
549 |
579 |
|
|
580 |
def get_homepage_entries(self):
|
|
581 |
entries = []
|
|
582 |
for entry in self.default_entries:
|
|
583 |
if 'permission' in entry and not self.request.user.has_perm(entry['permission']):
|
|
584 |
continue
|
|
585 |
entries.append(entry)
|
|
586 |
for hook_entries in hooks.call_hooks('manager_homepage_entries', self):
|
|
587 |
if not hasattr(hook_entries, 'append'):
|
|
588 |
hook_entries = [hook_entries]
|
|
589 |
for entry in hook_entries:
|
|
590 |
if 'permission' in entry and not self.request.user.has_perm(entry['permission']):
|
|
591 |
continue
|
|
592 |
entries.append(entry)
|
|
593 |
# use possible key order to sort
|
|
594 |
# list.sort() is supposed to be a stable sort (already sorted entries
|
|
595 |
# are kept in the same order)
|
|
596 |
entries.sort(key=lambda d: d.get('order', 0))
|
|
597 |
return entries
|
|
598 |
|
|
599 |
def get_context_data(self, **kwargs):
|
|
600 |
kwargs['entries'] = self.get_homepage_entries()
|
|
601 |
return super(HomepageView, self).get_context_data(**kwargs)
|
|
602 |
|
550 |
603 |
|
551 |
604 |
homepage = HomepageView.as_view()
|
552 |
605 |
|
553 |
|
-
|