From 32292790b6d13cb97c577a362b292c8e6556d35b Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 13 Oct 2008 14:44:30 +0400 Subject: [PATCH] Extract the code to determine full access info for a repo. It may be useful not only for htaccess generation, but in other parts of the code as well. Signed-off-by: Alexander Gavrilov --- gitosis/access.py | 16 ++++++++++++++++ gitosis/htaccess.py | 12 ++---------- gitosis/test/test_access.py | 13 +++++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/gitosis/access.py b/gitosis/access.py index e6f3149..3427b7d 100644 --- a/gitosis/access.py +++ b/gitosis/access.py @@ -128,3 +128,19 @@ def listAccess(config, mode, path, users, groups): for (iname, ivalue) in config.items(sectname): if ivalue == path and iname.startswith('map %s ' % mode): out_set.add(name) + + +def getAllAccess(config,path,modes=['readonly','writable','writeable']): + """ + Returns access information for a certain repository. + """ + users = set() + groups = set() + for mode in modes: + listAccess(config,mode,path,users,groups) + + all_refs = set(['@'+item for item in groups]) + for grp in groups: + group.listMembers(config,grp,all_refs) + + return (users, groups, all_refs) diff --git a/gitosis/htaccess.py b/gitosis/htaccess.py index 45b251a..7d042f4 100644 --- a/gitosis/htaccess.py +++ b/gitosis/htaccess.py @@ -48,17 +48,9 @@ def write_htaccess(repopath, users, groups): def gen_htaccess(config): for (dirpath, repo, name) in gitdaemon.walk_repos(config): - users = set() - groups = set() - access.listAccess(config,'readonly',name,users,groups) - access.listAccess(config,'writable',name,users,groups) - access.listAccess(config,'writeable',name,users,groups) + (users, groups, all_refs) = access.getAllAccess(config,name) - all_refs = set() - for grp in groups: - group.listMembers(config,grp,all_refs) - - if '@all' in all_refs or 'all' in groups: + if '@all' in all_refs: log.debug('Allow all for %r', name) remove_htaccess(os.path.join(dirpath, repo)) else: diff --git a/gitosis/test/test_access.py b/gitosis/test/test_access.py index 723124e..ef59b06 100644 --- a/gitosis/test/test_access.py +++ b/gitosis/test/test_access.py @@ -176,6 +176,19 @@ def test_list_read(): eq(sorted(groups), ['mooers']) eq(sorted(users), ['jdoe']) +def test_list_all(): + cfg = RawConfigParser() + cfg.add_section('group fooers') + cfg.set('group fooers', 'members', 'jdoe') + cfg.set('group fooers', 'map writable foo/bar', 'baz/quux/thud') + cfg.add_section('group mooers') + cfg.set('group mooers', 'members', '@fooers') + cfg.set('group mooers', 'readonly', 'baz/quux/thud') + (users, groups, all_refs) = access.getAllAccess(cfg,'baz/quux/thud',['readonly']) + eq(sorted(users), []) + eq(sorted(groups), ['mooers']) + eq(sorted(all_refs), ['@fooers','@mooers','jdoe']) + def test_dotgit(): # a .git extension is always allowed to be added cfg = RawConfigParser() -- 2.11.4.GIT