@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Enabling Admins to set profile pictures for System Agents

Summary: Added an action in Edit option of People application allowing Admins to set profile pictures for System Agents

Test Plan: By trying to set a profile picture for the sytem agents

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5293

authored by

Afaque Hussain and committed by
epriestley
95b84881 81334651

+132
+132
src/applications/people/controller/PhabricatorPeopleEditController.php
··· 54 54 pht('View Profile'), '/p/'.$user->getUsername().'/'); 55 55 $nav->addLabel(pht('Special')); 56 56 $nav->addFilter('rename', pht('Change Username')); 57 + $nav->addFilter('picture', pht('Set Account Picture')); 57 58 $nav->addFilter('delete', pht('Delete User')); 58 59 59 60 if (!$user->getID()) { ··· 85 86 break; 86 87 case 'rename': 87 88 $response = $this->processRenameRequest($user); 89 + break; 90 + case 'picture': 91 + $response = $this->processSetAccountPicture($user); 88 92 break; 89 93 case 'delete': 90 94 $response = $this->processDeleteRequest($user); ··· 707 711 return hsprintf( 708 712 '<p class="aphront-form-instructions">%s</p>', 709 713 $inst); 714 + } 715 + 716 + private function processSetAccountPicture(PhabricatorUser $user) { 717 + $request = $this->getRequest(); 718 + $admin = $request->getUser(); 719 + 720 + $profile = id(new PhabricatorUserProfile())->loadOneWhere( 721 + 'userPHID = %s', 722 + $user->getPHID()); 723 + if (!$profile) { 724 + $profile = new PhabricatorUserProfile(); 725 + $profile->setUserPHID($user->getPHID()); 726 + $profile->setTitle(''); 727 + $profile->setBlurb(''); 728 + } 729 + 730 + 731 + 732 + $supported_formats = PhabricatorFile::getTransformableImageFormats(); 733 + 734 + $e_image = null; 735 + $errors = array(); 736 + 737 + if ($request->isFormPost()) { 738 + $default_image = $request->getExists('default_image'); 739 + 740 + if ($default_image) { 741 + $profile->setProfileImagePHID(null); 742 + $user->setProfileImagePHID(null); 743 + } else if ($request->getFileExists('image')) { 744 + $file = null; 745 + $file = PhabricatorFile::newFromPHPUpload( 746 + $_FILES['image'], 747 + array( 748 + 'authorPHID' => $admin->getPHID(), 749 + )); 750 + 751 + $okay = $file->isTransformableImage(); 752 + 753 + if ($okay) { 754 + $xformer = new PhabricatorImageTransformer(); 755 + 756 + // Generate the large picture for the profile page. 757 + $large_xformed = $xformer->executeProfileTransform( 758 + $file, 759 + $width = 280, 760 + $min_height = 140, 761 + $max_height = 420); 762 + $profile->setProfileImagePHID($large_xformed->getPHID()); 763 + 764 + // Generate the small picture for comments, etc. 765 + $small_xformed = $xformer->executeProfileTransform( 766 + $file, 767 + $width = 50, 768 + $min_height = 50, 769 + $max_height = 50); 770 + $user->setProfileImagePHID($small_xformed->getPHID()); 771 + } else { 772 + $e_image = pht('Not Supported'); 773 + $errors[] = 774 + pht('This server only supports these image formats:'). 775 + ' ' .implode(', ', $supported_formats); 776 + } 777 + } 778 + 779 + if (!$errors) { 780 + $user->save(); 781 + $profile->save(); 782 + $response = id(new AphrontRedirectResponse()) 783 + ->setURI('/people/edit/'.$user->getID().'/picture/'); 784 + return $response; 785 + } 786 + } 787 + 788 + 789 + $error_view = null; 790 + if ($errors) { 791 + $error_view = new AphrontErrorView(); 792 + $error_view->setTitle(pht('Form Errors')); 793 + $error_view->setErrors($errors); 794 + } else { 795 + if ($request->getStr('saved')) { 796 + $error_view = new AphrontErrorView(); 797 + $error_view->setSeverity(AphrontErrorView::SEVERITY_NOTICE); 798 + $error_view->setTitle(pht('Changes Saved')); 799 + $error_view->appendChild( 800 + phutil_tag('p', array(), pht('Your changes have been saved.'))); 801 + $error_view = $error_view->render(); 802 + } 803 + } 804 + 805 + $img_src = $user->loadProfileImageURI(); 806 + 807 + $form = new AphrontFormView(); 808 + $form 809 + ->setUser($admin) 810 + ->setAction($request->getRequestURI()) 811 + ->setEncType('multipart/form-data') 812 + ->appendChild( 813 + id(new AphrontFormMarkupControl()) 814 + ->setLabel(pht('Profile Image')) 815 + ->setValue( 816 + phutil_tag( 817 + 'img', 818 + array( 819 + 'src' => $img_src, 820 + )))) 821 + ->appendChild( 822 + id(new AphrontFormImageControl()) 823 + ->setLabel(pht('Change Image')) 824 + ->setName('image') 825 + ->setError($e_image) 826 + ->setCaption( 827 + pht('Supported formats: %s', implode(', ', $supported_formats)))); 828 + 829 + $form->appendChild( 830 + id(new AphrontFormSubmitControl()) 831 + ->setValue(pht('Save')) 832 + ->addCancelButton('/people/edit/'.$user->getID().'/')); 833 + 834 + $panel = new AphrontPanelView(); 835 + $panel->setHeader(pht('Set Profile Picture')); 836 + $panel->setWidth(AphrontPanelView::WIDTH_FORM); 837 + $panel->setNoBackground(); 838 + $panel->appendChild($form); 839 + 840 + return array($error_view, $panel); 841 + 710 842 } 711 843 712 844 }