src/mercurialserver/access.py
author Paul Crowley <paul@lshift.net>
Sat, 19 Dec 2009 10:46:42 +0000
changeset 241 4af1e1ccf75b
parent 77 8d14aac93b5d
child 242 03d8f07230b3
permissions -rw-r--r--
"Checker" class isn't doing any work, replace with function

# Copyright 2008-2009 LShift Ltd
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
#
# Authors:
# Paul Crowley <paul@lshift.net>
# Vadim Gelfer <vadim.gelfer@gmail.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.

from mercurial.i18n import _
import mercurial.util
import mercurial.node

import os
from mercurialserver import ruleset
from mercurialserver import changes

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
    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)
    for ctx in changes.changes(repo, node):
        if not allow(ctx):
            raise mercurial.util.Abort(_('%s: access denied for changeset %s') %
                (__name__, mercurial.node.short(ctx.node())))