Example #1
0
def home(request):

    panels = [
        SiteSummaryPanel(request),
        UpgradeNotificationPanel(request),
        PagesForModerationPanel(request),
        RecentEditsPanel(request),
    ]

    for fn in hooks.get_hooks('construct_homepage_panels'):
        fn(request, panels)

    root_page = get_explorable_root_page(request.user)
    if root_page:
        root_site = root_page.get_site()
    else:
        root_site = None

    real_site_name = None
    if root_site:
        real_site_name = root_site.site_name if root_site.site_name else root_site.hostname

    return render(request, "tuiuiuadmin/home.html", {
        'root_page': root_page,
        'root_site': root_site,
        'site_name': real_site_name if real_site_name else settings.TUIUIU_SITE_NAME,
        'panels': sorted(panels, key=lambda p: p.order),
        'user': request.user
    })
Example #2
0
    def get_context(self, request):
        context = super(ExplorerMenuItem, self).get_context(request)
        start_page = get_explorable_root_page(request.user)

        if start_page:
            context['start_page_id'] = start_page.id

        return context
Example #3
0
 def test_nonadmin_sees_pages_below_closest_common_ancestor(self):
     User = get_user_model()
     user = User.objects.get(username='******')
     # Josh has permissions for /example-home/content/page-1 and /example-home/other-content,
     # of which the closest common ancestor is /example-home.
     self.assertEqual(get_explorable_root_page(user).id, 4)
     for page in get_pages_with_direct_explore_permission(user):
         self.assertIn(page.id, [6, 8])
Example #4
0
 def test_nonadmin_sees_only_explorable_pages(self):
     # Sam has permissions for /home and /example-home/content/page-1 , of which the closest
     # common ancestor is root; we don't show root in the menu, so the top level will consist
     # of 'home' and 'example-home' (but not the sibling 'home-2', which Sam doesn't have
     # permission on)
     User = get_user_model()
     user = User.objects.get(username='******')
     self.assertEqual(get_explorable_root_page(user).id, 1)
     for page in get_pages_with_direct_explore_permission(user):
         self.assertIn(page.id, [2, 6])
Example #5
0
def explorer_breadcrumb(context, page, include_self=False):
    user = context['request'].user

    # find the closest common ancestor of the pages that this user has direct explore permission
    # (i.e. add/edit/publish/lock) over; this will be the root of the breadcrumb
    cca = get_explorable_root_page(user)
    if not cca:
        return {'pages': Page.objects.none()}

    return {
        'pages':
        page.get_ancestors(inclusive=include_self).descendant_of(
            cca, inclusive=True)
    }
Example #6
0
 def test_nonadmin_with_no_page_perms_cannot_explore(self):
     User = get_user_model()
     user = User.objects.get(username='******')
     self.assertEqual(get_explorable_root_page(user), None)
Example #7
0
 def test_nonadmin_sees_leaf_page_at_root_level(self):
     User = get_user_model()
     user = User.objects.get(username='******')
     self.assertEqual(get_explorable_root_page(user).id, 6)
Example #8
0
 def test_nav_root_for_nonadmin_is_closest_common_ancestor(self):
     User = get_user_model()
     user = User.objects.get(username='******')
     self.assertEqual(get_explorable_root_page(user).id, 2)
Example #9
0
 def test_admins_see_all_pages(self):
     User = get_user_model()
     user = User.objects.get(username='******')
     self.assertEqual(get_explorable_root_page(user).id, 1)