src/mercurialserver/access.py
author Paul Crowley <paul@lshift.net>
Thu, 23 Aug 2012 17:50:02 +0100
changeset 354 70d9be61232d
parent 311 3cbde66305e4
child 372 80f78674c56e
permissions -rw-r--r--
No changes needed to comply with Standards-Version 3.9.3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
242
03d8f07230b3 Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents: 241
diff changeset
     1
"""Mercurial access control hook"""
17
4c98440de851 Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff changeset
     2
4c98440de851 Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff changeset
     3
from mercurial.i18n import _
51
d87eeeae29a5 Use the context API
Paul Crowley <paul@lshift.net>
parents: 50
diff changeset
     4
import mercurial.util
53
853444c5d393 small fix
Paul Crowley <paul@lshift.net>
parents: 52
diff changeset
     5
import mercurial.node
17
4c98440de851 Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff changeset
     6
4c98440de851 Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff changeset
     7
import os
67
fd16d9a1234b Put .py files into a directory of their own
Paul Crowley <paul@lshift.net>
parents: 62
diff changeset
     8
from mercurialserver import ruleset
fd16d9a1234b Put .py files into a directory of their own
Paul Crowley <paul@lshift.net>
parents: 62
diff changeset
     9
from mercurialserver import changes
17
4c98440de851 Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff changeset
    10
241
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    11
def allow(ctx):
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    12
    branch = ctx.branch()
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    13
    if not ruleset.rules.allow("write", branch=branch, file=None):
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    14
        return False
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    15
    for f in ctx.files():
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    16
        if not ruleset.rules.allow("write", branch=branch, file=f):
20
f4daa224dc7e Add support for locking by branch, and document breaking in.
Paul Crowley <paul@ciphergoth.org>
parents: 18
diff changeset
    17
            return False
241
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    18
    return True
20
f4daa224dc7e Add support for locking by branch, and document breaking in.
Paul Crowley <paul@ciphergoth.org>
parents: 18
diff changeset
    19
17
4c98440de851 Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff changeset
    20
def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
4c98440de851 Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff changeset
    21
    if hooktype != 'pretxnchangegroup':
51
d87eeeae29a5 Use the context API
Paul Crowley <paul@lshift.net>
parents: 50
diff changeset
    22
        raise mercurial.util.Abort(_('config error - hook type "%s" cannot stop '
17
4c98440de851 Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff changeset
    23
                           'incoming changesets') % hooktype)
52
f9eb98bb0791 Encapsulate change finding with backwards compatibility
Paul Crowley <paul@lshift.net>
parents: 51
diff changeset
    24
    for ctx in changes.changes(repo, node):
241
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    25
        if not allow(ctx):
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    26
            raise mercurial.util.Abort(_('%s: access denied for changeset %s') %
4af1e1ccf75b "Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents: 77
diff changeset
    27
                (__name__, mercurial.node.short(ctx.node())))