Gitosis sync fixes and improvements

- Fixed some remaining issues caused by the update process.
- Support custom rules for the repositories.
  Currnetly only supports allowing users.
This commit is contained in:
2014-11-10 01:38:58 +05:00
parent fb3c71820b
commit c90665645e

View File

@@ -45,8 +45,8 @@ function handleSingleUserPHID(
return array();
}
$keys = id(new PhabricatorUserSSHKey())->loadAllWhere(
'userPHID = %s',
$keys = id(new PhabricatorAuthSSHKey())->loadAllWhere(
'objectPHID = %s',
$user->getPHID());
$members = array();
@@ -73,6 +73,27 @@ function handleSingleUserPHID(
return $members;
}
function handleCustomPolicy(
$keydir, $viewer, $policy, $system_keys, &$used_keys) {
$members = array();
$rules = $policy->getRules();
foreach ($rules as $rule) {
// Everyone is denied by default anyway
if ($rule['action'] == 'allow') {
if ($rule['rule'] == 'PhabricatorPolicyRuleUsers') {
foreach ($rule['value'] as $userPHID) {
$members = array_merge($members,
handleSingleUserPHID($keydir, $viewer, $userPHID,
$system_keys, $used_keys));
}
} else {
/* pass */
}
}
}
return $members;
}
// Parse repository and put it's members to the config file
function handleSingleRepository(
$keydir, $viewer, $repository, $all_repositories, $system_keys,
@@ -82,11 +103,11 @@ function handleSingleRepository(
$repository);
$pushable = $policies[DiffusionPushCapability::CAPABILITY];
$type = phid_get_type($pushable->getPHID());
$type = $pushable->getType();
$members = array();
if ($type == PhabricatorProjectProjectPHIDType::TYPECONST) {
if ($type == PhabricatorPolicyType::TYPE_PROJECT) {
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->needMembers(true)
@@ -99,11 +120,12 @@ function handleSingleRepository(
handleSingleUserPHID($keydir, $viewer, $memberPHID,
$system_keys, $used_keys));
}
} else if ($type == PhabricatorPeopleUserPHIDType::TYPECONST) {
} else if ($type == PhabricatorPolicyType::TYPE_USER) {
$members = handleSingleUserPHID(
$keydir, $viewer, $pushable->getPHID(), $system_keys, $used_keys);
} else if ($type == PhabricatorPolicyPHIDTypePolicy::TYPECONST) {
/* pass */
} else if ($type == PhabricatorPolicyType::TYPE_CUSTOM) {
$members = handleCustomPolicy(
$keydir, $viewer, $pushable, $system_keys, $used_keys);
} else {
/* pass */
}