如何在TRAC simplemultiproject环境中按权限仅显示可用项目

时间:2014-03-18 18:05:58

标签: python trac

使用TRAC v 1.0进行测试

我偶然发现用户可以看到项目,他们无权访问。我不希望他们在这些项目上只看到“没有许可”,当用户没有权限看到项目时,我只是想完全隐藏它。

这是一个q'n'd“解决方案”,只需将两行代码移动到另一个地方即可。 如果你们中的一些人需要它,只需按照下图所示进行更改。

替换:

    for project_name in sorted(projects.keys()):
        has_access = True
        can_show = True
        if (project_name == "--None Project--"):
            div_project = '<br><div id="project"><fieldset><legend><h2>Unbenanntes Projekt</h2></legend>'
        else:
            project_info = self.__SmpModel.get_project_info(project_name)
            if project_info:
                if hide_closed and project_info[4] > 0: # column 4 of table smp_project tells if project is closed
                    can_show = False
                if self.__SmpModel.is_not_in_restricted_users(req.authname, project_info):
                    has_access = False

            div_project = '<br><div id="project"><fieldset><legend><b>Projekt </b> <em style="font-size: 12pt; color: black;">%s</em></legend>' % project_name
            if can_show and has_access and project_info and show_proj_descr:
                div_project = div_project + '<div class="description" xml:space="preserve">'
                if project_info[2]:
                    div_project = div_project + '%s<br/><br/>' % project_info[2]

                div_project = div_project + '%s</div>' % wiki_to_html(project_info[3], self.env, req)

        div_milestone = ''

        if can_show and len(projects[project_name]) > 0:
            if has_access:
                for milestone in projects[project_name]:
                    mi = '<em>%s</em>' % milestone
                    for i in range(len(div_milestones_array)):
                        if(div_milestones_array[i].find(mi)>0):
                            div_milestone = div_milestone + div_milestones_array[i]
            else:
                div_milestone = '<em style="color: red;">no permission</em>'
            div_project = div_project + to_unicode(div_milestone) + '</fieldset></div>'
            div_projects_milestones = to_unicode(div_projects_milestones + div_project)

    stream_div_projects_milestones = HTML(div_projects_milestones)
    return stream_div_projects_milestones

使用:

    for project_name in sorted(projects.keys()):
        has_access = True
        can_show = True
        project_info = self.__SmpModel.get_project_info(project_name)
        if self.__SmpModel.is_not_in_restricted_users(req.authname, project_info):
            has_access = False

        if has_access:
            if (project_name == "--None Project--"):
                div_project = '<br><div id="project"><fieldset><legend><h2>Unbenanntes Projekt</h2></legend>'
            else:
                if project_info:
                    if hide_closed and project_info[4] > 0: # column 4 of table smp_project tells if project is closed
                        can_show = False                    

                div_project = '<br><div id="project"><fieldset><legend><b>Projekt </b> <em style="font-size: 12pt; color: black;">%s</em></legend>' % project_name
                if can_show and has_access and project_info and show_proj_descr:
                    div_project = div_project + '<div class="description" xml:space="preserve">'
                    if project_info[2]:
                        div_project = div_project + '%s<br/><br/>' % project_info[2]

                    div_project = div_project + '%s</div>' % wiki_to_html(project_info[3], self.env, req)

            div_milestone = ''

            if can_show and len(projects[project_name]) > 0:
                if has_access:
                    for milestone in projects[project_name]:
                        mi = '<em>%s</em>' % milestone
                        for i in range(len(div_milestones_array)):
                            if(div_milestones_array[i].find(mi)>0):
                                div_milestone = div_milestone + div_milestones_array[i]
                else:
                    div_milestone = '<em style="color: red;">no permission</em>'
                div_project = div_project + to_unicode(div_milestone) + '</fieldset></div>'
                div_projects_milestones = to_unicode(div_projects_milestones + div_project)

        stream_div_projects_milestones = HTML(div_projects_milestones)
    return stream_div_projects_milestones
simplemultiproject / roadmap.py

中的

重新启动您的Apache Web服务器,您将只看到您可以访问的项目。

2 个答案:

答案 0 :(得分:1)

好吧,经过一段时间搞乱这个&#34;解决方案&#34;我在设置不同的过滤器时遇到了一些问题。在再次查看脚本之后,我看到只需要更改两行。

这是我新的更好的解决方案: 只需用上面的代码替换上面的代码即可。

    for project_name in sorted(projects.keys()):
        has_access = True
        can_show = True
        if (project_name == "--None Project--"):
            div_project = '<br><div id="project"><fieldset><legend><h2>Unbenanntes Projekt</h2></legend>'
        else:
            project_info = self.__SmpModel.get_project_info(project_name)
            if project_info:
                if hide_closed and project_info[4] > 0: # column 4 of table smp_project tells if project is closed
                    can_show = False
                if self.__SmpModel.is_not_in_restricted_users(req.authname, project_info):
                    has_access = False

            div_project = '<br><div id="project"><fieldset><legend><b>Projekt </b> <em style="font-size: 12pt; color: black;">%s</em></legend>' % project_name
            if can_show and has_access and project_info and show_proj_descr:
                div_project = div_project + '<div class="description" xml:space="preserve">'
                if project_info[2]:
                    div_project = div_project + '%s<br/><br/>' % project_info[2]

                div_project = div_project + '%s</div>' % wiki_to_html(project_info[3], self.env, req)

        div_milestone = ''

        if has_access:            
            if can_show and len(projects[project_name]) > 0:

                for milestone in projects[project_name]:
                    mi = '<em>%s</em>' % milestone
                    for i in range(len(div_milestones_array)):
                        if(div_milestones_array[i].find(mi)>0):
                            div_milestone = div_milestone + div_milestones_array[i]
            else:
                div_milestone = '<em style="color: red;">no permission</em>'
            div_project = div_project + to_unicode(div_milestone) + '</fieldset></div>'
            div_projects_milestones = to_unicode(div_projects_milestones + div_project)

    stream_div_projects_milestones = HTML(div_projects_milestones)
    return stream_div_projects_milestones

相应的差异是:

Index: simplemultiprojectplugin/trunk/simplemultiproject/roadmap.py
===================================================================
--- simplemultiprojectplugin/trunk/simplemultiproject/roadmap.py    (revision 13785)
+++ simplemultiprojectplugin/trunk/simplemultiproject/roadmap.py    (working copy)
@@ -157,8 +157,9 @@

             div_milestone = ''

-            if can_show and len(projects[project_name]) > 0:
-                if has_access:
+            if has_access:            
+                if can_show and len(projects[project_name]) > 0:
+
                     for milestone in projects[project_name]:
                         mi = '<em>%s</em>' % milestone
                         for i in range(len(div_milestones_array)):

答案 1 :(得分:0)

与此同时,由于多年来代码已完全更改,此问题已完全过时且过时。请关闭您的问题或接受它作为答案。