Modify

Opened 7 years ago

Closed 7 years ago

#13342 closed defect (fixed)

Permission restriction not working, anyone can post review

Reported by: ntmlod Owned by: Jun Omae
Priority: normal Component: CodeReviewerPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.0

Description

I have tried to fix it by myself, I add IPermissionRequestor methods so the permissions seems to be complied with from that.
I modify the test that controls the modification of ./changeset page but it's not working.

  • coderev/web_ui.py

     
    4141class CodeReviewerModule(Component):
    4242    """Base component for reviewing changesets."""
    4343
    44     implements(ITemplateProvider, IRequestFilter)
     44    implements(ITemplateProvider, IRequestFilter, IPermissionRequestor)
    4545
    4646    # config options
    4747    statuses = ListOption('codereviewer', 'status_choices',
     
    6868    def get_templates_dirs(self):
    6969        return []
    7070
     71    # IPermissionRequestor methods
     72
     73    def get_permission_actions(self):
     74    return ['CODEREVIEWER_MODIFY']
     75
    7176    # IRequestFilter methods
    7277
    7378    def pre_process_request(self, req, handler):
     
    7681    def post_process_request(self, req, template, data, content_type):
    7782        diff_mode = data and 'changeset' in data and \
    7883                    data['changeset'] is False
    79         if req.path_info.startswith('/changeset') and not diff_mode:
     84        if req.path_info.startswith('/changeset') and not diff_mode and 'CODEREVIEWER_MODIFY' in req.perm:
    8085            changeset = data['changeset']
    8186            repos = changeset.repos
    8287            reponame, rev = repos.reponame, repos.db_rev(changeset.rev)

Attachments (0)

Change History (4)

comment:1 Changed 7 years ago by ntmlod

Stupid mistake, I forgot the import at the beginning.

  • coderev/web_ui.py

     
    1616from trac.admin.api import IAdminCommandProvider
    1717from trac.core import *
    1818from trac.config import ListOption, Option
     19from trac.perm import IPermissionRequestor
    1920from trac.resource import Resource
    2021from trac.util.datefmt import format_datetime, from_utimestamp, \
    2122                              to_utimestamp, user_time
     
    4142class CodeReviewerModule(Component):
    4243    """Base component for reviewing changesets."""
    4344
    44     implements(ITemplateProvider, IRequestFilter)
     45    implements(ITemplateProvider, IRequestFilter, IPermissionRequestor)
    4546
    4647    # config options
    4748    statuses = ListOption('codereviewer', 'status_choices',
     
    6869    def get_templates_dirs(self):
    6970        return []
    7071
     72    # IPermissionRequestor methods
     73
     74    def get_permission_actions(self):
     75    return ['CODEREVIEWER_MODIFY']
     76
    7177    # IRequestFilter methods
    7278
    7379    def pre_process_request(self, req, handler):
     
    7682    def post_process_request(self, req, template, data, content_type):
    7783        diff_mode = data and 'changeset' in data and \
    7884                    data['changeset'] is False
    79         if req.path_info.startswith('/changeset') and not diff_mode:
     85        if req.path_info.startswith('/changeset') and not diff_mode and 'CODEREVIEWER_MODIFY' in req.perm:
    8086            changeset = data['changeset']
    8187            repos = changeset.repos
    8288            reponame, rev = repos.reponame, repos.db_rev(changeset.rev)

Seems to be working now

comment:2 Changed 7 years ago by Jun Omae

I don't think it is needed to implement IPermissionRequestor in CodeReviewerModule because CODEREVIEWER_MODIFY is declared in CodeReviewerSystem.get_permission_actions().

  • codereviewerplugin/1.0/coderev/web_ui.py

    diff --git a/codereviewerplugin/1.0/coderev/web_ui.py b/codereviewerplugin/1.0/coderev/web_ui.py
    index abc9e8f72..dccd818b9 100644
    a b class CodeReviewerModule(Component): 
    7676    def post_process_request(self, req, template, data, content_type):
    7777        diff_mode = data and 'changeset' in data and \
    7878                    data['changeset'] is False
    79         if req.path_info.startswith('/changeset') and not diff_mode:
     79        if req.path_info.startswith('/changeset') and not diff_mode and \
     80                'CODEREVIEWER_MODIFY' in req.perm:
    8081            changeset = data['changeset']
    8182            repos = changeset.repos
    8283            reponame, rev = repos.reponame, repos.db_rev(changeset.rev)

comment:3 in reply to:  2 Changed 7 years ago by ntmlod

Replying to Jun Omae:

I don't think it is needed to implement IPermissionRequestor in CodeReviewerModule because CODEREVIEWER_MODIFY is declared in CodeReviewerSystem.get_permission_actions().

  • codereviewerplugin/1.0/coderev/web_ui.py

    diff --git a/codereviewerplugin/1.0/coderev/web_ui.py b/codereviewerplugin/1.0/coderev/web_ui.py
    index abc9e8f72..dccd818b9 100644
    a b class CodeReviewerModule(Component): 
    7676    def post_process_request(self, req, template, data, content_type):
    7777        diff_mode = data and 'changeset' in data and \
    7878                    data['changeset'] is False
    79         if req.path_info.startswith('/changeset') and not diff_mode:
     79        if req.path_info.startswith('/changeset') and not diff_mode and \
     80                'CODEREVIEWER_MODIFY' in req.perm:
    8081            changeset = data['changeset']
    8182            repos = changeset.repos
    8283            reponame, rev = repos.reponame, repos.db_rev(changeset.rev)

You're right, my proposal was not much enhanced. The additional test is enough.

comment:4 Changed 7 years ago by Jun Omae

Owner: set to Jun Omae
Resolution: fixed
Status: newclosed

In 17013:

CodeReviewerPlugin 1.0.0dev: require CODEREVIEWER_MODIFY action to review (closes #13342)

Initial patch by ntmlod.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.