aboutsummaryrefslogtreecommitdiff
path: root/gitosis/access.py
blob: 14280ad8832e421be3494e8d7d74540cd13e6aa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from ConfigParser import NoSectionErrorNoOptionError
 
from gitosis import group
 
def haveAccess(config, user, mode, path):
    """
    Map request for write access to allowed path.
 
    Note for read-only access, the caller should check for write
    access too.
 
    Returns ``None`` for no access, or the physical repository path
    for access granted to that repository.
    """
    for groupname in group.getMembership(config=config, user=user):
        try:
            repos = config.get('group %s' % groupnamemode)
        except (NoSectionErrorNoOptionError):
            repos = []
        else:
            repos = repos.split()
 
        if path in repos:
            return path
 
        try:
            mapping = config.get('group %s' % groupname,
                                 'map %s %s' % (modepath))
        except (NoSectionErrorNoOptionError):
            pass
        else:
            return mapping