1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 15:22:41 +01:00

Unify profile and avatar images, move profile editing into settings

Summary: See T266. Combine these interfaces into one and move it to settings.

Test Plan: Edited my profile and account.

Reviewers: codeblock, tcook, jungejason, tuomaspelkonen, aran

CC:

Differential Revision: 722
This commit is contained in:
epriestley 2011-07-24 15:03:59 -07:00
parent 8d26399cfd
commit 0de2e03cc2
9 changed files with 88 additions and 109 deletions

View file

@ -337,7 +337,6 @@ phutil_register_library_map(array(
'PhabricatorDisabledUserController' => 'applications/auth/controller/disabled', 'PhabricatorDisabledUserController' => 'applications/auth/controller/disabled',
'PhabricatorDraft' => 'applications/draft/storage/draft', 'PhabricatorDraft' => 'applications/draft/storage/draft',
'PhabricatorDraftDAO' => 'applications/draft/storage/base', 'PhabricatorDraftDAO' => 'applications/draft/storage/base',
'PhabricatorEditPreferencesController' => 'applications/preferences/controller/edit',
'PhabricatorEmailLoginController' => 'applications/auth/controller/email', 'PhabricatorEmailLoginController' => 'applications/auth/controller/email',
'PhabricatorEmailTokenController' => 'applications/auth/controller/emailtoken', 'PhabricatorEmailTokenController' => 'applications/auth/controller/emailtoken',
'PhabricatorEnv' => 'infrastructure/env', 'PhabricatorEnv' => 'infrastructure/env',
@ -456,8 +455,6 @@ phutil_register_library_map(array(
'PhabricatorPeopleListController' => 'applications/people/controller/list', 'PhabricatorPeopleListController' => 'applications/people/controller/list',
'PhabricatorPeopleLogsController' => 'applications/people/controller/logs', 'PhabricatorPeopleLogsController' => 'applications/people/controller/logs',
'PhabricatorPeopleProfileController' => 'applications/people/controller/profile', 'PhabricatorPeopleProfileController' => 'applications/people/controller/profile',
'PhabricatorPeopleProfileEditController' => 'applications/people/controller/profileedit',
'PhabricatorPreferencesController' => 'applications/preferences/controller/base',
'PhabricatorProfileView' => 'view/layout/profile', 'PhabricatorProfileView' => 'view/layout/profile',
'PhabricatorProject' => 'applications/project/storage/project', 'PhabricatorProject' => 'applications/project/storage/project',
'PhabricatorProjectAffiliation' => 'applications/project/storage/affiliation', 'PhabricatorProjectAffiliation' => 'applications/project/storage/affiliation',
@ -577,6 +574,7 @@ phutil_register_library_map(array(
'PhabricatorUserPreferenceSettingsPanelController' => 'applications/people/controller/settings/panels/preferences', 'PhabricatorUserPreferenceSettingsPanelController' => 'applications/people/controller/settings/panels/preferences',
'PhabricatorUserPreferences' => 'applications/people/storage/preferences', 'PhabricatorUserPreferences' => 'applications/people/storage/preferences',
'PhabricatorUserProfile' => 'applications/people/storage/profile', 'PhabricatorUserProfile' => 'applications/people/storage/profile',
'PhabricatorUserProfileSettingsPanelController' => 'applications/people/controller/settings/panels/profile',
'PhabricatorUserSSHKey' => 'applications/people/storage/usersshkey', 'PhabricatorUserSSHKey' => 'applications/people/storage/usersshkey',
'PhabricatorUserSSHKeysSettingsPanelController' => 'applications/people/controller/settings/panels/sshkeys', 'PhabricatorUserSSHKeysSettingsPanelController' => 'applications/people/controller/settings/panels/sshkeys',
'PhabricatorUserSettingsController' => 'applications/people/controller/settings', 'PhabricatorUserSettingsController' => 'applications/people/controller/settings',
@ -892,7 +890,6 @@ phutil_register_library_map(array(
'PhabricatorDisabledUserController' => 'PhabricatorAuthController', 'PhabricatorDisabledUserController' => 'PhabricatorAuthController',
'PhabricatorDraft' => 'PhabricatorDraftDAO', 'PhabricatorDraft' => 'PhabricatorDraftDAO',
'PhabricatorDraftDAO' => 'PhabricatorLiskDAO', 'PhabricatorDraftDAO' => 'PhabricatorLiskDAO',
'PhabricatorEditPreferencesController' => 'PhabricatorPreferencesController',
'PhabricatorEmailLoginController' => 'PhabricatorAuthController', 'PhabricatorEmailLoginController' => 'PhabricatorAuthController',
'PhabricatorEmailTokenController' => 'PhabricatorAuthController', 'PhabricatorEmailTokenController' => 'PhabricatorAuthController',
'PhabricatorFeedController' => 'PhabricatorController', 'PhabricatorFeedController' => 'PhabricatorController',
@ -990,8 +987,6 @@ phutil_register_library_map(array(
'PhabricatorPeopleListController' => 'PhabricatorPeopleController', 'PhabricatorPeopleListController' => 'PhabricatorPeopleController',
'PhabricatorPeopleLogsController' => 'PhabricatorPeopleController', 'PhabricatorPeopleLogsController' => 'PhabricatorPeopleController',
'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController', 'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController',
'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleController',
'PhabricatorPreferencesController' => 'PhabricatorController',
'PhabricatorProfileView' => 'AphrontView', 'PhabricatorProfileView' => 'AphrontView',
'PhabricatorProject' => 'PhabricatorProjectDAO', 'PhabricatorProject' => 'PhabricatorProjectDAO',
'PhabricatorProjectAffiliation' => 'PhabricatorProjectDAO', 'PhabricatorProjectAffiliation' => 'PhabricatorProjectDAO',
@ -1098,6 +1093,7 @@ phutil_register_library_map(array(
'PhabricatorUserPreferenceSettingsPanelController' => 'PhabricatorUserSettingsPanelController', 'PhabricatorUserPreferenceSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
'PhabricatorUserPreferences' => 'PhabricatorUserDAO', 'PhabricatorUserPreferences' => 'PhabricatorUserDAO',
'PhabricatorUserProfile' => 'PhabricatorUserDAO', 'PhabricatorUserProfile' => 'PhabricatorUserDAO',
'PhabricatorUserProfileSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
'PhabricatorUserSSHKey' => 'PhabricatorUserDAO', 'PhabricatorUserSSHKey' => 'PhabricatorUserDAO',
'PhabricatorUserSSHKeysSettingsPanelController' => 'PhabricatorUserSettingsPanelController', 'PhabricatorUserSSHKeysSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
'PhabricatorUserSettingsController' => 'PhabricatorPeopleController', 'PhabricatorUserSettingsController' => 'PhabricatorPeopleController',

View file

@ -72,8 +72,6 @@ class AphrontDefaultApplicationConfiguration
'/people/' => array( '/people/' => array(
'$' => 'PhabricatorPeopleListController', '$' => 'PhabricatorPeopleListController',
'logs/$' => 'PhabricatorPeopleLogsController', 'logs/$' => 'PhabricatorPeopleLogsController',
'edit/(?:(?P<id>\d+)/(?:(?P<view>\w+)/)?)?$'
=> 'PhabricatorPeopleEditController',
), ),
'/p/(?P<username>\w+)/(?:(?P<page>\w+)/)?$' '/p/(?P<username>\w+)/(?:(?P<page>\w+)/)?$'
=> 'PhabricatorPeopleProfileController', => 'PhabricatorPeopleProfileController',

View file

@ -50,7 +50,7 @@ class PhabricatorPeopleProfileController extends PhabricatorPeopleController {
$links[] = phutil_render_tag( $links[] = phutil_render_tag(
'a', 'a',
array( array(
'href' => '/profile/edit/', 'href' => '/settings/page/profile/',
), ),
'Edit Profile'); 'Edit Profile');
} }

View file

@ -33,6 +33,7 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
$this->pages = array( $this->pages = array(
'account' => 'Account', 'account' => 'Account',
'profile' => 'Profile',
'email' => 'Email', 'email' => 'Email',
'preferences' => 'Preferences', 'preferences' => 'Preferences',
'conduit' => 'Conduit Certificate', 'conduit' => 'Conduit Certificate',
@ -60,6 +61,9 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
case 'account': case 'account':
$delegate = new PhabricatorUserAccountSettingsPanelController($request); $delegate = new PhabricatorUserAccountSettingsPanelController($request);
break; break;
case 'profile':
$delegate = new PhabricatorUserProfileSettingsPanelController($request);
break;
case 'email': case 'email':
$delegate = new PhabricatorUserEmailSettingsPanelController($request); $delegate = new PhabricatorUserEmailSettingsPanelController($request);
break; break;

View file

@ -14,6 +14,7 @@ phutil_require_module('phabricator', 'applications/people/controller/settings/pa
phutil_require_module('phabricator', 'applications/people/controller/settings/panels/email'); phutil_require_module('phabricator', 'applications/people/controller/settings/panels/email');
phutil_require_module('phabricator', 'applications/people/controller/settings/panels/oauth'); phutil_require_module('phabricator', 'applications/people/controller/settings/panels/oauth');
phutil_require_module('phabricator', 'applications/people/controller/settings/panels/preferences'); phutil_require_module('phabricator', 'applications/people/controller/settings/panels/preferences');
phutil_require_module('phabricator', 'applications/people/controller/settings/panels/profile');
phutil_require_module('phabricator', 'applications/people/controller/settings/panels/sshkeys'); phutil_require_module('phabricator', 'applications/people/controller/settings/panels/sshkeys');
phutil_require_module('phabricator', 'view/layout/sidenav'); phutil_require_module('phabricator', 'view/layout/sidenav');

View file

@ -25,44 +25,17 @@ class PhabricatorUserAccountSettingsPanelController
$user = $request->getUser(); $user = $request->getUser();
$editable = $this->getAccountEditable(); $editable = $this->getAccountEditable();
$e_realname = true; $e_realname = $editable ? true : null;
$errors = array(); $errors = array();
if ($request->isFormPost()) { if ($request->isFormPost()) {
if (!$editable) {
return new Aphront400Response();
}
if (!empty($_FILES['profile'])) {
$err = idx($_FILES['profile'], 'error');
if ($err != UPLOAD_ERR_NO_FILE) {
$file = PhabricatorFile::newFromPHPUpload(
$_FILES['profile'],
array(
'authorPHID' => $user->getPHID(),
));
$okay = $file->isTransformableImage();
if ($okay) {
$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) '.
'will be accepted.';
}
}
}
if ($editable) {
$user->setRealName($request->getStr('realname')); $user->setRealName($request->getStr('realname'));
if (!strlen($user->getRealName())) { if (!strlen($user->getRealName())) {
$errors[] = 'Real name must be nonempty.'; $errors[] = 'Real name must be nonempty.';
$e_realname = 'Required'; $e_realname = 'Required';
} }
}
$new_timezone = $request->getStr('timezone'); $new_timezone = $request->getStr('timezone');
if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) { if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
@ -78,9 +51,6 @@ class PhabricatorUserAccountSettingsPanelController
} }
} }
$img_src = PhabricatorFileURI::getViewURIForPHID(
$user->getProfileImagePHID());
$notice = null; $notice = null;
if (!$errors) { if (!$errors) {
if ($request->getStr('saved')) { if ($request->getStr('saved')) {
@ -97,6 +67,9 @@ class PhabricatorUserAccountSettingsPanelController
$notice = $notice->render(); $notice = $notice->render();
} }
$timezone_ids = DateTimeZone::listIdentifiers();
$timezone_id_map = array_combine($timezone_ids, $timezone_ids);
$form = new AphrontFormView(); $form = new AphrontFormView();
$form $form
->setUser($user) ->setUser($user)
@ -112,47 +85,18 @@ class PhabricatorUserAccountSettingsPanelController
->setError($e_realname) ->setError($e_realname)
->setValue($user->getRealName()) ->setValue($user->getRealName())
->setDisabled(!$editable)) ->setDisabled(!$editable))
->appendChild(
id(new AphrontFormMarkupControl())
->setValue('<hr />'))
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel('Profile Image')
->setValue(
phutil_render_tag(
'img',
array(
'src' => $img_src,
))));
if ($editable) {
$timezone_ids = DateTimeZone::listIdentifiers();
$timezone_id_map = array_combine($timezone_ids, $timezone_ids);
$form
->appendChild(
id(new AphrontFormFileControl())
->setLabel('Change Image')
->setName('profile'))
->appendChild(
id(new AphrontFormMarkupControl())
->setValue('<hr />'))
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setLabel('Timezone') ->setLabel('Timezone')
->setName('timezone') ->setName('timezone')
->setOptions($timezone_id_map) ->setOptions($timezone_id_map)
->setValue($user->getTimezoneIdentifier())) ->setValue($user->getTimezoneIdentifier()))
->appendChild(
id(new AphrontFormMarkupControl())
->setValue('<hr />'))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue('Save')); ->setValue('Save'));
}
$panel = new AphrontPanelView(); $panel = new AphrontPanelView();
$panel->setHeader('Profile Settings'); $panel->setHeader('Account Settings');
$panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->setWidth(AphrontPanelView::WIDTH_FORM);
$panel->appendChild($form); $panel->appendChild($form);

View file

@ -6,15 +6,9 @@
phutil_require_module('phabricator', 'aphront/response/400');
phutil_require_module('phabricator', 'aphront/response/redirect'); 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/files/uri');
phutil_require_module('phabricator', 'applications/people/controller/settings/panels/base'); phutil_require_module('phabricator', 'applications/people/controller/settings/panels/base');
phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/file');
phutil_require_module('phabricator', 'view/form/control/markup');
phutil_require_module('phabricator', 'view/form/control/select'); phutil_require_module('phabricator', 'view/form/control/select');
phutil_require_module('phabricator', 'view/form/control/static'); phutil_require_module('phabricator', 'view/form/control/static');
phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/submit');
@ -23,7 +17,6 @@ phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/null'); phutil_require_module('phabricator', 'view/null');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -16,8 +16,8 @@
* limitations under the License. * limitations under the License.
*/ */
class PhabricatorPeopleProfileEditController class PhabricatorUserProfileSettingsPanelController
extends PhabricatorPeopleController { extends PhabricatorUserSettingsPanelController {
public function processRequest() { public function processRequest() {
@ -48,12 +48,22 @@ class PhabricatorPeopleProfileEditController
$okay = $file->isTransformableImage(); $okay = $file->isTransformableImage();
if ($okay) { if ($okay) {
$xformer = new PhabricatorImageTransformer(); $xformer = new PhabricatorImageTransformer();
$xformed = $xformer->executeProfileTransform(
// Generate the large picture for the profile page.
$large_xformed = $xformer->executeProfileTransform(
$file, $file,
$width = 280, $width = 280,
$min_height = 140, $min_height = 140,
$max_height = 420); $max_height = 420);
$profile->setProfileImagePHID($xformed->getPHID()); $profile->setProfileImagePHID($large_xformed->getPHID());
// Generate the small picture for comments, etc.
$small_xformed = $xformer->executeProfileTransform(
$file,
$width = 50,
$min_height = 50,
$max_height = 50);
$user->setProfileImagePHID($small_xformed->getPHID());
} else { } else {
$errors[] = $errors[] =
'Only valid image files (jpg, jpeg, png or gif) '. 'Only valid image files (jpg, jpeg, png or gif) '.
@ -63,9 +73,10 @@ class PhabricatorPeopleProfileEditController
} }
if (!$errors) { if (!$errors) {
$user->save();
$profile->save(); $profile->save();
$response = id(new AphrontRedirectResponse()) $response = id(new AphrontRedirectResponse())
->setURI('/p/'.$user->getUsername().'/'); ->setURI('/settings/page/profile/?saved=true');
return $response; return $response;
} }
} }
@ -75,12 +86,24 @@ class PhabricatorPeopleProfileEditController
$error_view = new AphrontErrorView(); $error_view = new AphrontErrorView();
$error_view->setTitle('Form Errors'); $error_view->setTitle('Form Errors');
$error_view->setErrors($errors); $error_view->setErrors($errors);
} else {
if ($request->getStr('saved')) {
$error_view = new AphrontErrorView();
$error_view->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
$error_view->setTitle('Changes Saved');
$error_view->appendChild('<p>Your changes have been saved.</p>');
$error_view = $error_view->render();
} }
}
$img_src = PhabricatorFileURI::getViewURIForPHID(
$user->getProfileImagePHID());
$profile_uri = PhabricatorEnv::getURI('/p/'.$user->getUsername().'/');
$form = new AphrontFormView(); $form = new AphrontFormView();
$form $form
->setUser($request->getUser()) ->setUser($request->getUser())
->setAction('/profile/edit/') ->setAction('/settings/page/profile/')
->setEncType('multipart/form-data') ->setEncType('multipart/form-data')
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
@ -88,21 +111,38 @@ class PhabricatorPeopleProfileEditController
->setName('title') ->setName('title')
->setValue($profile->getTitle()) ->setValue($profile->getTitle())
->setCaption('Serious business title.')) ->setCaption('Serious business title.'))
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel('Profile URI')
->setValue(
phutil_render_tag(
'a',
array(
'href' => $profile_uri,
),
phutil_escape_html($profile_uri))))
->appendChild( ->appendChild(
'<p class="aphront-form-instructions">Write something about yourself! '. '<p class="aphront-form-instructions">Write something about yourself! '.
'Make sure to include <strong>important information</strong> like '. 'Make sure to include <strong>important information</strong> like '.
'your <strong>favorite pokemon</strong> and which '. 'your favorite pokemon and which Starcraft race you play.</p>')
'<strong>Starcraft race</strong> you play.</p>')
->appendChild( ->appendChild(
id(new AphrontFormTextAreaControl()) id(new AphrontFormTextAreaControl())
->setLabel('Blurb') ->setLabel('Blurb')
->setName('blurb') ->setName('blurb')
->setValue($profile->getBlurb())) ->setValue($profile->getBlurb()))
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel('Profile Image')
->setValue(
phutil_render_tag(
'img',
array(
'src' => $img_src,
))))
->appendChild( ->appendChild(
id(new AphrontFormFileControl()) id(new AphrontFormFileControl())
->setLabel('Change Image') ->setLabel('Change Image')
->setName('image') ->setName('image'))
->setCaption('Upload a 280px-wide image.'))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue('Save') ->setValue('Save')
@ -113,13 +153,11 @@ class PhabricatorPeopleProfileEditController
$panel->appendChild($form); $panel->appendChild($form);
$panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->setWidth(AphrontPanelView::WIDTH_FORM);
return $this->buildStandardPageResponse( return id(new AphrontNullView())
->appendChild(
array( array(
$error_view, $error_view,
$panel, $panel,
),
array(
'title' => 'Edit Profile',
)); ));
} }

View file

@ -9,17 +9,22 @@
phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'aphront/response/redirect');
phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/files/storage/file');
phutil_require_module('phabricator', 'applications/files/transform'); phutil_require_module('phabricator', 'applications/files/transform');
phutil_require_module('phabricator', 'applications/people/controller/base'); phutil_require_module('phabricator', 'applications/files/uri');
phutil_require_module('phabricator', 'applications/people/controller/settings/panels/base');
phutil_require_module('phabricator', 'applications/people/storage/profile'); phutil_require_module('phabricator', 'applications/people/storage/profile');
phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/file'); phutil_require_module('phabricator', 'view/form/control/file');
phutil_require_module('phabricator', 'view/form/control/markup');
phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/text'); phutil_require_module('phabricator', 'view/form/control/text');
phutil_require_module('phabricator', 'view/form/control/textarea'); phutil_require_module('phabricator', 'view/form/control/textarea');
phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/null');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorPeopleProfileEditController.php'); phutil_require_source('PhabricatorUserProfileSettingsPanelController.php');