1

Tested with TRAC v 1.0

I stumbled with users can see projects, they don't have access to. I did not wanted them to see only "no permission" on these projects, I simply wanted to hide it completely, when a user don't have the permission to see the project.

Here's a q'n'd "solution", by just moving two lines of code to another place. If some of you need it, just change it as shown below.

Replace:

    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

with:

    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

in simplemultiproject/roadmap.py

Restart your apache web server and you will see only projects you have acess to.

7
  • While your modification can be useful, I guess the format of your question is not the most adequate for this site. You can even post your solution as an answer and accept it, but the "ideal" would be the question posing the problem (e.g.: the users being able to see projects they don't have access to) and the answer providing the solution for it (your modifications to let them see just what they have access to).
    – Claudio
    Mar 18, 2014 at 18:11
  • Mh, I'll think about later. But thanks for your suggestion. If I get you right, you mean asking and answering in two seperate posts, right?
    – Thyrador
    Mar 18, 2014 at 18:14
  • Yes.. this site is intended to work as a question and answer forum. Likewise, you begin with a problem that others might help you solving. Then they might ask you for more details by commenting your question and if they have a solution proposal they post an answer in the "Your answer" box. If you got an answer yourself you can do that too, the question might be useful for others looking to solve the same problem you initially had.
    – Claudio
    Mar 18, 2014 at 18:17
  • That way you can have many answers to the same problem, and you could be surprised by some of them providing much simpler or better solutions than others, which you "reward" by voting the good ones up (users get some reputation points for that) and ultimately choosing the best one, which will get a little higher reputation.
    – Claudio
    Mar 18, 2014 at 18:23
  • 1
    You should consider posting to the trac-users mailing list, where the SimpleMultiProjectPlugin author is active, or opening a ticket. Perhaps he will integrate your change.
    – RjOllos
    Mar 18, 2014 at 18:52

2 Answers 2

1

Well, after a while messing around with this "solution" i ran into a few problems when setting different filters. After looking again into the script, I saw that there just 2 lines needed to be changed.

This is my new and better solution: Just replace the code above with this one.

    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

The according diff is:

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)):
2
  • I'm going to think about this patch and report back soon. Thanks anyway!
    – falkb
    May 6, 2014 at 11:35
  • 1
    @falkb. The consensus on Meta is that the diff is useful, and the one person who disagreed is no longer here. Perhaps add it back?
    – TRiG
    Mar 4, 2019 at 15:01
0

Meanwhile this question is completely outdated and obsolete since the code has completely changed over the years. Please close your question or accept this as answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.