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 {
|
|
|
|
|
2012-10-04 23:33:50 +02:00
|
|
|
private $id;
|
|
|
|
|
2011-02-21 03:41:23 +01:00
|
|
|
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();
|
|
|
|
|
2012-08-15 19:44:58 +02:00
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2011-06-26 17:37:47 +02:00
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
2011-02-21 03:41:23 +01:00
|
|
|
}
|
2012-08-15 19:44:58 +02: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();
|
|
|
|
}
|
|
|
|
|
2012-06-26 17:14:15 +02:00
|
|
|
$img_src = $profile->loadProfileImageURI();
|
|
|
|
|
2011-06-18 10:13:56 +02:00
|
|
|
$options = PhabricatorProjectStatus::getStatusMap();
|
|
|
|
|
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();
|
|
|
|
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;
|
|
|
|
|
2012-08-15 19:44:58 +02:00
|
|
|
$xaction = new PhabricatorProjectTransaction();
|
|
|
|
$xaction->setTransactionType(
|
|
|
|
PhabricatorProjectTransactionType::TYPE_CAN_VIEW);
|
|
|
|
$xaction->setNewValue($request->getStr('can_view'));
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
|
|
|
|
$xaction = new PhabricatorProjectTransaction();
|
|
|
|
$xaction->setTransactionType(
|
|
|
|
PhabricatorProjectTransactionType::TYPE_CAN_EDIT);
|
|
|
|
$xaction->setNewValue($request->getStr('can_edit'));
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
|
|
|
|
$xaction = new PhabricatorProjectTransaction();
|
|
|
|
$xaction->setTransactionType(
|
|
|
|
PhabricatorProjectTransactionType::TYPE_CAN_JOIN);
|
|
|
|
$xaction->setNewValue($request->getStr('can_join'));
|
|
|
|
$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-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;
|
|
|
|
}
|
|
|
|
|
2012-06-26 17:14:15 +02:00
|
|
|
$default_image = $request->getExists('default_image');
|
|
|
|
if ($default_image) {
|
|
|
|
$profile->setProfileImagePHID(null);
|
|
|
|
} else if (!empty($_FILES['image'])) {
|
2011-06-18 10:13:56 +02:00
|
|
|
$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-02-21 03:41:23 +01:00
|
|
|
if (!$errors) {
|
|
|
|
$project->save();
|
|
|
|
$profile->setProjectPHID($project->getPHID());
|
|
|
|
$profile->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/project/view/'.$project->getID().'/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
|
|
|
2012-09-13 19:15:08 +02:00
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->setObject($project)
|
|
|
|
->execute();
|
|
|
|
|
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()))
|
2012-08-15 19:44:58 +02:00
|
|
|
->appendChild(
|
|
|
|
'<p class="aphront-form-instructions">NOTE: Policy settings are not '.
|
|
|
|
'yet fully implemented. Some interfaces still ignore these settings, '.
|
|
|
|
'particularly "Visible To".</p>')
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($user)
|
|
|
|
->setName('can_view')
|
|
|
|
->setCaption('Members can always view a project.')
|
|
|
|
->setPolicyObject($project)
|
2012-09-13 19:15:08 +02:00
|
|
|
->setPolicies($policies)
|
2012-08-15 19:44:58 +02:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($user)
|
|
|
|
->setName('can_edit')
|
|
|
|
->setPolicyObject($project)
|
2012-09-13 19:15:08 +02:00
|
|
|
->setPolicies($policies)
|
2012-08-15 19:44:58 +02:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_EDIT))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($user)
|
|
|
|
->setName('can_join')
|
|
|
|
->setCaption(
|
|
|
|
'Users who can edit a project can always join a project.')
|
|
|
|
->setPolicyObject($project)
|
2012-09-13 19:15:08 +02:00
|
|
|
->setPolicies($policies)
|
2012-08-15 19:44:58 +02:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_JOIN))
|
2011-06-18 10:13:56 +02:00
|
|
|
->appendChild(
|
2012-06-26 17:14:15 +02:00
|
|
|
id(new AphrontFormMarkupControl())
|
|
|
|
->setLabel('Profile Image')
|
|
|
|
->setValue(
|
|
|
|
phutil_render_tag(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'src' => $img_src,
|
|
|
|
))))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormImageControl())
|
2011-06-18 10:13:56 +02:00
|
|
|
->setLabel('Change Image')
|
2012-03-14 20:41:33 +01:00
|
|
|
->setName('image')
|
|
|
|
->setError($e_image)
|
|
|
|
->setCaption('Supported formats: '.implode(', ', $supported_formats)))
|
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'));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader($header_name);
|
2012-08-07 20:57:38 +02:00
|
|
|
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
2011-02-21 03:41:23 +01:00
|
|
|
$panel->appendChild($form);
|
|
|
|
|
2012-08-07 20:57:38 +02:00
|
|
|
$nav = $this->buildLocalNavigation($project);
|
|
|
|
$nav->selectFilter('edit');
|
|
|
|
$nav->appendChild(
|
2011-02-21 03:41:23 +01:00
|
|
|
array(
|
|
|
|
$error_view,
|
|
|
|
$panel,
|
2012-08-07 20:57:38 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
$nav,
|
2011-02-21 03:41:23 +01:00
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|