2011-02-21 03:41:23 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-16 16:30:28 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-02-21 03:41:23 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorProjectProfileEditController
|
2011-02-21 03:41:23 +01:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
2011-06-26 17:37:47 +02:00
|
|
|
$this->id = $data['id'];
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
$project = id(new PhabricatorProject())->load($this->id);
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
2011-06-26 17:37:47 +02:00
|
|
|
$profile = $project->loadProfile();
|
2011-02-21 03:41:23 +01:00
|
|
|
|
|
|
|
if (empty($profile)) {
|
|
|
|
$profile = new PhabricatorProjectProfile();
|
|
|
|
}
|
|
|
|
|
2011-07-19 20:50:15 +02:00
|
|
|
if ($project->getSubprojectPHIDs()) {
|
|
|
|
$phids = $project->getSubprojectPHIDs();
|
|
|
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
|
|
|
->loadHandles();
|
|
|
|
$subprojects = mpull($handles, 'getFullName', 'getPHID');
|
|
|
|
} else {
|
|
|
|
$subprojects = array();
|
|
|
|
}
|
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
$options = PhabricatorProjectStatus::getStatusMap();
|
|
|
|
|
2011-07-16 07:30:55 +02:00
|
|
|
$affiliations = $project->loadAffiliations();
|
|
|
|
$affiliations = mpull($affiliations, null, 'getUserPHID');
|
|
|
|
|
2012-03-14 20:41:33 +01:00
|
|
|
$supported_formats = PhabricatorFile::getTransformableImageFormats();
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$e_name = true;
|
2012-03-14 20:41:33 +01:00
|
|
|
$e_image = null;
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$errors = array();
|
2011-07-16 07:30:55 +02:00
|
|
|
$state = null;
|
2011-02-21 03:41:23 +01:00
|
|
|
if ($request->isFormPost()) {
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 20:58:55 +01:00
|
|
|
|
|
|
|
try {
|
2012-01-24 16:11:37 +01:00
|
|
|
$xactions = array();
|
|
|
|
$xaction = new PhabricatorProjectTransaction();
|
|
|
|
$xaction->setTransactionType(
|
|
|
|
PhabricatorProjectTransactionType::TYPE_NAME);
|
|
|
|
$xaction->setNewValue($request->getStr('name'));
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
|
2012-02-07 23:59:38 +01:00
|
|
|
$xaction = new PhabricatorProjectTransaction();
|
|
|
|
$xaction->setTransactionType(
|
|
|
|
PhabricatorProjectTransactionType::TYPE_STATUS);
|
|
|
|
$xaction->setNewValue($request->getStr('status'));
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 20:58:55 +01:00
|
|
|
$editor = new PhabricatorProjectEditor($project);
|
|
|
|
$editor->setUser($user);
|
2012-01-24 16:11:37 +01:00
|
|
|
$editor->applyTransactions($xactions);
|
Provide wiki pages for projects
Summary:
Provide tighter integration between Projects and Phriction. Partly, I have most
of a rewrite for the Projects homepage ready but it's not currently possible to
publish feed stories about a project so all the feeds are empty/boring. This
partly makes them more useful and partly just provides a tool integration point.
- When you create a project, all the wiki pages in projects/<project_name>/*
are associated with it.
- Publish updates to those pages as being related to the project so they'll
show up in project feeds.
- Show a project link on those pages.
This is very "convention over configuration" but I think it's the right
approach. We could provide some sort of, like, "@project=derp" tag to let you
associated arbitrary pages to projects later, but just letting you move pages is
probably far better.
Test Plan:
- Ran upgrade scripts against stupidly named projects ("der", " der", " der
", "der (2)", " der (2) (2)", etc). Ended up with uniquely named projects.
- Ran unit tests.
- Created /projects/ wiki documents and made sure they displayed correctly.
- Verified feed stories publish as project-related.
- Edited projects, including perfomring a name-colliding edit.
- Created projects, including performing a name-colliding create.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T681
Differential Revision: 1231
2011-12-17 20:58:55 +01:00
|
|
|
} catch (PhabricatorProjectNameCollisionException $ex) {
|
|
|
|
$e_name = 'Not Unique';
|
|
|
|
$errors[] = $ex->getMessage();
|
|
|
|
}
|
|
|
|
|
2011-07-19 20:50:15 +02:00
|
|
|
$project->setSubprojectPHIDs($request->getArr('set_subprojects'));
|
2011-02-21 03:41:23 +01:00
|
|
|
$profile->setBlurb($request->getStr('blurb'));
|
|
|
|
|
|
|
|
if (!strlen($project->getName())) {
|
|
|
|
$e_name = 'Required';
|
|
|
|
$errors[] = 'Project name is required.';
|
|
|
|
} else {
|
|
|
|
$e_name = null;
|
|
|
|
}
|
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
if (!empty($_FILES['image'])) {
|
|
|
|
$err = idx($_FILES['image'], 'error');
|
|
|
|
if ($err != UPLOAD_ERR_NO_FILE) {
|
2011-07-08 06:17:00 +02:00
|
|
|
$file = PhabricatorFile::newFromPHPUpload(
|
|
|
|
$_FILES['image'],
|
|
|
|
array(
|
|
|
|
'authorPHID' => $user->getPHID(),
|
|
|
|
));
|
2011-06-18 10:13:56 +02:00
|
|
|
$okay = $file->isTransformableImage();
|
|
|
|
if ($okay) {
|
2011-06-26 17:37:47 +02:00
|
|
|
$xformer = new PhabricatorImageTransformer();
|
2011-12-17 05:01:38 +01:00
|
|
|
$xformed = $xformer->executeThumbTransform(
|
2011-06-26 17:37:47 +02:00
|
|
|
$file,
|
2011-12-17 05:01:38 +01:00
|
|
|
$x = 50,
|
|
|
|
$y = 50);
|
2011-06-26 17:37:47 +02:00
|
|
|
$profile->setProfileImagePHID($xformed->getPHID());
|
2011-06-18 10:13:56 +02:00
|
|
|
} else {
|
2012-03-14 20:41:33 +01:00
|
|
|
$e_image = 'Not Supported';
|
2011-06-18 10:13:56 +02:00
|
|
|
$errors[] =
|
2012-03-14 20:41:33 +01:00
|
|
|
'This server only supports these image formats: '.
|
|
|
|
implode(', ', $supported_formats).'.';
|
2011-06-18 10:13:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-16 07:30:55 +02:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
if (!$errors) {
|
|
|
|
$project->save();
|
|
|
|
$profile->setProjectPHID($project->getPHID());
|
|
|
|
$profile->save();
|
2011-07-16 07:30:55 +02:00
|
|
|
|
|
|
|
foreach ($delete_affiliations as $affil) {
|
|
|
|
$affil->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($save_affiliations as $save) {
|
|
|
|
$save->setProjectPHID($project->getPHID());
|
|
|
|
$save->save();
|
|
|
|
}
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/project/view/'.$project->getID().'/');
|
2011-07-16 07:30:55 +02:00
|
|
|
} 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(),
|
|
|
|
);
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$error_view = null;
|
|
|
|
if ($errors) {
|
|
|
|
$error_view = new AphrontErrorView();
|
|
|
|
$error_view->setTitle('Form Errors');
|
|
|
|
$error_view->setErrors($errors);
|
|
|
|
}
|
|
|
|
|
2011-06-26 17:37:47 +02:00
|
|
|
$header_name = 'Edit Project';
|
|
|
|
$title = 'Edit Project';
|
|
|
|
$action = '/project/edit/'.$project->getID().'/';
|
2011-02-21 03:41:23 +01:00
|
|
|
|
2011-07-16 07:30:55 +02:00
|
|
|
require_celerity_resource('project-edit-css');
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form
|
2011-07-16 07:30:55 +02:00
|
|
|
->setID('project-edit-form')
|
2011-02-21 03:41:23 +01:00
|
|
|
->setUser($user)
|
|
|
|
->setAction($action)
|
2011-06-18 10:13:56 +02:00
|
|
|
->setEncType('multipart/form-data')
|
2011-02-21 03:41:23 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel('Name')
|
|
|
|
->setName('name')
|
|
|
|
->setValue($project->getName())
|
|
|
|
->setError($e_name))
|
2011-06-18 10:13:56 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel('Project Status')
|
|
|
|
->setName('status')
|
|
|
|
->setOptions($options)
|
|
|
|
->setValue($project->getStatus()))
|
2011-02-21 03:41:23 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
|
|
|
->setLabel('Blurb')
|
|
|
|
->setName('blurb')
|
|
|
|
->setValue($profile->getBlurb()))
|
2011-07-19 20:50:15 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource('/typeahead/common/projects/')
|
|
|
|
->setLabel('Subprojects')
|
|
|
|
->setName('set_subprojects')
|
|
|
|
->setValue($subprojects))
|
2011-06-18 10:13:56 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormFileControl())
|
|
|
|
->setLabel('Change Image')
|
2012-03-14 20:41:33 +01:00
|
|
|
->setName('image')
|
|
|
|
->setError($e_image)
|
|
|
|
->setCaption('Supported formats: '.implode(', ', $supported_formats)))
|
2011-07-16 07:30:55 +02:00
|
|
|
->appendChild(
|
2012-03-16 01:10:19 +01:00
|
|
|
id(new AphrontFormInsetView())
|
|
|
|
->setTitle('Resources')
|
|
|
|
->setRightButton(javelin_render_tag(
|
2011-07-16 07:30:55 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'class' => 'button green',
|
|
|
|
'sigil' => 'add-resource',
|
|
|
|
'mustcapture' => true,
|
|
|
|
),
|
2012-03-16 01:10:19 +01:00
|
|
|
'Add New Resource'))
|
2012-03-20 00:06:52 +01:00
|
|
|
->appendChild(
|
|
|
|
phutil_render_tag(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'resources',
|
|
|
|
'id' => 'resources',
|
|
|
|
)))
|
2012-03-16 01:10:19 +01:00
|
|
|
->setContent(javelin_render_tag(
|
2011-07-16 07:30:55 +02:00
|
|
|
'table',
|
|
|
|
array(
|
|
|
|
'sigil' => 'resources',
|
|
|
|
'class' => 'project-resource-table',
|
|
|
|
),
|
2012-03-16 01:10:19 +01:00
|
|
|
'')))
|
2011-02-21 03:41:23 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2011-06-18 10:13:56 +02:00
|
|
|
->addCancelButton('/project/view/'.$project->getID().'/')
|
2011-02-21 03:41:23 +01:00
|
|
|
->setValue('Save'));
|
|
|
|
|
2011-07-16 07:30:55 +02:00
|
|
|
$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),
|
|
|
|
));
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader($header_name);
|
2011-07-19 20:50:15 +02:00
|
|
|
$panel->setWidth(AphrontPanelView::WIDTH_WIDE);
|
2011-02-21 03:41:23 +01:00
|
|
|
$panel->appendChild($form);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
array(
|
|
|
|
$error_view,
|
|
|
|
$panel,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|