1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-02 09:58:24 +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();
foreach ($projects as $project) {
$member_phids = mpull($project->getAffiliations(), 'getUserPHID');
$member_phids = $project->getMemberPHIDs();
$member_phids = array_values($member_phids);
$result[$project->getPHID()] = array(

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;

View file

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