Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/storage/PhabricatorUserPreferences.php
| <?php | <?php | ||||
| final class PhabricatorUserPreferences extends PhabricatorUserDAO { | final class PhabricatorUserPreferences | ||||
| extends PhabricatorUserDAO | |||||
| implements | |||||
| PhabricatorPolicyInterface, | |||||
| PhabricatorDestructibleInterface, | |||||
| PhabricatorApplicationTransactionInterface { | |||||
| const PREFERENCE_MONOSPACED = 'monospaced'; | const PREFERENCE_MONOSPACED = 'monospaced'; | ||||
| const PREFERENCE_DARK_CONSOLE = 'dark_console'; | const PREFERENCE_DARK_CONSOLE = 'dark_console'; | ||||
| const PREFERENCE_EDITOR = 'editor'; | const PREFERENCE_EDITOR = 'editor'; | ||||
| const PREFERENCE_MULTIEDIT = 'multiedit'; | const PREFERENCE_MULTIEDIT = 'multiedit'; | ||||
| const PREFERENCE_TITLES = 'titles'; | const PREFERENCE_TITLES = 'titles'; | ||||
| const PREFERENCE_MONOSPACED_TEXTAREAS = 'monospaced-textareas'; | const PREFERENCE_MONOSPACED_TEXTAREAS = 'monospaced-textareas'; | ||||
| const PREFERENCE_DATE_FORMAT = 'date-format'; | const PREFERENCE_DATE_FORMAT = 'date-format'; | ||||
| Show All 34 Lines | final class PhabricatorUserPreferences | ||||
| // These are in an unusual order for historic reasons. | // These are in an unusual order for historic reasons. | ||||
| const MAILTAG_PREFERENCE_NOTIFY = 0; | const MAILTAG_PREFERENCE_NOTIFY = 0; | ||||
| const MAILTAG_PREFERENCE_EMAIL = 1; | const MAILTAG_PREFERENCE_EMAIL = 1; | ||||
| const MAILTAG_PREFERENCE_IGNORE = 2; | const MAILTAG_PREFERENCE_IGNORE = 2; | ||||
| protected $userPHID; | protected $userPHID; | ||||
| protected $preferences = array(); | protected $preferences = array(); | ||||
| private $user = self::ATTACHABLE; | |||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_AUX_PHID => true, | |||||
| self::CONFIG_SERIALIZATION => array( | self::CONFIG_SERIALIZATION => array( | ||||
| 'preferences' => self::SERIALIZATION_JSON, | 'preferences' => self::SERIALIZATION_JSON, | ||||
| ), | ), | ||||
| self::CONFIG_TIMESTAMPS => false, | |||||
| self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
| 'userPHID' => array( | 'userPHID' => array( | ||||
| 'columns' => array('userPHID'), | 'columns' => array('userPHID'), | ||||
| 'unique' => true, | 'unique' => true, | ||||
| ), | ), | ||||
| ), | ), | ||||
| ) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
| } | } | ||||
| public function generatePHID() { | |||||
| return PhabricatorPHID::generateNewPHID( | |||||
| PhabricatorUserPreferencesPHIDType::TYPECONST); | |||||
| } | |||||
| public function getPreference($key, $default = null) { | public function getPreference($key, $default = null) { | ||||
| return idx($this->preferences, $key, $default); | return idx($this->preferences, $key, $default); | ||||
| } | } | ||||
| public function setPreference($key, $value) { | public function setPreference($key, $value) { | ||||
| $this->preferences[$key] = $value; | $this->preferences[$key] = $value; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| Show All 33 Lines | public function getPinnedApplications(array $apps, PhabricatorUser $viewer) { | ||||
| return $large; | return $large; | ||||
| } | } | ||||
| public static function filterMonospacedCSSRule($monospaced) { | public static function filterMonospacedCSSRule($monospaced) { | ||||
| // Prevent the user from doing dangerous things. | // Prevent the user from doing dangerous things. | ||||
| return preg_replace('([^a-z0-9 ,"./]+)i', '', $monospaced); | return preg_replace('([^a-z0-9 ,"./]+)i', '', $monospaced); | ||||
| } | } | ||||
| public function attachUser(PhabricatorUser $user = null) { | |||||
| $this->user = $user; | |||||
| return $this; | |||||
| } | |||||
| public function getUser() { | |||||
| return $this->assertAttached($this->user); | |||||
| } | |||||
| public function hasManagedUser() { | |||||
| $user_phid = $this->getUserPHID(); | |||||
| if (!$user_phid) { | |||||
| return false; | |||||
| } | |||||
| $user = $this->getUser(); | |||||
| if ($user->getIsSystemAgent() || $user->getIsMailingList()) { | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /* -( PhabricatorPolicyInterface )----------------------------------------- */ | |||||
| public function getCapabilities() { | |||||
| return array( | |||||
| PhabricatorPolicyCapability::CAN_VIEW, | |||||
| PhabricatorPolicyCapability::CAN_EDIT, | |||||
| ); | |||||
| } | |||||
| public function getPolicy($capability) { | |||||
| switch ($capability) { | |||||
| case PhabricatorPolicyCapability::CAN_VIEW: | |||||
| $user_phid = $this->getUserPHID(); | |||||
| if ($user_phid) { | |||||
| return $user_phid; | |||||
| } | |||||
| return PhabricatorPolicies::getMostOpenPolicy(); | |||||
| case PhabricatorPolicyCapability::CAN_EDIT: | |||||
| if ($this->hasManagedUser()) { | |||||
| return PhabricatorPolicies::POLICY_ADMIN; | |||||
| } | |||||
| $user_phid = $this->getUserPHID(); | |||||
| if ($user_phid) { | |||||
| return $user_phid; | |||||
| } | |||||
| return PhabricatorPolicies::POLICY_ADMIN; | |||||
| } | |||||
| } | |||||
| public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | |||||
| if ($this->hasManagedUser()) { | |||||
| if ($viewer->getIsAdmin()) { | |||||
| return true; | |||||
| } | |||||
| } | |||||
| return false; | |||||
| } | |||||
| public function describeAutomaticCapability($capability) { | |||||
| return null; | |||||
| } | |||||
| /* -( PhabricatorDestructibleInterface )----------------------------------- */ | |||||
| public function destroyObjectPermanently( | |||||
| PhabricatorDestructionEngine $engine) { | |||||
| $this->delete(); | |||||
| } | |||||
| /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | |||||
| public function getApplicationTransactionEditor() { | |||||
| // TODO: Implement. | |||||
| throw new PhutilMethodNotImplementedException(); | |||||
| } | |||||
| public function getApplicationTransactionObject() { | |||||
| return $this; | |||||
| } | |||||
| public function getApplicationTransactionTemplate() { | |||||
| return new PhabricatorUserPreferencesTransaction(); | |||||
| } | |||||
| public function willRenderTimeline( | |||||
| PhabricatorApplicationTransactionView $timeline, | |||||
| AphrontRequest $request) { | |||||
| return $timeline; | |||||
| } | |||||
| } | } | ||||