Tweaks to svn access rights importer

- Make it work with repositories outside of svn.b.o.
  Useful for local debugging.

- Make it aware of svn subpath repository setting.
  So now it's possible to restrict commit rights
  to a subpath in svn repository.

- Make SVN repositories always available for
  read-only access;
This commit is contained in:
2013-11-27 18:26:59 +06:00
parent c3fe33f5a0
commit a03cdacd9e

View File

@@ -4,6 +4,12 @@
$root = dirname(dirname(dirname(__FILE__))); $root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php'; require_once $root.'/scripts/__init_script__.php';
function getSVNRepositoryName($repository) {
$uri = $repository->getRemoteURI();
return preg_replace(
'/https?\:\/\/.*?\/svnroot\/([^\/]+)\/?.*/', '$1', $uri);
}
// Get user's heys and put them to the configuration // Get user's heys and put them to the configuration
function handleSingleUserPHID( function handleSingleUserPHID(
$viewer, $userPHID, $repository, &$authfile, &$access) { $viewer, $userPHID, $repository, &$authfile, &$access) {
@@ -28,13 +34,15 @@ function handleSingleUserPHID(
} }
} }
$uri = $repository->getRemoteURI(); $repository_name = getSVNRepositoryName($repository);
$repository_name = preg_replace(
'/https?\:\/\/svn.blender.org\/svnroot\/([^\/]+)\/?.*/', '$1', $uri); // Store write access settings to current subath
if (!array_key_exists($repository_name, $access)) { $subpath = $repository->getDetail('svn-subpath');
$access[$repository_name] = array(); $repository_pathname = "$repository_name:/$subpath";
if (!array_key_exists($repository_pathname, $access)) {
$access[$repository_pathname] = array();
} }
$access[$repository_name][] = $user_name; $access[$repository_pathname][] = $user_name;
} }
// Parse repository and put it's members to the config file // Parse repository and put it's members to the config file
@@ -47,6 +55,12 @@ function handleSingleRepository(
$pushable = $policies[DiffusionCapabilityPush::CAPABILITY]; $pushable = $policies[DiffusionCapabilityPush::CAPABILITY];
$type = phid_get_type($pushable->getPHID()); $type = phid_get_type($pushable->getPHID());
// Make sure repository is always available for read-only access
$repository_rootpath = getSVNRepositoryName($repository) . ':/';
if (!array_key_exists($repository_rootpath, $access)) {
$access[$repository_rootpath] = array();
}
if ($type == PhabricatorProjectPHIDTypeProject::TYPECONST) { if ($type == PhabricatorProjectPHIDTypeProject::TYPECONST) {
$project = id(new PhabricatorProjectQuery()) $project = id(new PhabricatorProjectQuery())
->setViewer($viewer) ->setViewer($viewer)
@@ -93,12 +107,12 @@ function rebuildConfiguration($what) {
} }
else if ($what == 'ACCESS') { else if ($what == 'ACCESS') {
foreach ($access as $repository => $users) { foreach ($access as $repository => $users) {
print("[$repository:/]\n"); print("[$repository]\n");
foreach ($users as $user) { foreach ($users as $user) {
print("$user = rw\n"); print("$user = rw\n");
} }
print("anonsvn = r\n"); print("anonsvn = r\n");
print("* = r\n"); print("* = r\n\n");
} }
} }
return true; return true;