2 from ConfigParser
import NoSectionError
, NoOptionError
4 from gitosis
import group
6 def haveAccess(config
, user
, mode
, path
):
8 Map request for write access to allowed path.
10 Note for read-only access, the caller should check for write
13 Returns ``None`` for no access, or a tuple of toplevel directory
14 containing repositories and a relative path to the physical repository.
16 log
= logging
.getLogger('gitosis.access.haveAccess')
19 'Access check for %(user)r as %(mode)r on %(path)r...'
26 basename
, ext
= os
.path
.splitext(path
)
29 'Stripping .git suffix from %(path)r, new value %(basename)r'
36 sections
= ['group %s' % item
for item
in
37 group
.getMembership(config
=config
, user
=user
)]
38 sections
.insert(0, 'user %s' % user
)
40 for sectname
in sections
:
42 repos
= config
.get(sectname
, mode
)
43 except (NoSectionError
, NoOptionError
):
52 'Access ok for %(user)r as %(mode)r on %(path)r'
61 mapping
= config
.get(sectname
,
62 'map %s %s' % (mode
, path
))
63 except (NoSectionError
, NoOptionError
):
67 'Access ok for %(user)r as %(mode)r on %(path)r=%(mapping)r'
75 if mapping
is not None:
78 prefix
= config
.get(sectname
, 'repositories')
79 except (NoSectionError
, NoOptionError
):
81 prefix
= config
.get('gitosis', 'repositories')
82 except (NoSectionError
, NoOptionError
):
83 prefix
= 'repositories'
86 'Using prefix %(prefix)r for %(path)r'
91 return (prefix
, mapping
)