mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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:
parent
8d26399cfd
commit
0de2e03cc2
9 changed files with 88 additions and 109 deletions
|
@ -337,7 +337,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDisabledUserController' => 'applications/auth/controller/disabled',
|
||||
'PhabricatorDraft' => 'applications/draft/storage/draft',
|
||||
'PhabricatorDraftDAO' => 'applications/draft/storage/base',
|
||||
'PhabricatorEditPreferencesController' => 'applications/preferences/controller/edit',
|
||||
'PhabricatorEmailLoginController' => 'applications/auth/controller/email',
|
||||
'PhabricatorEmailTokenController' => 'applications/auth/controller/emailtoken',
|
||||
'PhabricatorEnv' => 'infrastructure/env',
|
||||
|
@ -456,8 +455,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleListController' => 'applications/people/controller/list',
|
||||
'PhabricatorPeopleLogsController' => 'applications/people/controller/logs',
|
||||
'PhabricatorPeopleProfileController' => 'applications/people/controller/profile',
|
||||
'PhabricatorPeopleProfileEditController' => 'applications/people/controller/profileedit',
|
||||
'PhabricatorPreferencesController' => 'applications/preferences/controller/base',
|
||||
'PhabricatorProfileView' => 'view/layout/profile',
|
||||
'PhabricatorProject' => 'applications/project/storage/project',
|
||||
'PhabricatorProjectAffiliation' => 'applications/project/storage/affiliation',
|
||||
|
@ -577,6 +574,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserPreferenceSettingsPanelController' => 'applications/people/controller/settings/panels/preferences',
|
||||
'PhabricatorUserPreferences' => 'applications/people/storage/preferences',
|
||||
'PhabricatorUserProfile' => 'applications/people/storage/profile',
|
||||
'PhabricatorUserProfileSettingsPanelController' => 'applications/people/controller/settings/panels/profile',
|
||||
'PhabricatorUserSSHKey' => 'applications/people/storage/usersshkey',
|
||||
'PhabricatorUserSSHKeysSettingsPanelController' => 'applications/people/controller/settings/panels/sshkeys',
|
||||
'PhabricatorUserSettingsController' => 'applications/people/controller/settings',
|
||||
|
@ -892,7 +890,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDisabledUserController' => 'PhabricatorAuthController',
|
||||
'PhabricatorDraft' => 'PhabricatorDraftDAO',
|
||||
'PhabricatorDraftDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorEditPreferencesController' => 'PhabricatorPreferencesController',
|
||||
'PhabricatorEmailLoginController' => 'PhabricatorAuthController',
|
||||
'PhabricatorEmailTokenController' => 'PhabricatorAuthController',
|
||||
'PhabricatorFeedController' => 'PhabricatorController',
|
||||
|
@ -990,8 +987,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleListController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleLogsController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPreferencesController' => 'PhabricatorController',
|
||||
'PhabricatorProfileView' => 'AphrontView',
|
||||
'PhabricatorProject' => 'PhabricatorProjectDAO',
|
||||
'PhabricatorProjectAffiliation' => 'PhabricatorProjectDAO',
|
||||
|
@ -1098,6 +1093,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserPreferenceSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
|
||||
'PhabricatorUserPreferences' => 'PhabricatorUserDAO',
|
||||
'PhabricatorUserProfile' => 'PhabricatorUserDAO',
|
||||
'PhabricatorUserProfileSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
|
||||
'PhabricatorUserSSHKey' => 'PhabricatorUserDAO',
|
||||
'PhabricatorUserSSHKeysSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
|
||||
'PhabricatorUserSettingsController' => 'PhabricatorPeopleController',
|
||||
|
|
|
@ -72,8 +72,6 @@ class AphrontDefaultApplicationConfiguration
|
|||
'/people/' => array(
|
||||
'$' => 'PhabricatorPeopleListController',
|
||||
'logs/$' => 'PhabricatorPeopleLogsController',
|
||||
'edit/(?:(?P<id>\d+)/(?:(?P<view>\w+)/)?)?$'
|
||||
=> 'PhabricatorPeopleEditController',
|
||||
),
|
||||
'/p/(?P<username>\w+)/(?:(?P<page>\w+)/)?$'
|
||||
=> 'PhabricatorPeopleProfileController',
|
||||
|
|
|
@ -50,7 +50,7 @@ class PhabricatorPeopleProfileController extends PhabricatorPeopleController {
|
|||
$links[] = phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/profile/edit/',
|
||||
'href' => '/settings/page/profile/',
|
||||
),
|
||||
'Edit Profile');
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
|||
|
||||
$this->pages = array(
|
||||
'account' => 'Account',
|
||||
'profile' => 'Profile',
|
||||
'email' => 'Email',
|
||||
'preferences' => 'Preferences',
|
||||
'conduit' => 'Conduit Certificate',
|
||||
|
@ -60,6 +61,9 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
|||
case 'account':
|
||||
$delegate = new PhabricatorUserAccountSettingsPanelController($request);
|
||||
break;
|
||||
case 'profile':
|
||||
$delegate = new PhabricatorUserProfileSettingsPanelController($request);
|
||||
break;
|
||||
case 'email':
|
||||
$delegate = new PhabricatorUserEmailSettingsPanelController($request);
|
||||
break;
|
||||
|
|
|
@ -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/oauth');
|
||||
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', 'view/layout/sidenav');
|
||||
|
||||
|
|
|
@ -25,45 +25,18 @@ class PhabricatorUserAccountSettingsPanelController
|
|||
$user = $request->getUser();
|
||||
$editable = $this->getAccountEditable();
|
||||
|
||||
$e_realname = true;
|
||||
$e_realname = $editable ? true : null;
|
||||
$errors = array();
|
||||
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'));
|
||||
if (!strlen($user->getRealName())) {
|
||||
$errors[] = 'Real name must be nonempty.';
|
||||
$e_realname = 'Required';
|
||||
}
|
||||
}
|
||||
|
||||
$user->setRealName($request->getStr('realname'));
|
||||
|
||||
if (!strlen($user->getRealName())) {
|
||||
$errors[] = 'Real name must be nonempty.';
|
||||
$e_realname = 'Required';
|
||||
}
|
||||
|
||||
$new_timezone = $request->getStr('timezone');
|
||||
if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
|
||||
$user->setTimezoneIdentifier($new_timezone);
|
||||
|
@ -78,9 +51,6 @@ class PhabricatorUserAccountSettingsPanelController
|
|||
}
|
||||
}
|
||||
|
||||
$img_src = PhabricatorFileURI::getViewURIForPHID(
|
||||
$user->getProfileImagePHID());
|
||||
|
||||
$notice = null;
|
||||
if (!$errors) {
|
||||
if ($request->getStr('saved')) {
|
||||
|
@ -97,6 +67,9 @@ class PhabricatorUserAccountSettingsPanelController
|
|||
$notice = $notice->render();
|
||||
}
|
||||
|
||||
$timezone_ids = DateTimeZone::listIdentifiers();
|
||||
$timezone_id_map = array_combine($timezone_ids, $timezone_ids);
|
||||
|
||||
$form = new AphrontFormView();
|
||||
$form
|
||||
->setUser($user)
|
||||
|
@ -113,46 +86,17 @@ class PhabricatorUserAccountSettingsPanelController
|
|||
->setValue($user->getRealName())
|
||||
->setDisabled(!$editable))
|
||||
->appendChild(
|
||||
id(new AphrontFormMarkupControl())
|
||||
->setValue('<hr />'))
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel('Timezone')
|
||||
->setName('timezone')
|
||||
->setOptions($timezone_id_map)
|
||||
->setValue($user->getTimezoneIdentifier()))
|
||||
->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(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel('Timezone')
|
||||
->setName('timezone')
|
||||
->setOptions($timezone_id_map)
|
||||
->setValue($user->getTimezoneIdentifier()))
|
||||
->appendChild(
|
||||
id(new AphrontFormMarkupControl())
|
||||
->setValue('<hr />'))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue('Save'));
|
||||
}
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue('Save'));
|
||||
|
||||
$panel = new AphrontPanelView();
|
||||
$panel->setHeader('Profile Settings');
|
||||
$panel->setHeader('Account Settings');
|
||||
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
||||
$panel->appendChild($form);
|
||||
|
||||
|
|
|
@ -6,15 +6,9 @@
|
|||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/400');
|
||||
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', '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/static');
|
||||
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/null');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class PhabricatorPeopleProfileEditController
|
||||
extends PhabricatorPeopleController {
|
||||
class PhabricatorUserProfileSettingsPanelController
|
||||
extends PhabricatorUserSettingsPanelController {
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
|
@ -48,12 +48,22 @@ class PhabricatorPeopleProfileEditController
|
|||
$okay = $file->isTransformableImage();
|
||||
if ($okay) {
|
||||
$xformer = new PhabricatorImageTransformer();
|
||||
$xformed = $xformer->executeProfileTransform(
|
||||
|
||||
// Generate the large picture for the profile page.
|
||||
$large_xformed = $xformer->executeProfileTransform(
|
||||
$file,
|
||||
$width = 280,
|
||||
$min_height = 140,
|
||||
$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 {
|
||||
$errors[] =
|
||||
'Only valid image files (jpg, jpeg, png or gif) '.
|
||||
|
@ -63,9 +73,10 @@ class PhabricatorPeopleProfileEditController
|
|||
}
|
||||
|
||||
if (!$errors) {
|
||||
$user->save();
|
||||
$profile->save();
|
||||
$response = id(new AphrontRedirectResponse())
|
||||
->setURI('/p/'.$user->getUsername().'/');
|
||||
->setURI('/settings/page/profile/?saved=true');
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -75,12 +86,24 @@ class PhabricatorPeopleProfileEditController
|
|||
$error_view = new AphrontErrorView();
|
||||
$error_view->setTitle('Form 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
|
||||
->setUser($request->getUser())
|
||||
->setAction('/profile/edit/')
|
||||
->setAction('/settings/page/profile/')
|
||||
->setEncType('multipart/form-data')
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
|
@ -88,21 +111,38 @@ class PhabricatorPeopleProfileEditController
|
|||
->setName('title')
|
||||
->setValue($profile->getTitle())
|
||||
->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(
|
||||
'<p class="aphront-form-instructions">Write something about yourself! '.
|
||||
'Make sure to include <strong>important information</strong> like '.
|
||||
'your <strong>favorite pokemon</strong> and which '.
|
||||
'<strong>Starcraft race</strong> you play.</p>')
|
||||
'your favorite pokemon and which Starcraft race you play.</p>')
|
||||
->appendChild(
|
||||
id(new AphrontFormTextAreaControl())
|
||||
->setLabel('Blurb')
|
||||
->setName('blurb')
|
||||
->setValue($profile->getBlurb()))
|
||||
->appendChild(
|
||||
id(new AphrontFormMarkupControl())
|
||||
->setLabel('Profile Image')
|
||||
->setValue(
|
||||
phutil_render_tag(
|
||||
'img',
|
||||
array(
|
||||
'src' => $img_src,
|
||||
))))
|
||||
->appendChild(
|
||||
id(new AphrontFormFileControl())
|
||||
->setLabel('Change Image')
|
||||
->setName('image')
|
||||
->setCaption('Upload a 280px-wide image.'))
|
||||
->setName('image'))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue('Save')
|
||||
|
@ -113,14 +153,12 @@ class PhabricatorPeopleProfileEditController
|
|||
$panel->appendChild($form);
|
||||
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
array(
|
||||
$error_view,
|
||||
$panel,
|
||||
),
|
||||
array(
|
||||
'title' => 'Edit Profile',
|
||||
));
|
||||
return id(new AphrontNullView())
|
||||
->appendChild(
|
||||
array(
|
||||
$error_view,
|
||||
$panel,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
|
@ -9,17 +9,22 @@
|
|||
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/files/uri');
|
||||
phutil_require_module('phabricator', 'applications/people/controller/settings/panels/base');
|
||||
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/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/text');
|
||||
phutil_require_module('phabricator', 'view/form/control/textarea');
|
||||
phutil_require_module('phabricator', 'view/form/error');
|
||||
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_source('PhabricatorPeopleProfileEditController.php');
|
||||
phutil_require_source('PhabricatorUserProfileSettingsPanelController.php');
|
Loading…
Reference in a new issue