"Checker" class isn't doing any work, replace with function
authorPaul Crowley <paul@lshift.net>
Sat, 19 Dec 2009 10:46:42 +0000
changeset 241 4af1e1ccf75b
parent 238 4747f2920666
child 242 03d8f07230b3
"Checker" class isn't doing any work, replace with function
src/mercurialserver/access.py
--- a/src/mercurialserver/access.py	Thu Dec 17 16:28:43 2009 +0000
+++ b/src/mercurialserver/access.py	Sat Dec 19 10:46:42 2009 +0000
@@ -16,32 +16,21 @@
 from mercurialserver import ruleset
 from mercurialserver import changes
 
-class Checker(object):
-    '''acl checker.'''
-
-    def __init__(self, ui, repo):
-        self.ui = ui
-        self.repo = repo
-        
-    def allow(self, ctx):
-        branch = ctx.branch()
-        if not ruleset.rules.allow("write", branch=branch, file=None):
+def allow(ctx):
+    branch = ctx.branch()
+    if not ruleset.rules.allow("write", branch=branch, file=None):
+        return False
+    for f in ctx.files():
+        if not ruleset.rules.allow("write", branch=branch, file=f):
             return False
-        for f in ctx.files():
-            if not ruleset.rules.allow("write", branch=branch, file=f):
-                return False
-        return True
-
-    def check(self, ctx):
-        '''return if access allowed, raise exception if not.'''
-        if not self.allow(ctx):
-            raise mercurial.util.Abort(_('%s: access denied for changeset %s') %
-                (__name__, mercurial.node.short(ctx.node())))
+    return True
 
 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
     if hooktype != 'pretxnchangegroup':
         raise mercurial.util.Abort(_('config error - hook type "%s" cannot stop '
                            'incoming changesets') % hooktype)
-    c = Checker(ui, repo)
     for ctx in changes.changes(repo, node):
-        c.check(ctx)
+        if not allow(ctx):
+            raise mercurial.util.Abort(_('%s: access denied for changeset %s') %
+                (__name__, mercurial.node.short(ctx.node())))
+