aboutsummaryrefslogtreecommitdiff
path: root/gitosis/access.py
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2007-05-30 13:57:31 +0300
committerTommi Virtanen <tv@eagain.net>2007-06-04 14:16:26 +0300
commitbd1ee4fc013f169f1c052dc763c3e9ed602502c9 (patch)
tree04e054b5fe52efb1e801c4098d44bcc9359433d0 /gitosis/access.py
downloadgitosis-dakkar-bd1ee4fc013f169f1c052dc763c3e9ed602502c9.tar.gz
gitosis-dakkar-bd1ee4fc013f169f1c052dc763c3e9ed602502c9.tar.bz2
gitosis-dakkar-bd1ee4fc013f169f1c052dc763c3e9ed602502c9.zip
Initial import.
Diffstat (limited to 'gitosis/access.py')
-rw-r--r--gitosis/access.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/gitosis/access.py b/gitosis/access.py
new file mode 100644
index 0000000..14280ad
--- /dev/null
+++ b/gitosis/access.py
@@ -0,0 +1,32 @@
+from ConfigParser import NoSectionError, NoOptionError
+
+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' % groupname, mode)
+ except (NoSectionError, NoOptionError):
+ repos = []
+ else:
+ repos = repos.split()
+
+ if path in repos:
+ return path
+
+ try:
+ mapping = config.get('group %s' % groupname,
+ 'map %s %s' % (mode, path))
+ except (NoSectionError, NoOptionError):
+ pass
+ else:
+ return mapping