Make project membership edits use transactions and PHIDs and not be awful

Summary:
  - Split project profile editing apart from project membership editing.
  - Make project membership editing simpler and easier to use.
  - Drop role / owner stuff from the UI.

Test Plan: Added and removed project members. Edited project profile information.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D3184
This commit is contained in:
epriestley
2012-08-07 11:57:38 -07:00
parent f01c89f8de
commit d5a0352fd7
11 changed files with 319 additions and 325 deletions

View File

@@ -41,18 +41,13 @@ final class PhabricatorProjectProfileEditController
$options = PhabricatorProjectStatus::getStatusMap();
$affiliations = $project->loadAffiliations();
$affiliations = mpull($affiliations, null, 'getUserPHID');
$supported_formats = PhabricatorFile::getTransformableImageFormats();
$e_name = true;
$e_image = null;
$errors = array();
$state = null;
if ($request->isFormPost()) {
try {
$xactions = array();
$xaction = new PhabricatorProjectTransaction();
@@ -112,94 +107,12 @@ final class PhabricatorProjectProfileEditController
}
}
$resources = $request->getStr('resources');
$resources = json_decode($resources, true);
if (!is_array($resources)) {
throw new Exception(
"Project resource information was not correctly encoded in the ".
"request.");
}
$state = array();
foreach ($resources as $resource) {
$user_phid = $resource['phid'];
if (!$user_phid) {
continue;
}
if (isset($state[$user_phid])) {
// TODO: We should deal with this better -- the user has entered
// the same resource more than once.
}
$state[$user_phid] = array(
'phid' => $user_phid,
'role' => $resource['role'],
'owner' => $resource['owner'],
);
}
$all_phids = array_merge(array_keys($state), array_keys($affiliations));
$all_phids = array_unique($all_phids);
$delete_affiliations = array();
$save_affiliations = array();
foreach ($all_phids as $phid) {
$old = idx($affiliations, $phid);
$new = idx($state, $phid);
if ($old && !$new) {
$delete_affiliations[] = $affiliations[$phid];
continue;
}
if (!$old) {
$affil = new PhabricatorProjectAffiliation();
$affil->setUserPHID($phid);
} else {
$affil = $old;
}
$affil->setRole((string)$new['role']);
$affil->setIsOwner((int)$new['owner']);
$save_affiliations[] = $affil;
}
if (!$errors) {
$project->save();
$profile->setProjectPHID($project->getPHID());
$profile->save();
foreach ($delete_affiliations as $affil) {
$affil->delete();
}
foreach ($save_affiliations as $save) {
$save->setProjectPHID($project->getPHID());
$save->save();
}
return id(new AphrontRedirectResponse())
->setURI('/project/view/'.$project->getID().'/');
} else {
$phids = array_keys($state);
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
foreach ($state as $phid => $info) {
$state[$phid]['name'] = $handles[$phid]->getFullName();
}
}
} else {
$phids = mpull($affiliations, 'getUserPHID');
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
$state = array();
foreach ($affiliations as $affil) {
$user_phid = $affil->getUserPHID();
$state[] = array(
'phid' => $user_phid,
'name' => $handles[$user_phid]->getFullName(),
'role' => $affil->getRole(),
'owner' => $affil->getIsOwner(),
);
}
}
@@ -214,8 +127,6 @@ final class PhabricatorProjectProfileEditController
$title = 'Edit Project';
$action = '/project/edit/'.$project->getID().'/';
require_celerity_resource('project-edit-css');
$form = new AphrontFormView();
$form
->setID('project-edit-form')
@@ -254,61 +165,26 @@ final class PhabricatorProjectProfileEditController
->setName('image')
->setError($e_image)
->setCaption('Supported formats: '.implode(', ', $supported_formats)))
->appendChild(
id(new AphrontFormInsetView())
->setTitle('Resources')
->setRightButton(javelin_render_tag(
'a',
array(
'href' => '#',
'class' => 'button green',
'sigil' => 'add-resource',
'mustcapture' => true,
),
'Add New Resource'))
->appendChild(
phutil_render_tag(
'input',
array(
'type' => 'hidden',
'name' => 'resources',
'id' => 'resources',
)))
->setContent(javelin_render_tag(
'table',
array(
'sigil' => 'resources',
'class' => 'project-resource-table',
),
'')))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton('/project/view/'.$project->getID().'/')
->setValue('Save'));
$template = new AphrontTokenizerTemplateView();
$template = $template->render();
Javelin::initBehavior(
'projects-resource-editor',
array(
'root' => 'project-edit-form',
'tokenizerTemplate' => $template,
'tokenizerSource' => '/typeahead/common/users/',
'input' => 'resources',
'state' => array_values($state),
));
$panel = new AphrontPanelView();
$panel->setHeader($header_name);
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
$panel->appendChild($form);
return $this->buildStandardPageResponse(
$nav = $this->buildLocalNavigation($project);
$nav->selectFilter('edit');
$nav->appendChild(
array(
$error_view,
$panel,
),
));
return $this->buildStandardPageResponse(
$nav,
array(
'title' => $title,
));