@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.

Allow administrators to edit System Agent information from the agent's profile

Summary:
Ref T4065. Currently, we have this super copy/pasted "edit profile picture" UI for system agents.

Instead, give administrators direct access from profiles, so they can use the same code pages do.

Test Plan: Edited my profile picture and profile details. Edited an agent's. Was unable to edit a non-agent user.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4065

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

+13 -137
-131
src/applications/people/controller/PhabricatorPeopleEditController.php
··· 39 39 $nav->addFilter('cert', pht('Conduit Certificate')); 40 40 $nav->addFilter('profile', 41 41 pht('View Profile'), '/p/'.$user->getUsername().'/'); 42 - if ($user->getIsSystemAgent()) { 43 - $nav->addLabel(pht('Special')); 44 - $nav->addFilter('picture', pht('Set Account Picture')); 45 - } 46 42 47 43 if (!$user->getID()) { 48 44 $this->view = 'basic'; ··· 70 66 break; 71 67 case 'cert': 72 68 $response = $this->processCertificateRequest($user); 73 - break; 74 - case 'picture': 75 - $response = $this->processSetAccountPicture($user); 76 69 break; 77 70 default: 78 71 return new Aphront404Response(); ··· 490 483 'p', 491 484 array('class' => 'aphront-form-instructions'), 492 485 pht('For a detailed explanation of account roles, see %s.', $roles_link)); 493 - } 494 - 495 - private function processSetAccountPicture(PhabricatorUser $user) { 496 - $request = $this->getRequest(); 497 - $admin = $request->getUser(); 498 - 499 - $profile = $user->loadUserProfile(); 500 - if (!$profile->getID()) { 501 - $profile->setTitle(''); 502 - $profile->setBlurb(''); 503 - } 504 - 505 - 506 - 507 - $supported_formats = PhabricatorFile::getTransformableImageFormats(); 508 - 509 - $e_image = null; 510 - $errors = array(); 511 - 512 - if ($request->isFormPost()) { 513 - $default_image = $request->getExists('default_image'); 514 - 515 - if ($default_image) { 516 - $profile->setProfileImagePHID(null); 517 - $user->setProfileImagePHID(null); 518 - } else if ($request->getFileExists('image')) { 519 - $file = null; 520 - $file = PhabricatorFile::newFromPHPUpload( 521 - $_FILES['image'], 522 - array( 523 - 'authorPHID' => $admin->getPHID(), 524 - )); 525 - 526 - $okay = $file->isTransformableImage(); 527 - 528 - if ($okay) { 529 - $xformer = new PhabricatorImageTransformer(); 530 - 531 - // Generate the large picture for the profile page. 532 - $large_xformed = $xformer->executeProfileTransform( 533 - $file, 534 - $width = 280, 535 - $min_height = 140, 536 - $max_height = 420); 537 - $profile->setProfileImagePHID($large_xformed->getPHID()); 538 - 539 - // Generate the small picture for comments, etc. 540 - $small_xformed = $xformer->executeProfileTransform( 541 - $file, 542 - $width = 50, 543 - $min_height = 50, 544 - $max_height = 50); 545 - $user->setProfileImagePHID($small_xformed->getPHID()); 546 - } else { 547 - $e_image = pht('Not Supported'); 548 - $errors[] = 549 - pht('This server only supports these image formats:'). 550 - ' ' .implode(', ', $supported_formats); 551 - } 552 - } 553 - 554 - if (!$errors) { 555 - $user->save(); 556 - $profile->save(); 557 - $response = id(new AphrontRedirectResponse()) 558 - ->setURI('/people/edit/'.$user->getID().'/picture/'); 559 - return $response; 560 - } 561 - } 562 - 563 - 564 - $error_view = null; 565 - if ($errors) { 566 - $error_view = new AphrontErrorView(); 567 - $error_view->setTitle(pht('Form Errors')); 568 - $error_view->setErrors($errors); 569 - } else { 570 - if ($request->getStr('saved')) { 571 - $error_view = new AphrontErrorView(); 572 - $error_view->setSeverity(AphrontErrorView::SEVERITY_NOTICE); 573 - $error_view->setTitle(pht('Changes Saved')); 574 - $error_view->appendChild( 575 - phutil_tag('p', array(), pht('Your changes have been saved.'))); 576 - $error_view = $error_view->render(); 577 - } 578 - } 579 - 580 - $img_src = $user->loadProfileImageURI(); 581 - 582 - $form = new AphrontFormView(); 583 - $form 584 - ->setUser($admin) 585 - ->setAction($request->getRequestURI()) 586 - ->setEncType('multipart/form-data') 587 - ->appendChild( 588 - id(new AphrontFormMarkupControl()) 589 - ->setLabel(pht('Profile Image')) 590 - ->setValue( 591 - phutil_tag( 592 - 'img', 593 - array( 594 - 'src' => $img_src, 595 - )))) 596 - ->appendChild( 597 - id(new AphrontFormImageControl()) 598 - ->setLabel(pht('Change Image')) 599 - ->setName('image') 600 - ->setError($e_image) 601 - ->setCaption( 602 - pht('Supported formats: %s', implode(', ', $supported_formats)))); 603 - 604 - $form->appendChild( 605 - id(new AphrontFormSubmitControl()) 606 - ->setValue(pht('Save')) 607 - ->addCancelButton('/people/edit/'.$user->getID().'/')); 608 - 609 - $panel = new AphrontPanelView(); 610 - $panel->setHeader(pht('Set Profile Picture')); 611 - $panel->setWidth(AphrontPanelView::WIDTH_FORM); 612 - $panel->setNoBackground(); 613 - $panel->appendChild($form); 614 - 615 - return array($error_view, $panel); 616 - 617 486 } 618 487 619 488 }
+4 -1
src/applications/people/controller/PhabricatorPeopleProfileController.php
··· 42 42 ->setObjectURI($this->getRequest()->getRequestURI()) 43 43 ->setUser($viewer); 44 44 45 - $can_edit = ($user->getPHID() == $viewer->getPHID()); 45 + $can_edit = PhabricatorPolicyFilter::hasCapability( 46 + $viewer, 47 + $user, 48 + PhabricatorPolicyCapability::CAN_EDIT); 46 49 47 50 $actions->addAction( 48 51 id(new PhabricatorActionView())
+2 -2
src/applications/people/controller/PhabricatorPeopleProfileEditController.php
··· 36 36 $user, 37 37 PhabricatorCustomField::ROLE_EDIT); 38 38 $field_list 39 - ->setViewer($user) 39 + ->setViewer($viewer) 40 40 ->readFieldsFromStorage($user); 41 41 42 42 $validation_exception = null; ··· 76 76 ->setValue(pht('Save Profile'))); 77 77 78 78 $form_box = id(new PHUIObjectBoxView()) 79 - ->setHeaderText(pht('Edit Your Profile')) 79 + ->setHeaderText(pht('Edit Profile')) 80 80 ->setValidationException($validation_exception) 81 81 ->setForm($form); 82 82
+2 -2
src/applications/people/controller/PhabricatorPeopleProfilePictureController.php
··· 155 155 if (PhabricatorEnv::getEnvConfig('security.allow-outbound-http')) { 156 156 $emails = id(new PhabricatorUserEmail())->loadAllWhere( 157 157 'userPHID = %s ORDER BY address', 158 - $viewer->getPHID()); 158 + $user->getPHID()); 159 159 160 160 $futures = array(); 161 161 foreach ($emails as $email_object) { ··· 262 262 ->setForm($form); 263 263 264 264 $upload_form = id(new AphrontFormView()) 265 - ->setUser($user) 265 + ->setUser($viewer) 266 266 ->setEncType('multipart/form-data') 267 267 ->appendChild( 268 268 id(new AphrontFormFileControl())
+5 -1
src/applications/people/storage/PhabricatorUser.php
··· 739 739 case PhabricatorPolicyCapability::CAN_VIEW: 740 740 return PhabricatorPolicies::POLICY_PUBLIC; 741 741 case PhabricatorPolicyCapability::CAN_EDIT: 742 - return PhabricatorPolicies::POLICY_NOONE; 742 + if ($this->getIsSystemAgent()) { 743 + return PhabricatorPolicies::POLICY_ADMIN; 744 + } else { 745 + return PhabricatorPolicies::POLICY_NOONE; 746 + } 743 747 } 744 748 } 745 749