Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to 'per user access rules' #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 73 additions & 31 deletions gitosis/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,98 @@ def haveAccess(config, user, mode, path):
))
path = basename

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()
# First test an explicit '[user %s]' section
log.debug(
'Checking for explicit access for %(user)r as %(mode)r on %(path)r'
% dict(
user=user,
mode=mode,
path=path,
))

mapping = None
try:
repos = config.get('user %s' % user, mode)
except (NoSectionError, NoOptionError):
repos = []
else:
log.debug(
'Found section for %(user)r as %(mode)r = %(repos)r'
% dict(
user=user,
mode=mode,
repos=repos,
))
repos = repos.split()

if path in repos:
mapping = None
groupname = None

if path in repos:
log.debug(
'Access ok for %(user)r as %(mode)r on %(path)r'
'Explicit access ok for %(user)r as %(mode)r on %(path)r'
% dict(
user=user,
mode=mode,
path=path,
))
mapping = path
else:
else:
# then go in old code
for groupname in group.getMembership(config=config, user=user):
try:
mapping = config.get('group %s' % groupname,
'map %s %s' % (mode, path))
repos = config.get('group %s' % groupname, mode)
except (NoSectionError, NoOptionError):
pass
repos = []
else:
repos = repos.split()

mapping = None
if path in repos:
log.debug(
'Access ok for %(user)r as %(mode)r on %(path)r=%(mapping)r'
'Access ok for %(user)r as %(mode)r on %(path)r'
% dict(
user=user,
mode=mode,
path=path,
mapping=mapping,
))
mapping = path
break
else:
try:
mapping = config.get('group %s' % groupname,
'map %s %s' % (mode, path))
except (NoSectionError, NoOptionError):
pass
else:
log.debug(
'Access ok for %(user)r as %(mode)r on %(path)r=%(mapping)r'
% dict(
user=user,
mode=mode,
path=path,
mapping=mapping,
))
break

if mapping is not None:
prefix = None
# If we used a [user _] section, we consider being in the 'gitosis' group
if groupname is None:
groupname = 'gitosis'

if mapping is not None:
prefix = None
try:
prefix = config.get(
'group %s' % groupname, 'repositories')
except (NoSectionError, NoOptionError):
try:
prefix = config.get(
'group %s' % groupname, 'repositories')
prefix = config.get('gitosis', 'repositories')
except (NoSectionError, NoOptionError):
try:
prefix = config.get('gitosis', 'repositories')
except (NoSectionError, NoOptionError):
prefix = 'repositories'
prefix = 'repositories'

log.debug(
'Using prefix %(prefix)r for %(path)r'
% dict(
prefix=prefix,
path=mapping,
))
return (prefix, mapping)
log.debug(
'Using prefix %(prefix)r for %(path)r'
% dict(
prefix=prefix,
path=mapping,
))
return (prefix, mapping)