Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorSettingsPanel.php
| Show All 12 Lines | |||||
| */ | */ | ||||
| abstract class PhabricatorSettingsPanel extends Phobject { | abstract class PhabricatorSettingsPanel extends Phobject { | ||||
| private $user; | private $user; | ||||
| private $viewer; | private $viewer; | ||||
| private $controller; | private $controller; | ||||
| private $navigation; | private $navigation; | ||||
| private $overrideURI; | private $overrideURI; | ||||
| private $preferences; | |||||
| public function setUser(PhabricatorUser $user) { | public function setUser(PhabricatorUser $user) { | ||||
| $this->user = $user; | $this->user = $user; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getUser() { | public function getUser() { | ||||
| return $this->user; | return $this->user; | ||||
| Show All 26 Lines | final public function setNavigation(AphrontSideNavFilterView $navigation) { | ||||
| $this->navigation = $navigation; | $this->navigation = $navigation; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| final public function getNavigation() { | final public function getNavigation() { | ||||
| return $this->navigation; | return $this->navigation; | ||||
| } | } | ||||
| public function setPreferences(PhabricatorUserPreferences $preferences) { | |||||
| $this->preferences = $preferences; | |||||
| return $this; | |||||
| } | |||||
| public function getPreferences() { | |||||
| return $this->preferences; | |||||
| } | |||||
| final public static function getAllPanels() { | final public static function getAllPanels() { | ||||
| $panels = id(new PhutilClassMapQuery()) | $panels = id(new PhutilClassMapQuery()) | ||||
| ->setAncestorClass(__CLASS__) | ->setAncestorClass(__CLASS__) | ||||
| ->setUniqueMethod('getPanelKey') | ->setUniqueMethod('getPanelKey') | ||||
| ->execute(); | ->execute(); | ||||
| return msortv($panels, 'getPanelOrderVector'); | return msortv($panels, 'getPanelOrderVector'); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | /* -( Panel Configuration )------------------------------------------------ */ | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| public function isEnabled() { | public function isEnabled() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | /** | ||||
| * Return true if this panel is available to administrators while editing | * Return true if this panel is available to administrators while managing | ||||
| * system agent accounts. | * bot and mailing list accounts. | ||||
| * | * | ||||
| * @return bool True to enable edit by administrators. | * @return bool True to enable management on behalf of accounts. | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| public function isEditableByAdministrators() { | public function isManagementPanel() { | ||||
| return false; | |||||
| } | |||||
| /** | |||||
| * Return true if this panel is available while editing settings templates. | |||||
| * | |||||
| * @return bool True to allow editing in templates. | |||||
| * @task config | |||||
| */ | |||||
| public function isTemplatePanel() { | |||||
| return false; | return false; | ||||
| } | } | ||||
| /* -( Panel Implementation )----------------------------------------------- */ | /* -( Panel Implementation )----------------------------------------------- */ | ||||
| /** | /** | ||||
| Show All 26 Lines | final public function getPanelURI($path = '') { | ||||
| if ($this->overrideURI) { | if ($this->overrideURI) { | ||||
| return rtrim($this->overrideURI, '/').'/'.$path; | return rtrim($this->overrideURI, '/').'/'.$path; | ||||
| } | } | ||||
| $key = $this->getPanelKey(); | $key = $this->getPanelKey(); | ||||
| $key = phutil_escape_uri($key); | $key = phutil_escape_uri($key); | ||||
| if ($this->getUser()->getPHID() != $this->getViewer()->getPHID()) { | $user = $this->getUser(); | ||||
| $user_id = $this->getUser()->getID(); | if ($user) { | ||||
| return "/settings/{$user_id}/panel/{$key}/{$path}"; | $username = $user->getUsername(); | ||||
| return "/settings/user/{$username}/page/{$key}/{$path}"; | |||||
| } else { | } else { | ||||
| return "/settings/panel/{$key}/{$path}"; | $builtin = $this->getPreferences()->getBuiltinKey(); | ||||
| return "/settings/builtin/{$builtin}/page/{$key}/{$path}"; | |||||
| } | } | ||||
| } | } | ||||
| /* -( Internals )---------------------------------------------------------- */ | /* -( Internals )---------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * Generates a key to sort the list of panels. | * Generates a key to sort the list of panels. | ||||
| * | * | ||||
| * @return string Sortable key. | * @return string Sortable key. | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| final public function getPanelOrderVector() { | final public function getPanelOrderVector() { | ||||
| return id(new PhutilSortVector()) | return id(new PhutilSortVector()) | ||||
| ->addString($this->getPanelName()); | ->addString($this->getPanelName()); | ||||
| } | } | ||||
| protected function loadTargetPreferences() { | |||||
| $viewer = $this->getViewer(); | |||||
| $user = $this->getUser(); | |||||
| $preferences = PhabricatorUserPreferences::loadUserPreferences($user); | |||||
| PhabricatorPolicyFilter::requireCapability( | |||||
| $viewer, | |||||
| $preferences, | |||||
| PhabricatorPolicyCapability::CAN_EDIT); | |||||
| return $preferences; | |||||
| } | |||||
| protected function newDialog() { | protected function newDialog() { | ||||
| return $this->getController()->newDialog(); | return $this->getController()->newDialog(); | ||||
| } | } | ||||
| protected function writeSetting( | protected function writeSetting( | ||||
| PhabricatorUserPreferences $preferences, | PhabricatorUserPreferences $preferences, | ||||
| $key, | $key, | ||||
| $value) { | $value) { | ||||
| Show All 15 Lines | |||||