mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Add an alias to Phurl URL's
Summary: Ref T8992, Add an alias to Phurl URL's that can be used to redirect to link. Test Plan: Add an alias to Phurl object, and navigate to `local.install.com/u/<newalias>`. This should redirect to the Phurl's URL. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: joshuaspence, Korvin Maniphest Tasks: T8992 Differential Revision: https://secure.phabricator.com/D14395
This commit is contained in:
parent
39f8feab5a
commit
2b05f7cc43
7 changed files with 103 additions and 5 deletions
|
@ -30,6 +30,7 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication {
|
|||
return array(
|
||||
'/U(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLViewController',
|
||||
'/u/(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLAccessController',
|
||||
'/u/(?P<alias>[^/]+)' => 'PhabricatorPhurlURLAccessController',
|
||||
'/phurl/' => array(
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||
=> 'PhabricatorPhurlURLListController',
|
||||
|
|
|
@ -6,11 +6,19 @@ final class PhabricatorPhurlURLAccessController
|
|||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
$alias = $request->getURIData('alias');
|
||||
|
||||
$url = id(new PhabricatorPhurlURLQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
if ($id) {
|
||||
$url = id(new PhabricatorPhurlURLQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
} else if ($alias) {
|
||||
$url = id(new PhabricatorPhurlURLQuery())
|
||||
->setViewer($viewer)
|
||||
->withAliases(array($alias))
|
||||
->executeOne();
|
||||
}
|
||||
|
||||
if (!$url) {
|
||||
return new Aphront404Response();
|
||||
|
|
|
@ -7,10 +7,11 @@ final class PhabricatorPhurlURLEditController
|
|||
$id = $request->getURIData('id');
|
||||
$is_create = !$id;
|
||||
|
||||
$viewer = $request->getViewer();
|
||||
$viewer = $this->getViewer();
|
||||
$user_phid = $viewer->getPHID();
|
||||
$error_name = true;
|
||||
$error_long_url = true;
|
||||
$error_alias = null;
|
||||
$validation_exception = null;
|
||||
|
||||
$next_workflow = $request->getStr('next');
|
||||
|
@ -58,6 +59,7 @@ final class PhabricatorPhurlURLEditController
|
|||
|
||||
$name = $url->getName();
|
||||
$long_url = $url->getLongURL();
|
||||
$alias = $url->getAlias();
|
||||
$description = $url->getDescription();
|
||||
$edit_policy = $url->getEditPolicy();
|
||||
$view_policy = $url->getViewPolicy();
|
||||
|
@ -67,6 +69,7 @@ final class PhabricatorPhurlURLEditController
|
|||
$xactions = array();
|
||||
$name = $request->getStr('name');
|
||||
$long_url = $request->getStr('longURL');
|
||||
$alias = $request->getStr('alias');
|
||||
$projects = $request->getArr('projects');
|
||||
$description = $request->getStr('description');
|
||||
$subscribers = $request->getArr('subscribers');
|
||||
|
@ -84,6 +87,11 @@ final class PhabricatorPhurlURLEditController
|
|||
PhabricatorPhurlURLTransaction::TYPE_URL)
|
||||
->setNewValue($long_url);
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorPhurlURLTransaction::TYPE_ALIAS)
|
||||
->setNewValue($alias);
|
||||
|
||||
$xactions[] = id(new PhabricatorPhurlURLTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorTransactions::TYPE_SUBSCRIBERS)
|
||||
|
@ -127,6 +135,8 @@ final class PhabricatorPhurlURLEditController
|
|||
PhabricatorPhurlURLTransaction::TYPE_NAME);
|
||||
$error_long_url = $ex->getShortMessage(
|
||||
PhabricatorPhurlURLTransaction::TYPE_URL);
|
||||
$error_alias = $ex->getShortMessage(
|
||||
PhabricatorPhurlURLTransaction::TYPE_ALIAS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,6 +157,12 @@ final class PhabricatorPhurlURLEditController
|
|||
->setValue($long_url)
|
||||
->setError($error_long_url);
|
||||
|
||||
$alias = id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Alias'))
|
||||
->setName('alias')
|
||||
->setValue($alias)
|
||||
->setError($error_alias);
|
||||
|
||||
$projects = id(new AphrontFormTokenizerControl())
|
||||
->setLabel(pht('Projects'))
|
||||
->setName('projects')
|
||||
|
@ -187,6 +203,7 @@ final class PhabricatorPhurlURLEditController
|
|||
->setUser($viewer)
|
||||
->appendChild($name)
|
||||
->appendChild($long_url)
|
||||
->appendChild($alias)
|
||||
->appendControl($view_policies)
|
||||
->appendControl($edit_policies)
|
||||
->appendControl($subscribers)
|
||||
|
|
|
@ -129,6 +129,10 @@ final class PhabricatorPhurlURLViewController
|
|||
pht('Original URL'),
|
||||
$url->getLongURL());
|
||||
|
||||
$properties->addProperty(
|
||||
pht('Alias'),
|
||||
$url->getAlias());
|
||||
|
||||
$properties->invokeWillRenderEvent();
|
||||
|
||||
if (strlen($url->getDescription())) {
|
||||
|
|
|
@ -16,6 +16,7 @@ final class PhabricatorPhurlURLEditor
|
|||
|
||||
$types[] = PhabricatorPhurlURLTransaction::TYPE_NAME;
|
||||
$types[] = PhabricatorPhurlURLTransaction::TYPE_URL;
|
||||
$types[] = PhabricatorPhurlURLTransaction::TYPE_ALIAS;
|
||||
$types[] = PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION;
|
||||
|
||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||
|
@ -33,6 +34,8 @@ final class PhabricatorPhurlURLEditor
|
|||
return $object->getName();
|
||||
case PhabricatorPhurlURLTransaction::TYPE_URL:
|
||||
return $object->getLongURL();
|
||||
case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
|
||||
return $object->getAlias();
|
||||
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
|
||||
return $object->getDescription();
|
||||
}
|
||||
|
@ -46,6 +49,7 @@ final class PhabricatorPhurlURLEditor
|
|||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorPhurlURLTransaction::TYPE_NAME:
|
||||
case PhabricatorPhurlURLTransaction::TYPE_URL:
|
||||
case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
|
||||
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
|
||||
return $xaction->getNewValue();
|
||||
}
|
||||
|
@ -64,6 +68,9 @@ final class PhabricatorPhurlURLEditor
|
|||
case PhabricatorPhurlURLTransaction::TYPE_URL:
|
||||
$object->setLongURL($xaction->getNewValue());
|
||||
return;
|
||||
case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
|
||||
$object->setAlias($xaction->getNewValue());
|
||||
return;
|
||||
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
|
||||
$object->setDescription($xaction->getNewValue());
|
||||
return;
|
||||
|
@ -79,6 +86,7 @@ final class PhabricatorPhurlURLEditor
|
|||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorPhurlURLTransaction::TYPE_NAME:
|
||||
case PhabricatorPhurlURLTransaction::TYPE_URL:
|
||||
case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
|
||||
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
|
||||
return;
|
||||
}
|
||||
|
@ -109,6 +117,28 @@ final class PhabricatorPhurlURLEditor
|
|||
$error->setIsMissingFieldError(true);
|
||||
$errors[] = $error;
|
||||
}
|
||||
break;
|
||||
case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
|
||||
foreach ($xactions as $xaction) {
|
||||
if ($xaction->getOldValue() != $xaction->getNewValue()) {
|
||||
$new_alias = $xaction->getNewValue();
|
||||
if (!preg_match('/[a-zA-Z]/', $new_alias)) {
|
||||
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
||||
$type,
|
||||
pht('Invalid Alias'),
|
||||
pht('The alias must contain at least one letter.'),
|
||||
$xaction);
|
||||
}
|
||||
if (preg_match('/[^a-z0-9]/i', $new_alias)) {
|
||||
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
||||
$type,
|
||||
pht('Invalid Alias'),
|
||||
pht('The alias may only contain letters and numbers.'),
|
||||
$xaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case PhabricatorPhurlURLTransaction::TYPE_URL:
|
||||
$missing = $this->validateIsEmptyTextField(
|
||||
|
|
|
@ -7,6 +7,7 @@ final class PhabricatorPhurlURLQuery
|
|||
private $phids;
|
||||
private $names;
|
||||
private $longURLs;
|
||||
private $aliases;
|
||||
private $authorPHIDs;
|
||||
|
||||
public function newResultObject() {
|
||||
|
@ -33,6 +34,11 @@ final class PhabricatorPhurlURLQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withAliases(array $aliases) {
|
||||
$this->aliases = $aliases;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withAuthorPHIDs(array $author_phids) {
|
||||
$this->authorPHIDs = $author_phids;
|
||||
return $this;
|
||||
|
@ -87,6 +93,13 @@ final class PhabricatorPhurlURLQuery
|
|||
$this->longURLs);
|
||||
}
|
||||
|
||||
if ($this->aliases !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'url.alias IN (%Ls)',
|
||||
$this->aliases);
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ final class PhabricatorPhurlURLTransaction
|
|||
|
||||
const TYPE_NAME = 'phurl.name';
|
||||
const TYPE_URL = 'phurl.longurl';
|
||||
const TYPE_ALIAS = 'phurl.alias';
|
||||
const TYPE_DESCRIPTION = 'phurl.description';
|
||||
|
||||
const MAILTAG_CONTENT = 'phurl:content';
|
||||
|
@ -28,6 +29,7 @@ final class PhabricatorPhurlURLTransaction
|
|||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_NAME:
|
||||
case self::TYPE_URL:
|
||||
case self::TYPE_ALIAS:
|
||||
case self::TYPE_DESCRIPTION:
|
||||
$phids[] = $this->getObjectPHID();
|
||||
break;
|
||||
|
@ -49,6 +51,7 @@ final class PhabricatorPhurlURLTransaction
|
|||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_NAME:
|
||||
case self::TYPE_URL:
|
||||
case self::TYPE_ALIAS:
|
||||
case self::TYPE_DESCRIPTION:
|
||||
return 'fa-pencil';
|
||||
break;
|
||||
|
@ -83,6 +86,12 @@ final class PhabricatorPhurlURLTransaction
|
|||
$this->renderHandleLink($author_phid),
|
||||
$old,
|
||||
$new);
|
||||
case self::TYPE_ALIAS:
|
||||
return pht(
|
||||
'%s changed the alias of the URL from %s to %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$old,
|
||||
$new);
|
||||
case self::TYPE_DESCRIPTION:
|
||||
return pht(
|
||||
"%s updated the URL's description.",
|
||||
|
@ -130,6 +139,20 @@ final class PhabricatorPhurlURLTransaction
|
|||
$old,
|
||||
$new);
|
||||
}
|
||||
case self::TYPE_ALIAS:
|
||||
if ($old === null) {
|
||||
return pht(
|
||||
'%s created %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
} else {
|
||||
return pht(
|
||||
'%s changed the alias of %s from %s to %s',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid),
|
||||
$old,
|
||||
$new);
|
||||
}
|
||||
case self::TYPE_DESCRIPTION:
|
||||
return pht(
|
||||
'%s updated the description of %s.',
|
||||
|
@ -147,6 +170,7 @@ final class PhabricatorPhurlURLTransaction
|
|||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_NAME:
|
||||
case self::TYPE_URL:
|
||||
case self::TYPE_ALIAS:
|
||||
case self::TYPE_DESCRIPTION:
|
||||
return PhabricatorTransactions::COLOR_GREEN;
|
||||
}
|
||||
|
@ -185,6 +209,7 @@ final class PhabricatorPhurlURLTransaction
|
|||
case self::TYPE_NAME:
|
||||
case self::TYPE_DESCRIPTION:
|
||||
case self::TYPE_URL:
|
||||
case self::TYPE_ALIAS:
|
||||
$tags[] = self::MAILTAG_CONTENT;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue