author | Mahlon E. Smith <mahlon@martini.nu> |
Wed, 31 Oct 2018 13:22:13 -0700 | |
changeset 378 | a788cfad4cfa |
parent 372 | 80f78674c56e |
permissions | -rw-r--r-- |
242
03d8f07230b3
Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents:
241
diff
changeset
|
1 |
"""Mercurial access control hook""" |
17
4c98440de851
Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
2 |
|
4c98440de851
Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
3 |
from mercurial.i18n import _ |
51 | 4 |
import mercurial.util |
53 | 5 |
import mercurial.node |
17
4c98440de851
Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
6 |
|
4c98440de851
Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
7 |
import os |
67
fd16d9a1234b
Put .py files into a directory of their own
Paul Crowley <paul@lshift.net>
parents:
62
diff
changeset
|
8 |
from mercurialserver import ruleset |
fd16d9a1234b
Put .py files into a directory of their own
Paul Crowley <paul@lshift.net>
parents:
62
diff
changeset
|
9 |
from mercurialserver import changes |
17
4c98440de851
Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
10 |
|
241
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
11 |
def allow(ctx): |
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
12 |
branch = ctx.branch() |
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
13 |
if not ruleset.rules.allow("write", branch=branch, file=None): |
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
14 |
return False |
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
15 |
for f in ctx.files(): |
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
16 |
if not ruleset.rules.allow("write", branch=branch, file=f): |
20
f4daa224dc7e
Add support for locking by branch, and document breaking in.
Paul Crowley <paul@ciphergoth.org>
parents:
18
diff
changeset
|
17 |
return False |
241
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
18 |
return True |
20
f4daa224dc7e
Add support for locking by branch, and document breaking in.
Paul Crowley <paul@ciphergoth.org>
parents:
18
diff
changeset
|
19 |
|
17
4c98440de851
Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
20 |
def hook(ui, repo, hooktype, node=None, source=None, **kwargs): |
4c98440de851
Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
21 |
if hooktype != 'pretxnchangegroup': |
51 | 22 |
raise mercurial.util.Abort(_('config error - hook type "%s" cannot stop ' |
17
4c98440de851
Started work on acl.py replacement - currently broken.
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
23 |
'incoming changesets') % hooktype) |
52
f9eb98bb0791
Encapsulate change finding with backwards compatibility
Paul Crowley <paul@lshift.net>
parents:
51
diff
changeset
|
24 |
for ctx in changes.changes(repo, node): |
241
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
25 |
if not allow(ctx): |
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
26 |
raise mercurial.util.Abort(_('%s: access denied for changeset %s') % |
4af1e1ccf75b
"Checker" class isn't doing any work, replace with function
Paul Crowley <paul@lshift.net>
parents:
77
diff
changeset
|
27 |
(__name__, mercurial.node.short(ctx.node()))) |
372
80f78674c56e
Add support for phases
David Douard <david.douard@logilab.fr>
parents:
311
diff
changeset
|
28 |
|
80f78674c56e
Add support for phases
David Douard <david.douard@logilab.fr>
parents:
311
diff
changeset
|
29 |
def phasehook(ui, repo, hooktype, **kwargs): |
80f78674c56e
Add support for phases
David Douard <david.douard@logilab.fr>
parents:
311
diff
changeset
|
30 |
if hooktype != 'prepushkey': |
80f78674c56e
Add support for phases
David Douard <david.douard@logilab.fr>
parents:
311
diff
changeset
|
31 |
raise mercurial.util.Abort(_('config error - hook type "%s" cannot stop ' |
80f78674c56e
Add support for phases
David Douard <david.douard@logilab.fr>
parents:
311
diff
changeset
|
32 |
'incoming phase changes') % hooktype) |
80f78674c56e
Add support for phases
David Douard <david.douard@logilab.fr>
parents:
311
diff
changeset
|
33 |
if kwargs.get('namespace') == 'phases': |
80f78674c56e
Add support for phases
David Douard <david.douard@logilab.fr>
parents:
311
diff
changeset
|
34 |
if not ruleset.rules.allow("publish"): |
80f78674c56e
Add support for phases
David Douard <david.douard@logilab.fr>
parents:
311
diff
changeset
|
35 |
raise mercurial.util.Abort(_('%s: access denied for making %s public') % |
80f78674c56e
Add support for phases
David Douard <david.douard@logilab.fr>
parents:
311
diff
changeset
|
36 |
(__name__, kwargs['key'][:12])) |