From e0e6ec9117d34c4d6fb56b6579fc9ca28ec987a1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 26 Jun 2011 08:37:47 -0700 Subject: [PATCH] Allow affiliations to carry project ownership information; transform profile images correctly Summary: This is sort of doing two things at once: - Add an "isOwner" flag to Project Affiliation to lay the groundwork for T237. - Rename the "QuickCreate" workflow to "Create" and funnel all creation through it. - Reorganize the image transformation stuff and use it to correctly crop/resize uploaded images. Test Plan: Created and edited projects and affailiations. Uploaded project, user, and profile photos. Verified existing thumbnailing in Maniphest still works properly. Reviewed By: cadamo Reviewers: cadamo, aran, jungejason, tuomaspelkonen CC: aran, epriestley, cadamo Differential Revision: 529 --- resources/sql/patches/049.projectowner.sql | 2 + src/__phutil_library_map__.php | 5 +- ...AphrontDefaultApplicationConfiguration.php | 4 +- .../PhabricatorFileTransformController.php | 59 +-------- .../files/controller/transform/__init__.php | 1 + .../transform/PhabricatorImageTransformer.php | 125 ++++++++++++++++++ src/applications/files/transform/__init__.php | 12 ++ .../taskedit/ManiphestTaskEditController.php | 4 +- ...PhabricatorPeopleProfileEditController.php | 8 +- .../controller/profileedit/__init__.php | 3 +- .../PhabricatorUserSettingsController.php | 12 +- .../people/controller/settings/__init__.php | 1 + .../PhabricatorProjectCreateController.php} | 84 +++++++++--- .../{quickcreate => create}/__init__.php | 7 +- ...icatorProjectAffiliationEditController.php | 7 +- .../list/PhabricatorProjectListController.php | 2 +- ...habricatorProjectProfileEditController.php | 40 +++--- .../controller/profileedit/__init__.php | 1 + .../PhabricatorProjectAffiliation.php | 3 +- 19 files changed, 266 insertions(+), 114 deletions(-) create mode 100644 resources/sql/patches/049.projectowner.sql create mode 100644 src/applications/files/transform/PhabricatorImageTransformer.php create mode 100644 src/applications/files/transform/__init__.php rename src/applications/project/controller/{quickcreate/PhabricatorProjectQuickCreateController.php => create/PhabricatorProjectCreateController.php} (51%) rename src/applications/project/controller/{quickcreate => create}/__init__.php (69%) diff --git a/resources/sql/patches/049.projectowner.sql b/resources/sql/patches/049.projectowner.sql new file mode 100644 index 0000000000..56af7474bf --- /dev/null +++ b/resources/sql/patches/049.projectowner.sql @@ -0,0 +1,2 @@ +ALTER TABLE phabricator_project.project_affiliation + ADD isOwner bool NOT NULL; \ No newline at end of file diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 5bddbe16c0..6d599a312f 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -354,6 +354,7 @@ phutil_register_library_map(array( 'PhabricatorIRCMessage' => 'infrastructure/daemon/irc/message', 'PhabricatorIRCObjectNameHandler' => 'infrastructure/daemon/irc/handler/objectname', 'PhabricatorIRCProtocolHandler' => 'infrastructure/daemon/irc/handler/protocol', + 'PhabricatorImageTransformer' => 'applications/files/transform', 'PhabricatorJavelinLinter' => 'infrastructure/lint/linter/javelin', 'PhabricatorLintEngine' => 'infrastructure/lint/engine', 'PhabricatorLiskDAO' => 'applications/base/storage/lisk', @@ -428,12 +429,12 @@ phutil_register_library_map(array( 'PhabricatorProjectAffiliation' => 'applications/project/storage/affiliation', 'PhabricatorProjectAffiliationEditController' => 'applications/project/controller/editaffiliation', 'PhabricatorProjectController' => 'applications/project/controller/base', + 'PhabricatorProjectCreateController' => 'applications/project/controller/create', 'PhabricatorProjectDAO' => 'applications/project/storage/base', 'PhabricatorProjectListController' => 'applications/project/controller/list', 'PhabricatorProjectProfile' => 'applications/project/storage/profile', 'PhabricatorProjectProfileController' => 'applications/project/controller/profile', 'PhabricatorProjectProfileEditController' => 'applications/project/controller/profileedit', - 'PhabricatorProjectQuickCreateController' => 'applications/project/controller/quickcreate', 'PhabricatorProjectStatus' => 'applications/project/constants/status', 'PhabricatorProjectTransactionSearch' => 'applications/project/transactions/search', 'PhabricatorRedirectController' => 'applications/base/controller/redirect', @@ -900,12 +901,12 @@ phutil_register_library_map(array( 'PhabricatorProjectAffiliation' => 'PhabricatorProjectDAO', 'PhabricatorProjectAffiliationEditController' => 'PhabricatorProjectController', 'PhabricatorProjectController' => 'PhabricatorController', + 'PhabricatorProjectCreateController' => 'PhabricatorProjectController', 'PhabricatorProjectDAO' => 'PhabricatorLiskDAO', 'PhabricatorProjectListController' => 'PhabricatorProjectController', 'PhabricatorProjectProfile' => 'PhabricatorProjectDAO', 'PhabricatorProjectProfileController' => 'PhabricatorProjectController', 'PhabricatorProjectProfileEditController' => 'PhabricatorProjectController', - 'PhabricatorProjectQuickCreateController' => 'PhabricatorProjectController', 'PhabricatorRedirectController' => 'PhabricatorController', 'PhabricatorRemarkupRuleDifferential' => 'PhabricatorRemarkupRuleObjectName', 'PhabricatorRemarkupRuleDiffusion' => 'PhutilRemarkupRule', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index 42ff0a847c..a76b31a783 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -198,12 +198,12 @@ class AphrontDefaultApplicationConfiguration '/project/' => array( '$' => 'PhabricatorProjectListController', - 'edit/(?:(?P\d+)/)?$' => 'PhabricatorProjectProfileEditController', + 'edit/(?P\d+)/$' => 'PhabricatorProjectProfileEditController', 'view/(?P\d+)/(?:(?P\w+)/)?$' => 'PhabricatorProjectProfileController', 'affiliation/(?P\d+)/$' => 'PhabricatorProjectAffiliationEditController', - 'quickcreate/$' => 'PhabricatorProjectQuickCreateController', + 'create/$' => 'PhabricatorProjectCreateController', ), '/r(?P[A-Z]+)(?P[a-z0-9]+)$' diff --git a/src/applications/files/controller/transform/PhabricatorFileTransformController.php b/src/applications/files/controller/transform/PhabricatorFileTransformController.php index 7f3a42253d..c2b777233d 100644 --- a/src/applications/files/controller/transform/PhabricatorFileTransformController.php +++ b/src/applications/files/controller/transform/PhabricatorFileTransformController.php @@ -56,9 +56,6 @@ class PhabricatorFileTransformController extends PhabricatorFileController { case 'thumb-60x45': $xformed_file = $this->executeThumbTransform($file, 60, 45); break; - case 'profile-50x50': - $xformed_file = $this->executeProfile50x50Transform($file); - break; default: return new Aphront400Response(); } @@ -118,61 +115,9 @@ class PhabricatorFileTransformController extends PhabricatorFileController { PhabricatorFileURI::getViewURIForPHID($xform->getTransformedPHID())); } - private function executeProfile50x50Transform(PhabricatorFile $file) { - $data = $file->loadFileData(); - $jpeg = $this->crudelyScaleTo($data, 50, 50); - - return PhabricatorFile::newFromFileData($jpeg, array( - 'name' => 'profile-'.$file->getName(), - )); - } - private function executeThumbTransform(PhabricatorFile $file, $x, $y) { - $data = $file->loadFileData(); - $jpeg = $this->crudelyScaleTo($data, $x, $y); - return PhabricatorFile::newFromFileData($jpeg, array( - 'name' => 'thumb-'.$file->getName(), - )); - } - - /** - * Very crudely scale an image up or down to an exact size. - */ - private function crudelyScaleTo($data, $dx, $dy) { - $src = imagecreatefromstring($data); - $x = imagesx($src); - $y = imagesy($src); - - $scale = min($x / $dx, $y / $dy); - $dst = imagecreatetruecolor($dx, $dy); - - imagecopyresampled( - $dst, - $src, - 0, 0, - 0, 0, - $dx, $dy, - $scale * $dx, $scale * $dy); - - $img = null; - - if (function_exists('imagejpeg')) { - ob_start(); - imagejpeg($dst); - $img = ob_get_clean(); - } else if (function_exists('imagepng')) { - ob_start(); - imagepng($dst); - $img = ob_get_clean(); - } else if (function_exists('imagegif')) { - ob_start(); - imagegif($dst); - $img = ob_get_clean(); - } else { - throw new Exception("No image generation functions exist!"); - } - - return $img; + $xformer = new PhabricatorImageTransformer(); + return $xformer->executeThumbTransform($file, $x, $y); } } diff --git a/src/applications/files/controller/transform/__init__.php b/src/applications/files/controller/transform/__init__.php index ee7607aff0..296cae409a 100644 --- a/src/applications/files/controller/transform/__init__.php +++ b/src/applications/files/controller/transform/__init__.php @@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'applications/files/controller/base'); phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/files/storage/transformed'); +phutil_require_module('phabricator', 'applications/files/transform'); phutil_require_module('phabricator', 'applications/files/uri'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/files/transform/PhabricatorImageTransformer.php b/src/applications/files/transform/PhabricatorImageTransformer.php new file mode 100644 index 0000000000..1919e9c4de --- /dev/null +++ b/src/applications/files/transform/PhabricatorImageTransformer.php @@ -0,0 +1,125 @@ +loadFileData(); + $image = $this->crudelyScaleTo($data, $x, $y); + + return PhabricatorFile::newFromFileData( + $image, + array( + 'name' => 'thumb-'.$file->getName(), + )); + } + + public function executeProfileTransform( + PhabricatorFile $file, + $x, + $min_y, + $max_y) { + + $data = $file->loadFileData(); + $image = $this->crudelyCropTo($data, $x, $min_y, $max_y); + + return PhabricatorFile::newFromFileData( + $image, + array( + 'name' => 'profile-'.$file->getName(), + )); + } + + private function crudelyCropTo($data, $x, $min_y, $max_y) { + $img = imagecreatefromstring($data); + $sx = imagesx($img); + $sy = imagesy($img); + + $scaled_y = ($x / $sx) * $sy; + if ($scaled_y > $max_y) { + // This image is very tall and thin. + $scaled_y = $max_y; + } else if ($scaled_y < $min_y) { + // This image is very short and wide. + $scaled_y = $min_y; + } + + $img = $this->applyScaleTo( + $img, + $x, + $scaled_y); + + return $this->saveImageDataInAnyFormat($img); + } + + /** + * Very crudely scale an image up or down to an exact size. + */ + private function crudelyScaleTo($data, $dx, $dy) { + $src = imagecreatefromstring($data); + + $dst = $this->applyScaleTo($src, $dx, $dy); + + return $this->saveImageDataInAnyFormat($dst); + } + + private function applyScaleTo($src, $dx, $dy) { + $x = imagesx($src); + $y = imagesy($src); + + $scale = min($x / $dx, $y / $dy); + $dst = imagecreatetruecolor($dx, $dy); + + imagecopyresampled( + $dst, + $src, + 0, 0, + 0, 0, + $dx, $dy, + $scale * $dx, $scale * $dy); + + return $dst; + } + + private function saveImageDataInAnyFormat($data) { + $img = null; + + if (function_exists('imagejpeg')) { + ob_start(); + imagejpeg($data); + $img = ob_get_clean(); + } else if (function_exists('imagepng')) { + ob_start(); + imagepng($data); + $img = ob_get_clean(); + } else if (function_exists('imagegif')) { + ob_start(); + imagegif($data); + $img = ob_get_clean(); + } else { + throw new Exception("No image generation functions exist!"); + } + + return $img; + } + +} diff --git a/src/applications/files/transform/__init__.php b/src/applications/files/transform/__init__.php new file mode 100644 index 0000000000..22c7880540 --- /dev/null +++ b/src/applications/files/transform/__init__.php @@ -0,0 +1,12 @@ + '/project/quickcreate/', + 'href' => '/project/create/', 'mustcapture' => true, 'sigil' => 'project-create', ), 'Create New Project')) ->setDatasource('/typeahead/common/projects/')); + require_celerity_resource('aphront-error-view-css'); + Javelin::initBehavior('maniphest-project-create', array( 'tokenizerID' => $project_tokenizer_id, )); diff --git a/src/applications/people/controller/profileedit/PhabricatorPeopleProfileEditController.php b/src/applications/people/controller/profileedit/PhabricatorPeopleProfileEditController.php index 5b7ec23d31..48e3db955e 100644 --- a/src/applications/people/controller/profileedit/PhabricatorPeopleProfileEditController.php +++ b/src/applications/people/controller/profileedit/PhabricatorPeopleProfileEditController.php @@ -43,7 +43,13 @@ class PhabricatorPeopleProfileEditController $file = PhabricatorFile::newFromPHPUpload($_FILES['image']); $okay = $file->isTransformableImage(); if ($okay) { - $profile->setProfileImagePHID($file->getPHID()); + $xformer = new PhabricatorImageTransformer(); + $xformed = $xformer->executeProfileTransform( + $file, + $width = 280, + $min_height = 140, + $max_height = 420); + $profile->setProfileImagePHID($xformed->getPHID()); } else { $errors[] = 'Only valid image files (jpg, jpeg, png or gif) '. diff --git a/src/applications/people/controller/profileedit/__init__.php b/src/applications/people/controller/profileedit/__init__.php index 0a37dee920..fdfc29408f 100644 --- a/src/applications/people/controller/profileedit/__init__.php +++ b/src/applications/people/controller/profileedit/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'applications/files/storage/file'); +phutil_require_module('phabricator', 'applications/files/transform'); phutil_require_module('phabricator', 'applications/people/controller/base'); phutil_require_module('phabricator', 'applications/people/storage/profile'); phutil_require_module('phabricator', 'view/form/base'); @@ -21,4 +22,4 @@ phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phutil', 'utils'); -phutil_require_source('PhabricatorPeopleProfileEditController.php'); \ No newline at end of file +phutil_require_source('PhabricatorPeopleProfileEditController.php'); diff --git a/src/applications/people/controller/settings/PhabricatorUserSettingsController.php b/src/applications/people/controller/settings/PhabricatorUserSettingsController.php index d00ed87e66..09e43cf39f 100644 --- a/src/applications/people/controller/settings/PhabricatorUserSettingsController.php +++ b/src/applications/people/controller/settings/PhabricatorUserSettingsController.php @@ -119,9 +119,14 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController { if ($err != UPLOAD_ERR_NO_FILE) { $file = PhabricatorFile::newFromPHPUpload($_FILES['profile']); $okay = $file->isTransformableImage(); - if ($okay) { - $user->setProfileImagePHID($file->getPHID()); + $xformer = new PhabricatorImageTransformer(); + $xformed = $xformer->executeProfileTransform( + $file, + $width = 50, + $min_height = 50, + $max_height = 50); + $user->setProfileImagePHID($xformed->getPHID()); } else { $errors[] = 'Only valid image files (jpg, jpeg, png or gif) '. @@ -339,8 +344,7 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController { ->appendChild( id(new AphrontFormFileControl()) ->setLabel('Change Image') - ->setName('profile') - ->setCaption('Upload a 50x50px image.')) + ->setName('profile')) ->appendChild( id(new AphrontFormMarkupControl()) ->setValue('
')) diff --git a/src/applications/people/controller/settings/__init__.php b/src/applications/people/controller/settings/__init__.php index 1a952ff9c4..b85ec56b52 100644 --- a/src/applications/people/controller/settings/__init__.php +++ b/src/applications/people/controller/settings/__init__.php @@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'aphront/response/dialog'); phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'applications/auth/oauth/provider/base'); phutil_require_module('phabricator', 'applications/files/storage/file'); +phutil_require_module('phabricator', 'applications/files/transform'); phutil_require_module('phabricator', 'applications/files/uri'); phutil_require_module('phabricator', 'applications/people/controller/base'); phutil_require_module('phabricator', 'applications/people/storage/user'); diff --git a/src/applications/project/controller/quickcreate/PhabricatorProjectQuickCreateController.php b/src/applications/project/controller/create/PhabricatorProjectCreateController.php similarity index 51% rename from src/applications/project/controller/quickcreate/PhabricatorProjectQuickCreateController.php rename to src/applications/project/controller/create/PhabricatorProjectCreateController.php index e4e2c1796e..f4c8560f12 100644 --- a/src/applications/project/controller/quickcreate/PhabricatorProjectQuickCreateController.php +++ b/src/applications/project/controller/create/PhabricatorProjectCreateController.php @@ -16,7 +16,7 @@ * limitations under the License. */ -class PhabricatorProjectQuickCreateController +class PhabricatorProjectCreateController extends PhabricatorProjectController { @@ -28,13 +28,14 @@ class PhabricatorProjectQuickCreateController $project = new PhabricatorProject(); $project->setAuthorPHID($user->getPHID()); $profile = new PhabricatorProjectProfile(); - $options = PhabricatorProjectStatus::getStatusMap(); $e_name = true; $errors = array(); if ($request->isFormPost()) { $project->setName($request->getStr('name')); + $project->setStatus(PhabricatorProjectStatus::ONGOING); + $profile->setBlurb($request->getStr('blurb')); if (!strlen($project->getName())) { @@ -49,11 +50,23 @@ class PhabricatorProjectQuickCreateController $profile->setProjectPHID($project->getPHID()); $profile->save(); - return id(new AphrontAjaxResponse()) - ->setContent(array( - 'phid' => $project->getPHID(), - 'name' => $project->getName(), - )); + id(new PhabricatorProjectAffiliation()) + ->setUserPHID($user->getPHID()) + ->setProjectPHID($project->getPHID()) + ->setRole('Owner') + ->setIsOwner(true) + ->save(); + + if ($request->isAjax()) { + return id(new AphrontAjaxResponse()) + ->setContent(array( + 'phid' => $project->getPHID(), + 'name' => $project->getName(), + )); + } else { + return id(new AphrontRedirectResponse()) + ->setURI('/project/view/'.$project->getID().'/'); + } } } @@ -61,11 +74,17 @@ class PhabricatorProjectQuickCreateController if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Form Errors'); - $error_view->setWidth(AphrontErrorView::WIDTH_DIALOG); $error_view->setErrors($errors); } - $form = id(new AphrontFormLayoutView()) + if ($request->isAjax()) { + $form = new AphrontFormLayoutView(); + } else { + $form = new AphrontFormView(); + $form->setUser($user); + } + + $form ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Name') @@ -79,15 +98,44 @@ class PhabricatorProjectQuickCreateController ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT) ->setValue($profile->getBlurb())); - $dialog = id(new AphrontDialogView()) - ->setUser($user) - ->setWidth(AphrontDialogView::WIDTH_FORM) - ->setTitle('Create a New Project') - ->appendChild($error_view) - ->appendChild($form) - ->addSubmitButton('Create Project') - ->addCancelButton('/project/'); + if ($request->isAjax()) { - return id(new AphrontDialogResponse())->setDialog($dialog); + if ($error_view) { + $error_view->setWidth(AphrontErrorView::WIDTH_DIALOG); + } + + $dialog = id(new AphrontDialogView()) + ->setUser($user) + ->setWidth(AphrontDialogView::WIDTH_FORM) + ->setTitle('Create a New Project') + ->appendChild($error_view) + ->appendChild($form) + ->addSubmitButton('Create Project') + ->addCancelButton('/project/'); + + return id(new AphrontDialogResponse())->setDialog($dialog); + } else { + + $form + ->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue('Create') + ->addCancelButton('/project/')); + + $panel = new AphrontPanelView(); + $panel + ->setWidth(AphrontPanelView::WIDTH_FORM) + ->setHeader('Create a New Project') + ->appendChild($form); + + return $this->buildStandardPageResponse( + array( + $error_view, + $panel, + ), + array( + 'title' => 'Create new Project', + )); + } } } diff --git a/src/applications/project/controller/quickcreate/__init__.php b/src/applications/project/controller/create/__init__.php similarity index 69% rename from src/applications/project/controller/quickcreate/__init__.php rename to src/applications/project/controller/create/__init__.php index 3e33f41148..e9d5874a69 100644 --- a/src/applications/project/controller/quickcreate/__init__.php +++ b/src/applications/project/controller/create/__init__.php @@ -8,17 +8,22 @@ phutil_require_module('phabricator', 'aphront/response/ajax'); phutil_require_module('phabricator', 'aphront/response/dialog'); +phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'applications/project/constants/status'); phutil_require_module('phabricator', 'applications/project/controller/base'); +phutil_require_module('phabricator', 'applications/project/storage/affiliation'); phutil_require_module('phabricator', 'applications/project/storage/profile'); phutil_require_module('phabricator', 'applications/project/storage/project'); phutil_require_module('phabricator', 'view/dialog'); +phutil_require_module('phabricator', 'view/form/base'); +phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/text'); phutil_require_module('phabricator', 'view/form/control/textarea'); phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/form/layout'); +phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phutil', 'utils'); -phutil_require_source('PhabricatorProjectQuickCreateController.php'); +phutil_require_source('PhabricatorProjectCreateController.php'); diff --git a/src/applications/project/controller/editaffiliation/PhabricatorProjectAffiliationEditController.php b/src/applications/project/controller/editaffiliation/PhabricatorProjectAffiliationEditController.php index 4dffe20957..9c53b63e35 100644 --- a/src/applications/project/controller/editaffiliation/PhabricatorProjectAffiliationEditController.php +++ b/src/applications/project/controller/editaffiliation/PhabricatorProjectAffiliationEditController.php @@ -52,7 +52,12 @@ class PhabricatorProjectAffiliationEditController if (!strlen($affiliation->getRole())) { if ($affiliation->getID()) { - $affiliation->delete(); + if ($affiliation->getIsOwner()) { + $affiliation->setRole('Owner'); + $affiliation->save(); + } else { + $affiliation->delete(); + } } } else { $affiliation->save(); diff --git a/src/applications/project/controller/list/PhabricatorProjectListController.php b/src/applications/project/controller/list/PhabricatorProjectListController.php index 852e5868c7..ba825511ee 100644 --- a/src/applications/project/controller/list/PhabricatorProjectListController.php +++ b/src/applications/project/controller/list/PhabricatorProjectListController.php @@ -121,7 +121,7 @@ class PhabricatorProjectListController $panel = new AphrontPanelView(); $panel->appendChild($table); $panel->setHeader('Project'); - $panel->setCreateButton('Create New Project', '/project/edit/'); + $panel->setCreateButton('Create New Project', '/project/create/'); return $this->buildStandardPageResponse( $panel, diff --git a/src/applications/project/controller/profileedit/PhabricatorProjectProfileEditController.php b/src/applications/project/controller/profileedit/PhabricatorProjectProfileEditController.php index 20cc2dfd6e..cef8edb283 100644 --- a/src/applications/project/controller/profileedit/PhabricatorProjectProfileEditController.php +++ b/src/applications/project/controller/profileedit/PhabricatorProjectProfileEditController.php @@ -19,10 +19,8 @@ class PhabricatorProjectProfileEditController extends PhabricatorProjectController { - private $id; - public function willProcessRequest(array $data) { - $this->id = idx($data, 'id'); + $this->id = $data['id']; } public function processRequest() { @@ -30,16 +28,11 @@ class PhabricatorProjectProfileEditController $request = $this->getRequest(); $user = $request->getUser(); - if ($this->id) { - $project = id(new PhabricatorProject())->load($this->id); - if (!$project) { - return new Aphront404Response(); - } - $profile = $project->loadProfile(); - } else { - $project = new PhabricatorProject(); - $project->setAuthorPHID($user->getPHID()); + $project = id(new PhabricatorProject())->load($this->id); + if (!$project) { + return new Aphront404Response(); } + $profile = $project->loadProfile(); if (empty($profile)) { $profile = new PhabricatorProjectProfile(); @@ -67,7 +60,13 @@ class PhabricatorProjectProfileEditController $file = PhabricatorFile::newFromPHPUpload($_FILES['image']); $okay = $file->isTransformableImage(); if ($okay) { - $profile->setProfileImagePHID($file->getPHID()); + $xformer = new PhabricatorImageTransformer(); + $xformed = $xformer->executeProfileTransform( + $file, + $width = 280, + $min_height = 140, + $max_height = 420); + $profile->setProfileImagePHID($xformed->getPHID()); } else { $errors[] = 'Only valid image files (jpg, jpeg, png or gif) '. @@ -92,15 +91,9 @@ class PhabricatorProjectProfileEditController $error_view->setErrors($errors); } - if ($project->getID()) { - $header_name = 'Edit Project'; - $title = 'Edit Project'; - $action = '/project/edit/'.$project->getID().'/'; - } else { - $header_name = 'Create Project'; - $title = 'Create Project'; - $action = '/project/edit/'; - } + $header_name = 'Edit Project'; + $title = 'Edit Project'; + $action = '/project/edit/'.$project->getID().'/'; $form = new AphrontFormView(); $form @@ -127,8 +120,7 @@ class PhabricatorProjectProfileEditController ->appendChild( id(new AphrontFormFileControl()) ->setLabel('Change Image') - ->setName('image') - ->setCaption('Upload a 280px-wide image.')) + ->setName('image')) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton('/project/view/'.$project->getID().'/') diff --git a/src/applications/project/controller/profileedit/__init__.php b/src/applications/project/controller/profileedit/__init__.php index ae3c1e153e..a03f8883d2 100644 --- a/src/applications/project/controller/profileedit/__init__.php +++ b/src/applications/project/controller/profileedit/__init__.php @@ -9,6 +9,7 @@ phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'applications/files/storage/file'); +phutil_require_module('phabricator', 'applications/files/transform'); phutil_require_module('phabricator', 'applications/project/constants/status'); phutil_require_module('phabricator', 'applications/project/controller/base'); phutil_require_module('phabricator', 'applications/project/storage/profile'); diff --git a/src/applications/project/storage/affiliation/PhabricatorProjectAffiliation.php b/src/applications/project/storage/affiliation/PhabricatorProjectAffiliation.php index 23c73254a8..7dc819792b 100644 --- a/src/applications/project/storage/affiliation/PhabricatorProjectAffiliation.php +++ b/src/applications/project/storage/affiliation/PhabricatorProjectAffiliation.php @@ -21,7 +21,8 @@ class PhabricatorProjectAffiliation extends PhabricatorProjectDAO { protected $projectPHID; protected $userPHID; protected $role; - protected $status; + protected $status = ''; + protected $isOwner = 0; public static function loadAllForProjectPHIDs($phids) { if (!$phids) {