Add getMemberPHIDs() and loadMemberPHIDs() to PhabricatorProject

Summary:
I want to:

  - move the membership storage to edges
  - remove the concepts of "roles" (which are decorative text only) and "owners" (which will be replaced with policy-based controls)

This moves us a step closer to that by reducing the use of ProjectAffiliation outside of the class.

Test Plan: Loaded project profile. Called `project.query`. Joined and left a project.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D3182
This commit is contained in:
epriestley
2012-08-07 11:55:00 -07:00
parent d74b84a729
commit fbf6d967ff
4 changed files with 27 additions and 22 deletions

View File

@@ -41,8 +41,8 @@ final class PhabricatorProjectProfileController
}
$picture = $profile->loadProfileImageURI();
$members = mpull($project->loadAffiliations(), null, 'getUserPHID');
$members = $project->loadMemberPHIDs();
$member_map = array_fill_keys($members, true);
$nav_view = new AphrontSideNavFilterView();
$uri = new PhutilURI('/project/view/'.$project->getID().'/');
@@ -107,7 +107,7 @@ final class PhabricatorProjectProfileController
$header->setProfilePicture($picture);
$action = null;
if (empty($members[$user->getPHID()])) {
if (empty($member_map[$user->getPHID()])) {
$action = phabricator_render_form(
$user,
array(
@@ -211,17 +211,13 @@ final class PhabricatorProjectProfileController
PhabricatorProject $project,
PhabricatorProjectProfile $profile) {
$affiliations = $project->loadAffiliations();
$phids = mpull($affiliations, 'getUserPHID');
$handles = id(new PhabricatorObjectHandleData($phids))
$member_phids = $project->loadMemberPHIDs();
$handles = id(new PhabricatorObjectHandleData($member_phids))
->loadHandles();
$affiliated = array();
foreach ($affiliations as $affiliation) {
$user = $handles[$affiliation->getUserPHID()]->renderLink();
$role = phutil_escape_html($affiliation->getRole());
$affiliated[] = '<li>'.$user.' &mdash; '.$role.'</li>';
foreach ($handles as $phids => $handle) {
$affiliated[] = '<li>'.$handle->renderLink().'</li>';
}
if ($affiliated) {

View File

@@ -53,30 +53,31 @@ final class PhabricatorProjectUpdateController
if ($process_action) {
$xactions = array();
switch ($this->action) {
case 'join':
$affils = $project->loadAffiliations();
$affils = mpull($affils, null, 'getUserPHID');
if (empty($affils[$user->getPHID()])) {
$affils[$user->getPHID()] = true;
$member_phids = $project->loadMemberPHIDs();
$member_map = array_fill_keys($member_phids, true);
if (empty($member_map[$user->getPHID()])) {
$member_map[$user->getPHID()] = true;
$xaction = new PhabricatorProjectTransaction();
$xaction->setTransactionType(
PhabricatorProjectTransactionType::TYPE_MEMBERS);
$xaction->setNewValue(array_keys($affils));
$xaction->setNewValue(array_keys($member_map));
$xactions[] = $xaction;
}
break;
case 'leave':
$affils = $project->loadAffiliations();
$affils = mpull($affils, null, 'getUserPHID');
if (isset($affils[$user->getPHID()])) {
unset($affils[$user->getPHID()]);
$member_phids = $project->loadMemberPHIDs();
$member_map = array_fill_keys($member_phids, true);
if (isset($member_map[$user->getPHID()])) {
unset($member_map[$user->getPHID()]);
$xaction = new PhabricatorProjectTransaction();
$xaction->setTransactionType(
PhabricatorProjectTransactionType::TYPE_MEMBERS);
$xaction->setNewValue(array_keys($affils));
$xaction->setNewValue(array_keys($member_map));
$xactions[] = $xaction;
}
break;