From 91ef2372908cfde5365adb8388f745cd4206bf7f Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 1 Mar 2017 14:56:31 -0800 Subject: [PATCH] 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 --- .../autopatches/20170301.subtype.01.col.sql | 2 + .../20170301.subtype.02.default.sql | 2 + src/__phutil_library_map__.php | 4 ++ .../editengine/PhabricatorEditEngine.php | 2 + .../PhabricatorEditEngineSubtype.php | 36 ++++++++++++++++++ .../PhabricatorEditEngineSubtypeTestCase.php | 38 +++++++++++++++++++ .../PhabricatorEditEngineConfiguration.php | 3 ++ 7 files changed, 87 insertions(+) create mode 100644 resources/sql/autopatches/20170301.subtype.01.col.sql create mode 100644 resources/sql/autopatches/20170301.subtype.02.default.sql create mode 100644 src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php create mode 100644 src/applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php diff --git a/resources/sql/autopatches/20170301.subtype.01.col.sql b/resources/sql/autopatches/20170301.subtype.01.col.sql new file mode 100644 index 0000000000..318021f9d0 --- /dev/null +++ b/resources/sql/autopatches/20170301.subtype.01.col.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_search.search_editengineconfiguration + ADD subtype VARCHAR(64) COLLATE {$COLLATE_TEXT} NOT NULL; diff --git a/resources/sql/autopatches/20170301.subtype.02.default.sql b/resources/sql/autopatches/20170301.subtype.02.default.sql new file mode 100644 index 0000000000..e1baedc013 --- /dev/null +++ b/resources/sql/autopatches/20170301.subtype.02.default.sql @@ -0,0 +1,2 @@ +UPDATE {$NAMESPACE}_search.search_editengineconfiguration + SET subtype = 'default' WHERE subtype = ''; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d01186e489..0c6cf98eea 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php index 8bfde17fdd..44b794bceb 100644 --- a/src/applications/transactions/editengine/PhabricatorEditEngine.php +++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php @@ -18,6 +18,8 @@ abstract class PhabricatorEditEngine const EDITENGINECONFIG_DEFAULT = 'default'; + const SUBTYPE_DEFAULT = 'default'; + private $viewer; private $controller; private $isCreate; diff --git a/src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php b/src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php new file mode 100644 index 0000000000..71a66e648a --- /dev/null +++ b/src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php @@ -0,0 +1,36 @@ + 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)); + } + } + + +} diff --git a/src/applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php b/src/applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php new file mode 100644 index 0000000000..6a9248753d --- /dev/null +++ b/src/applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php @@ -0,0 +1,38 @@ + 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)); + } + } +} diff --git a/src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php b/src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php index 130686dd5a..ada979c45c 100644 --- a/src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php +++ b/src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php @@ -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(