1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-02 01:48:23 +01:00
phorge-phorge/src/applications/auth/storage/PhabricatorAuthMessage.php

139 lines
3.3 KiB
PHP
Raw Normal View History

Add "Auth Messages" to support customizing onboarding/welcome flows Summary: Ref T13222. Long ago, we had a Config option (`welcome.html`) to let you dump HTML onto the login screen, but this was relatively hard to use and not good from a security perspective. In some cases this was obsoleted by Dashboards, but there's at least some remaining set of use cases for actual login instructions on the login screen. For example, WMF has some guidance on //which// SSO mechanism to use based on what types of account you have. On `secure`, users assume they can register by clicking "Log In With GitHub" or whatever, and it might reduce frustration to tell them upfront that registration is closed. Some other types of auth messaging could also either use customization or defaults (e.g., the invite/welcome/approve mail). We could do this with a bunch of Config options, but I'd generally like to move to a world where there's less stuff in Config and more configuration is contextual. I think it tends to be easier to use, and we get a lot of fringe benefits (granular permissions, API, normal transaction logs, more abililty to customize workflows and provide contextual help/hints, etc). Here, for example, we can provide a remarkup preview, which would be trickier with Config. This does not actually do anything yet. Test Plan: {F6137541} Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13222 Differential Revision: https://secure.phabricator.com/D19992
2019-01-17 10:47:13 -08:00
<?php
final class PhabricatorAuthMessage
extends PhabricatorAuthDAO
implements
PhabricatorApplicationTransactionInterface,
PhabricatorPolicyInterface,
PhabricatorDestructibleInterface {
protected $messageKey;
protected $messageText;
private $messageType = self::ATTACHABLE;
public static function initializeNewMessage(
PhabricatorAuthMessageType $type) {
return id(new self())
->setMessageKey($type->getMessageTypeKey())
->attachMessageType($type);
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'messageKey' => 'text64',
'messageText' => 'text',
),
self::CONFIG_KEY_SCHEMA => array(
'key_type' => array(
'columns' => array('messageKey'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
public function getPHIDType() {
return PhabricatorAuthMessagePHIDType::TYPECONST;
}
public function getObjectName() {
return pht('Auth Message %d', $this->getID());
}
public function getURI() {
return urisprintf('/auth/message/%s', $this->getID());
}
public function attachMessageType(PhabricatorAuthMessageType $type) {
$this->messageType = $type;
return $this;
}
public function getMessageType() {
return $this->assertAttached($this->messageType);
}
public function getMessageTypeDisplayName() {
return $this->getMessageType()->getDisplayName();
}
public static function loadMessage(
PhabricatorUser $viewer,
$message_key) {
return id(new PhabricatorAuthMessageQuery())
->setViewer($viewer)
->withMessageKeys(array($message_key))
->executeOne();
}
public static function loadMessageText(
PhabricatorUser $viewer,
$message_key) {
$message = self::loadMessage($viewer, $message_key);
if (!$message) {
return null;
}
return $message->getMessageText();
}
Add "Auth Messages" to support customizing onboarding/welcome flows Summary: Ref T13222. Long ago, we had a Config option (`welcome.html`) to let you dump HTML onto the login screen, but this was relatively hard to use and not good from a security perspective. In some cases this was obsoleted by Dashboards, but there's at least some remaining set of use cases for actual login instructions on the login screen. For example, WMF has some guidance on //which// SSO mechanism to use based on what types of account you have. On `secure`, users assume they can register by clicking "Log In With GitHub" or whatever, and it might reduce frustration to tell them upfront that registration is closed. Some other types of auth messaging could also either use customization or defaults (e.g., the invite/welcome/approve mail). We could do this with a bunch of Config options, but I'd generally like to move to a world where there's less stuff in Config and more configuration is contextual. I think it tends to be easier to use, and we get a lot of fringe benefits (granular permissions, API, normal transaction logs, more abililty to customize workflows and provide contextual help/hints, etc). Here, for example, we can provide a remarkup preview, which would be trickier with Config. This does not actually do anything yet. Test Plan: {F6137541} Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13222 Differential Revision: https://secure.phabricator.com/D19992
2019-01-17 10:47:13 -08:00
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::getMostOpenPolicy();
default:
return false;
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
// Even if an install doesn't allow public users, you can still view
// auth messages: otherwise, we can't do things like show you
// guidance on the login screen.
return true;
default:
return false;
}
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new PhabricatorAuthMessageEditor();
}
public function getApplicationTransactionTemplate() {
return new PhabricatorAuthMessageTransaction();
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->delete();
}
}