Liferay 仅显示具有 children 的页面

Liferay only show page that have children

我在 Liferay 上使用权限,但遇到了问题。我有这个页面结构:

->Page 1
---->Child page 1
---->Child page 2
---->Child page 3
->Page 2
(...)

每个 child 页面 (1,2,3) 都有不同的权限。我想要的是让 'Page 1' 只对至少有权访问一个 child 页面的用户可见。另一方面,如果用户无权访问任何 child 页面,则该页面不应该可见。

我已经删除了对 'Page 1' 的所有权限,期望它假定 children 权限,但有了这个页面总是不可见的。

我该怎么做才能解决这个问题?

**不完美的解决方案**

好吧,在第 1 页的权限中,我设置为 'visible to all logged users' 并为 child 页面提供了所需的权限,然后我将 navigation.vm 更改为:

<ul id="mainTopMenu">
    ## First Level Generation
    #foreach ($nav_item in $nav_items)

            #if ($nav_item.hasChildren())

                <li>
                    <a> $nav_item.getName()</a>
                    <ul>
                        ## Second Level Generation
                        #foreach ($nav_child in $nav_item.getChildren())
                            <li>            
                                <a href="$nav_child.getURL()">
                                    $nav_child.getName()
                                </a>
                            </li>   
                        #end

                    </ul>
                </li>
    #end
</ul>

此代码的作用是始终显示具有 children 的页面。但这只有在我只有 children 的页面时才有效,但事实并非如此。我有 3 个页面没有 children,所以为了解决这个问题我做了这个 else 声明:

#else
    #set ($str = $nav_item.getURL().substring($nav_item.getURL().lastIndexOf("bc"),$nav_item.getURL().length()))

    #if ($str.equals("bclogin") || $str.equals("bchome") || $str.equals("bcmaintenance"))
        <li>
             <a href="$nav_item.getURL()">
                $nav_item.getName()
             </a>
        </li>
        #end
#end

这解决了我的整个问题。这段代码的唯一问题是我需要指定没有 children 的页面的名称,这不是一个好的原则,因为我每次都需要编辑这段代码 add/remove/edit一页。

我正在努力寻找更好的解决方案,我愿意接受一些想法:)

I've already removed all the permissions to 'Page 1' expecting that it assumes the children permissions but with this the page is always invisible.

您可以将页面和子页面之间的关系视为子文件夹中的文件夹。因此,如果您从文件夹中删除权限,那么......即使您拥有子文件夹的权限,您也不会看到该文件夹​​和子文件夹。

What i want is to make 'Page 1' only visible to users who have at least access to one child page.

我能想到的是,您可以像往常一样拥有 Page 1 的 VIEW 权限,并自定义呈现页面导航的模板。在该模板中,您可以检查每个子页面的权限,即使有一个子页面有权限,您也可以设置一个标志来显示 Page 1,否则不显示。

唯一的缺点是,如果用户直接输入 Page 1 的 URL,他将能够看到 Page 1 内容(如果有的话)。我们也可以阻止它,但我认为使用服务前操作或过滤器挂钩会变得有点乏味。

希望这能让您对这种方法有所了解。

我找到了一种解决方案,但只有在根页面(在我的示例中是第 1 页和第 2 页)没有任何内容并且它们仅提供子页面聚合器时才有效。这是代码:

<ul id="mainTopMenu">
    ## First Level Generation

    #set($layoutLocalServiceUtil = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))

    #foreach ($nav_item in $nav_items)

        #if ($nav_item.hasChildren())

            <li>
                <a> $nav_item.getName()</a>
                <ul>
                    ## Second Level Generation
                    #foreach ($nav_child in $nav_item.getChildren())
                        <li>            
                            <a href="$nav_child.getURL()">
                                $nav_child.getName()
                            </a>
                        </li>   
                    #end
                </ul>
            </li>

        #else

            #set($lay = $layoutLocalServiceUtil.getLayout($nav_item.getLayout().getAncestorPlid()))

            #if (!$lay.hasChildren()) 
                <li>
                    <a href="$nav_item.getURL()">
                        $nav_item.getName()
                    </a>
                </li>
            #end
        #end
    #end
</ul>

为了完成这项工作,我们还需要将第 1 页的权限设置为 'visible to all logged users' 并为子页面提供所需的权限。