Skip to content

Commit

Permalink
Added new permission CODE_COMMENTS_LIST instead of TRAC_ADMIN. Fixes t…
Browse files Browse the repository at this point in the history
  • Loading branch information
ntesteca committed Sep 10, 2012
1 parent cc9de98 commit a1c0543
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions code_comments/web.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import copy
from trac.core import *
from trac.perm import IPermissionRequestor
from trac.web.chrome import INavigationContributor, ITemplateProvider, add_script, add_script_data, add_stylesheet, add_notice, add_link
from trac.web.main import IRequestHandler, IRequestFilter
from trac.util import Markup
Expand All @@ -19,7 +20,7 @@ class CodeComments(Component):
implements(ITemplateProvider, IRequestFilter)

href = 'code-comments'

# ITemplateProvider methods
def get_templates_dirs(self):
return [self.get_template_dir()]
Expand All @@ -41,14 +42,17 @@ def post_process_request(self, req, template, data, content_type):
return template, data, content_type

class MainNavigation(CodeComments):
implements(INavigationContributor)
implements(INavigationContributor, IPermissionRequestor)

def get_permission_actions(self):
return ['CODE_COMMENTS_LIST']

# INavigationContributor methods
def get_active_navigation_item(self, req):
return self.href

def get_navigation_items(self, req):
if 'TRAC_ADMIN' in req.perm:
if 'CODE_COMMENTS_LIST' in req.perm:
yield 'mainnav', 'code-comments', Markup('<a href="%s">Code Comments</a>' % (
req.href(self.href) ) )

Expand All @@ -73,7 +77,7 @@ def post_process_request(self, req, template, data, content_type):
'templates': self.templates_js_data(),
'active_comment_id': req.args.get('codecomment'),
'username': req.authname,
'is_admin': 'TRAC_ADMIN' in req.perm,
'is_admin': 'CODE_COMMENTS_LIST' in req.perm,
}

original_return_value = template, data, content_type
Expand Down Expand Up @@ -130,7 +134,7 @@ def match_request(self, req):
return req.path_info == '/' + self.href

def process_request(self, req):
req.perm.require('TRAC_ADMIN')
req.perm.require('CODE_COMMENTS_LIST')

self.data = {}
self.args = {}
Expand All @@ -146,7 +150,7 @@ def process_request(self, req):
self.comments = Comments(req, self.env);
self.data['comments'] = self.comments.search(self.args, self.order, self.per_page, self.page, self.order_by)
self.data['reponame'], repos, path = RepositoryManager(self.env).get_repository_by_path('/')
self.data['can_delete'] = 'TRAC_ADMIN' in req.perm
self.data['can_delete'] = 'CODE_COMMENTS_LIST' in req.perm
self.data['paginator'] = self.get_paginator()
self.data['current_sorting_method'] = self.order_by
self.data['current_order'] = self.order
Expand Down Expand Up @@ -219,7 +223,7 @@ def match_request(self, req):
return req.path_info == '/' + self.href

def process_request(self, req):
req.perm.require('TRAC_ADMIN')
req.perm.require('CODE_COMMENTS_LIST')
if 'GET' == req.method:
return self.form(req)
else:
Expand Down

0 comments on commit a1c0543

Please sign in to comment.