mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 04:42:40 +01:00
Add a "subtype" field to EditEngine forms
Summary: Ref T12314. This adds storage so EditEngine forms can later be marked as edit fields for particular types of objects (like an "animal edit form" vs a "plant edit form"). We'll take you to the right edit form when you click "Edit" by selecting among forms with the same subtype as the task. This doesn't do anything very interesting on its own. Test Plan: - Ran `bin/storage upgrade`. - Verified database got the field with proper values. - Created a new form, checked the database. - Ran unit tests. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12314 Differential Revision: https://secure.phabricator.com/D17439
This commit is contained in:
parent
fcd8c9c240
commit
91ef237290
7 changed files with 87 additions and 0 deletions
2
resources/sql/autopatches/20170301.subtype.01.col.sql
Normal file
2
resources/sql/autopatches/20170301.subtype.01.col.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_search.search_editengineconfiguration
|
||||
ADD subtype VARCHAR(64) COLLATE {$COLLATE_TEXT} NOT NULL;
|
|
@ -0,0 +1,2 @@
|
|||
UPDATE {$NAMESPACE}_search.search_editengineconfiguration
|
||||
SET subtype = 'default' WHERE subtype = '';
|
|
@ -2624,6 +2624,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorEditEngineSelectCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineSelectCommentAction.php',
|
||||
'PhabricatorEditEngineSettingsPanel' => 'applications/settings/panel/PhabricatorEditEngineSettingsPanel.php',
|
||||
'PhabricatorEditEngineStaticCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineStaticCommentAction.php',
|
||||
'PhabricatorEditEngineSubtype' => 'applications/transactions/editengine/PhabricatorEditEngineSubtype.php',
|
||||
'PhabricatorEditEngineSubtypeTestCase' => 'applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php',
|
||||
'PhabricatorEditEngineTokenizerCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineTokenizerCommentAction.php',
|
||||
'PhabricatorEditField' => 'applications/transactions/editfield/PhabricatorEditField.php',
|
||||
'PhabricatorEditPage' => 'applications/transactions/editengine/PhabricatorEditPage.php',
|
||||
|
@ -7678,6 +7680,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorEditEngineSelectCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||
'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorEditEngineStaticCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||
'PhabricatorEditEngineSubtype' => 'Phobject',
|
||||
'PhabricatorEditEngineSubtypeTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorEditEngineTokenizerCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||
'PhabricatorEditField' => 'Phobject',
|
||||
'PhabricatorEditPage' => 'Phobject',
|
||||
|
|
|
@ -18,6 +18,8 @@ abstract class PhabricatorEditEngine
|
|||
|
||||
const EDITENGINECONFIG_DEFAULT = 'default';
|
||||
|
||||
const SUBTYPE_DEFAULT = 'default';
|
||||
|
||||
private $viewer;
|
||||
private $controller;
|
||||
private $isCreate;
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
|
||||
final class PhabricatorEditEngineSubtype
|
||||
extends Phobject {
|
||||
|
||||
const SUBTYPE_DEFAULT = 'default';
|
||||
|
||||
public static function validateSubtypeKey($subtype) {
|
||||
if (strlen($subtype) > 64) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Subtype "%s" is not valid: subtype keys must be no longer than '.
|
||||
'64 bytes.',
|
||||
$subtype));
|
||||
}
|
||||
|
||||
if (strlen($subtype) < 3) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Subtype "%s" is not valid: subtype keys must have a minimum '.
|
||||
'length of 3 bytes.',
|
||||
$subtype));
|
||||
}
|
||||
|
||||
if (!preg_match('/^[a-z]+\z/', $subtype)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Subtype "%s" is not valid: subtype keys may only contain '.
|
||||
'lowercase latin letters ("a" through "z").',
|
||||
$subtype));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorEditEngineSubtypeTestCase
|
||||
extends PhabricatorTestCase {
|
||||
|
||||
public function testEditEngineSubtypeKeys() {
|
||||
$map = array(
|
||||
// Too short.
|
||||
'a' => false,
|
||||
'ab' => false,
|
||||
|
||||
// Too long.
|
||||
'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm'.
|
||||
'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm' => false,
|
||||
|
||||
// Junk.
|
||||
'!_(#(31 1~' => false,
|
||||
|
||||
// These are reasonable and valid.
|
||||
'default' => true,
|
||||
'bug' => true,
|
||||
'feature' => true,
|
||||
'risk' => true,
|
||||
'security' => true,
|
||||
);
|
||||
|
||||
foreach ($map as $input => $expect) {
|
||||
try {
|
||||
PhabricatorEditEngineSubtype::validateSubtypeKey($input);
|
||||
$actual = true;
|
||||
} catch (Exception $ex) {
|
||||
$actual = false;
|
||||
}
|
||||
|
||||
$this->assertEqual($expect, $actual, pht('Subtype Key "%s"', $input));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ final class PhabricatorEditEngineConfiguration
|
|||
protected $isEdit = 0;
|
||||
protected $createOrder = 0;
|
||||
protected $editOrder = 0;
|
||||
protected $subtype;
|
||||
|
||||
private $engine = self::ATTACHABLE;
|
||||
|
||||
|
@ -32,6 +33,7 @@ final class PhabricatorEditEngineConfiguration
|
|||
PhabricatorEditEngine $engine) {
|
||||
|
||||
return id(new PhabricatorEditEngineConfiguration())
|
||||
->setSubtype(PhabricatorEditEngine::SUBTYPE_DEFAULT)
|
||||
->setEngineKey($engine->getEngineKey())
|
||||
->attachEngine($engine)
|
||||
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy());
|
||||
|
@ -84,6 +86,7 @@ final class PhabricatorEditEngineConfiguration
|
|||
'isEdit' => 'bool',
|
||||
'createOrder' => 'uint32',
|
||||
'editOrder' => 'uint32',
|
||||
'subtype' => 'text64',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'key_engine' => array(
|
||||
|
|
Loading…
Reference in a new issue