##// END OF EJS Templates
acl: support for group definitions in section [acl.groups], which take precedence over OS-level groups
Elifarley Callado Coelho Cruz -
r11114:62714143 default
parent child Browse files
Show More
@@ -145,16 +145,24 b' from mercurial.i18n import _'
145 145 from mercurial import util, match
146 146 import getpass, urllib, grp
147 147
148 def _getusers(group):
148 def _getusers(ui, group):
149
150 # First, try to use group definition from section [acl.groups]
151 hgrcusers = ui.configlist('acl.groups', group)
152 if hgrcusers:
153 return hgrcusers
154
155 ui.debug('acl: "%s" not defined in [acl.groups]\n' % group)
156 # If no users found in group definition, get users from OS-level group
149 157 return grp.getgrnam(group).gr_mem
150 158
151 def _usermatch(user, usersorgroups):
159 def _usermatch(ui, user, usersorgroups):
152 160
153 161 if usersorgroups == '*':
154 162 return True
155 163
156 164 for ug in usersorgroups.replace(',', ' ').split():
157 if user == ug or ug.find('@') == 0 and user in _getusers(ug[1:]):
165 if user == ug or ug.find('@') == 0 and user in _getusers(ui, ug[1:]):
158 166 return True
159 167
160 168 return False
@@ -166,7 +174,7 b' def buildmatch(ui, repo, user, key):'
166 174 return None
167 175
168 176 pats = [pat for pat, users in ui.configitems(key)
169 if _usermatch(user, users)]
177 if _usermatch(ui, user, users)]
170 178 ui.debug('acl: %s enabled, %d entries for user %s\n' %
171 179 (key, len(pats), user))
172 180
@@ -200,7 +208,7 b' def hook(ui, repo, hooktype, node=None, '
200 208
201 209 cfg = ui.config('acl', 'config')
202 210 if cfg:
203 ui.readconfig(cfg, sections = ['acl.allow.branches',
211 ui.readconfig(cfg, sections = ['acl.groups', 'acl.allow.branches',
204 212 'acl.deny.branches', 'acl.allow', 'acl.deny'])
205 213
206 214 allowbranches = buildmatch(ui, None, user, 'acl.allow.branches')
@@ -28,7 +28,13 b' init_config()'
28 28 {
29 29 cat > fakegroups.py <<EOF
30 30 from hgext import acl
31 acl._getusers = lambda x: ["fred", "betty"]
31 def fakegetusers(ui, group):
32 try:
33 return acl._getusersorig(ui, group)
34 except:
35 return ["fred", "betty"]
36 acl._getusersorig = acl._getusers
37 acl._getusers = fakegetusers
32 38 EOF
33 39
34 40 rm -f acl.config
General Comments 0
You need to be logged in to leave comments. Login now