1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-10 19:34:51 +01:00

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

@ -35,7 +35,7 @@ abstract class ConduitAPI_project_Method extends ConduitAPIMethod {
$result = array(); $result = array();
foreach ($projects as $project) { foreach ($projects as $project) {
$member_phids = mpull($project->getAffiliations(), 'getUserPHID'); $member_phids = $project->getMemberPHIDs();
$member_phids = array_values($member_phids); $member_phids = array_values($member_phids);
$result[$project->getPHID()] = array( $result[$project->getPHID()] = array(

View file

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

View file

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

View file

@ -55,6 +55,14 @@ final class PhabricatorProject extends PhabricatorProjectDAO {
return $profile; return $profile;
} }
public function getMemberPHIDs() {
return mpull($this->getAffiliations(), 'getUserPHID');
}
public function loadMemberPHIDs() {
return mpull($this->loadAffiliations(), 'getUserPHID');
}
public function getAffiliations() { public function getAffiliations() {
if ($this->affiliations === null) { if ($this->affiliations === null) {
throw new Exception('Attach affiliations first!'); throw new Exception('Attach affiliations first!');