gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:30:11 25 4
gpt4 key购买 nike

使用 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 行。

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

    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)):

关于python - 如何在 TRAC simplemultiproject 环境中按权限仅显示可用项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22487520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com