Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / auth / storage / PhabricatorAuthMessage.php
blob9969d7adeddacaeaf369ce14423962a698e67eda
1 <?php
3 final class PhabricatorAuthMessage
4 extends PhabricatorAuthDAO
5 implements
6 PhabricatorApplicationTransactionInterface,
7 PhabricatorPolicyInterface,
8 PhabricatorDestructibleInterface {
10 protected $messageKey;
11 protected $messageText;
13 private $messageType = self::ATTACHABLE;
15 public static function initializeNewMessage(
16 PhabricatorAuthMessageType $type) {
18 return id(new self())
19 ->setMessageKey($type->getMessageTypeKey())
20 ->attachMessageType($type);
23 protected function getConfiguration() {
24 return array(
25 self::CONFIG_AUX_PHID => true,
26 self::CONFIG_COLUMN_SCHEMA => array(
27 'messageKey' => 'text64',
28 'messageText' => 'text',
30 self::CONFIG_KEY_SCHEMA => array(
31 'key_type' => array(
32 'columns' => array('messageKey'),
33 'unique' => true,
36 ) + parent::getConfiguration();
39 public function getPHIDType() {
40 return PhabricatorAuthMessagePHIDType::TYPECONST;
43 public function getObjectName() {
44 return pht('Auth Message %d', $this->getID());
47 public function getURI() {
48 return urisprintf('/auth/message/%s/', $this->getID());
51 public function attachMessageType(PhabricatorAuthMessageType $type) {
52 $this->messageType = $type;
53 return $this;
56 public function getMessageType() {
57 return $this->assertAttached($this->messageType);
60 public function getMessageTypeDisplayName() {
61 return $this->getMessageType()->getDisplayName();
64 public static function loadMessage(
65 PhabricatorUser $viewer,
66 $message_key) {
67 return id(new PhabricatorAuthMessageQuery())
68 ->setViewer($viewer)
69 ->withMessageKeys(array($message_key))
70 ->executeOne();
73 public static function loadMessageText(
74 PhabricatorUser $viewer,
75 $message_key) {
77 $message = self::loadMessage($viewer, $message_key);
78 if ($message) {
79 $message_text = $message->getMessageText();
80 if (strlen($message_text)) {
81 return $message_text;
85 $message_type = PhabricatorAuthMessageType::newFromKey($message_key);
87 return $message_type->getDefaultMessageText();
91 /* -( PhabricatorPolicyInterface )----------------------------------------- */
94 public function getCapabilities() {
95 return array(
96 PhabricatorPolicyCapability::CAN_VIEW,
97 PhabricatorPolicyCapability::CAN_EDIT,
101 public function getPolicy($capability) {
102 switch ($capability) {
103 case PhabricatorPolicyCapability::CAN_VIEW:
104 return PhabricatorPolicies::getMostOpenPolicy();
105 default:
106 return false;
110 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
111 switch ($capability) {
112 case PhabricatorPolicyCapability::CAN_VIEW:
113 // Even if an install doesn't allow public users, you can still view
114 // auth messages: otherwise, we can't do things like show you
115 // guidance on the login screen.
116 return true;
117 default:
118 return false;
122 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
125 public function getApplicationTransactionEditor() {
126 return new PhabricatorAuthMessageEditor();
129 public function getApplicationTransactionTemplate() {
130 return new PhabricatorAuthMessageTransaction();
134 /* -( PhabricatorDestructibleInterface )----------------------------------- */
137 public function destroyObjectPermanently(
138 PhabricatorDestructionEngine $engine) {
139 $this->delete();