Changeset 388

Show
Ignore:
Timestamp:
01/20/06 13:41:21 (3 years ago)
Author:
puffy
Message:

WikiRbacPatch:

Fix the calling semantics on WikiAuthorizer? so it takes a permission system rather than a request.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wikirbacpatch/0.9/rbac.patch

    r382 r388  
    2424         version = req.args.get('version') 
    2525  
    26 +        self.authz.assert_authorization(req, req.authname, pagename, 'WIKI_VIEW') 
     26+        self.authz.assert_authorization(req.perm, req.authname, pagename, 'WIKI_VIEW') 
    2727         db = self.env.get_db_cnx() 
    2828         page = WikiPage(self.env, pagename, version, db) 
     
    3737+            self.log.debug("PERMISSION: %s", permission) 
    3838+            req.hdf['trac.acl.' + permission] =\ 
    39 +                self.authz.has_authorization(req, req.authname, page.name, permission) 
     39+                self.authz.has_authorization(req.perm, req.authname, page.name, permission) 
    4040         return 'wiki.cs', None 
    4141  
     
    5656-                                               shorten=True) 
    5757-                yield 'wiki', href, title, t, author, comment 
    58 +                if self.authz.has_authorization(req, req.authname, name, 'WIKI_VIEW'): 
     58+                if self.authz.has_authorization(req.perm, req.authname, name, 'WIKI_VIEW'): 
    5959+                    title = '<em>%s</em> edited by %s' % ( 
    6060+                            escape(name), escape(author)) 
     
    7979         else: 
    8080             req.perm.assert_permission('WIKI_DELETE') 
    81 +            self.authz.assert_authorization(req, req.authname, page.name, 'WIKI_DELETE') 
     81+            self.authz.assert_authorization(req.perm, req.authname, page.name, 'WIKI_DELETE') 
    8282  
    8383         if req.args.has_key('cancel'): 
     
    8787         elif not page.exists: 
    8888             req.perm.assert_permission('WIKI_CREATE') 
    89 +            self.authz.assert_authorization(req, req.authname, page.name, 'WIKI_CREATE') 
     89+            self.authz.assert_authorization(req.perm, req.authname, page.name, 'WIKI_CREATE') 
    9090         else: 
    9191             req.perm.assert_permission('WIKI_MODIFY') 
    92 +            self.authz.assert_authorization(req, req.authname, page.name, 'WIKI_MODIFY') 
     92+            self.authz.assert_authorization(req.perm, req.authname, page.name, 'WIKI_MODIFY') 
    9393  
    9494         page.text = req.args.get('text') 
     
    9898         else: 
    9999             req.perm.assert_permission('WIKI_DELETE') 
    100 +            self.authz.assert_authorization(req, req.authname, page.name, 'WIKI_DELETE') 
     100+            self.authz.assert_authorization(req.perm, req.authname, page.name, 'WIKI_DELETE') 
    101101  
    102102         version = None 
     
    106106     def _render_diff(self, req, db, page): 
    107107         req.perm.assert_permission('WIKI_VIEW') 
    108 +        self.authz.assert_authorization(req, req.authname, page.name, 'WIKI_VIEW') 
     108+        self.authz.assert_authorization(req.perm, req.authname, page.name, 'WIKI_VIEW') 
    109109  
    110110         if not page.exists: 
     
    114114     def _render_editor(self, req, db, page, preview=False): 
    115115         req.perm.assert_permission('WIKI_MODIFY') 
    116 +        self.authz.assert_authorization(req, req.authname, page.name, 'WIKI_MODIFY') 
     116+        self.authz.assert_authorization(req.perm, req.authname, page.name, 'WIKI_MODIFY') 
    117117  
    118118         if req.args.has_key('text'): 
     
    122122         """ 
    123123         req.perm.assert_permission('WIKI_VIEW') 
    124 +        self.authz.assert_authorization(req, req.authname, page.name, 'WIKI_VIEW') 
     124+        self.authz.assert_authorization(req.perm, req.authname, page.name, 'WIKI_VIEW') 
    125125  
    126126         if not page.exists: 
     
    130130     def _render_view(self, req, db, page): 
    131131         req.perm.assert_permission('WIKI_VIEW') 
    132 +        self.authz.assert_authorization(req, req.authname, page.name, 'WIKI_VIEW') 
     132+        self.authz.assert_authorization(req.perm, req.authname, page.name, 'WIKI_VIEW') 
    133133  
    134134         if page.name == 'WikiStart': 
     
    140140-            if not req.perm.has_permission('WIKI_CREATE'): 
    141141+            if not req.perm.has_permission('WIKI_CREATE') and\ 
    142 +                self.authz.has_authorization(req, req.authname, page.name, 'WIKI_CREATE'): 
     142+                self.authz.has_authorization(req.perm, req.authname, page.name, 'WIKI_CREATE'): 
    143143                 raise TracError('Page %s not found' % page.name) 
    144144             req.hdf['wiki.page_html'] = '<p>Describe "%s" here</p>' % page.name 
     
    150150-        if req.perm.has_permission('WIKI_MODIFY'): 
    151151+        if req.perm.has_permission('WIKI_MODIFY') and\ 
    152 +            self.authz.has_authorization(req, req.authname, page.name, 'WIKI_MODIFY'): 
     152+            self.authz.has_authorization(req.perm, req.authname, page.name, 'WIKI_MODIFY'): 
    153153             attach_href = self.env.href.attachment('wiki', page.name) 
    154154             req.hdf['wiki.attach_href'] = attach_href 
     
    162162-                   date, author, 
    163163-                   escape(shorten_result(text, query.split()))) 
    164 +            if self.authz.has_authorization(req, name, 'WIKI_VIEW'): 
     164+            if self.authz.has_authorization(req.perm, name, 'WIKI_VIEW'): 
    165165+                yield (self.env.href.wiki(name), 
    166166+                    '%s: %s' % (name, escape(shorten_line(text))), 
     
    170170=================================================================== 
    171171--- rbac.py     (revision 0) 
    172 +++ rbac.py     (revision 85
     172+++ rbac.py     (revision 88
    173173@@ -0,0 +1,82 @@ 
    174174+from trac.core import * 
     
    209209+                       return True 
    210210+ 
    211 +       def has_authorization(self, req, user, path, operation): 
    212 +               if not req.perm.has_permission('WIKI_VIEW'): 
     211+       def has_authorization(self, perm, user, path, operation): 
     212+               if not perm.has_permission('WIKI_VIEW'): 
    213213+                       return False 
    214214+ 
     
    216216+               for provider in self.providers: 
    217217+                       authzed = self._accumulate(authzed, provider.has_authorization(user, path, operation)) 
    218 +               return authzed or req.perm.has_permission('TRAC_ADMIN') 
    219 + 
    220 +       def assert_authorization(self, req, user, path, operation): 
    221 +               if not self.has_authorization(req, user, path, operation): 
     218+               return authzed or perm.has_permission('TRAC_ADMIN') 
     219+ 
     220+       def assert_authorization(self, perm, user, path, operation): 
     221+               if not self.has_authorization(perm, user, path, operation): 
    222222+                       raise PermissionDenied,\ 
    223223+                               '%s authorization on %s is necessary to perform this operation.' % (operation, 'wiki:' + path)