From 814b586f5d3d232d741ddb02256ca6eedfa9a7fc Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 10 Jun 2015 15:53:51 -0700 Subject: [PATCH] Add a "Description" field to Spaces Summary: Ref T8377. - Add a description field. - Add edges so files can be attached. Test Plan: {F492410} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8377 Differential Revision: https://secure.phabricator.com/D13235 --- .../autopatches/20150610.spaces.1.desc.sql | 2 + .../autopatches/20150610.spaces.2.edge.sql | 16 ++++++++ src/__phutil_library_map__.php | 2 + .../PhabricatorSpacesEditController.php | 12 ++++++ .../PhabricatorSpacesViewController.php | 14 +++++++ .../PhabricatorSpacesNamespaceEditor.php | 11 ++++++ .../PhabricatorSpacesNamespacePHIDType.php | 7 +++- .../storage/PhabricatorSpacesNamespace.php | 5 ++- .../PhabricatorSpacesNamespaceTransaction.php | 37 +++++++++++++++++++ .../storage/PhabricatorSpacesSchemaSpec.php | 10 +++++ 10 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 resources/sql/autopatches/20150610.spaces.1.desc.sql create mode 100644 resources/sql/autopatches/20150610.spaces.2.edge.sql create mode 100644 src/applications/spaces/storage/PhabricatorSpacesSchemaSpec.php diff --git a/resources/sql/autopatches/20150610.spaces.1.desc.sql b/resources/sql/autopatches/20150610.spaces.1.desc.sql new file mode 100644 index 0000000000..c62cd8aece --- /dev/null +++ b/resources/sql/autopatches/20150610.spaces.1.desc.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_spaces.spaces_namespace + ADD description LONGTEXT COLLATE {$COLLATE_TEXT} NOT NULL; diff --git a/resources/sql/autopatches/20150610.spaces.2.edge.sql b/resources/sql/autopatches/20150610.spaces.2.edge.sql new file mode 100644 index 0000000000..bc72ed2225 --- /dev/null +++ b/resources/sql/autopatches/20150610.spaces.2.edge.sql @@ -0,0 +1,16 @@ +CREATE TABLE {$NAMESPACE}_spaces.edge ( + src VARBINARY(64) NOT NULL, + type INT UNSIGNED NOT NULL, + dst VARBINARY(64) NOT NULL, + dateCreated INT UNSIGNED NOT NULL, + seq INT UNSIGNED NOT NULL, + dataID INT UNSIGNED, + PRIMARY KEY (src, type, dst), + KEY `src` (src, type, dateCreated, seq), + UNIQUE KEY `key_dst` (dst, type, src) +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; + +CREATE TABLE {$NAMESPACE}_spaces.edgedata ( + id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + data LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT} +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c389400972..e3ba379280 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2594,6 +2594,7 @@ phutil_register_library_map(array( 'PhabricatorSpacesNamespaceTransaction' => 'applications/spaces/storage/PhabricatorSpacesNamespaceTransaction.php', 'PhabricatorSpacesNamespaceTransactionQuery' => 'applications/spaces/query/PhabricatorSpacesNamespaceTransactionQuery.php', 'PhabricatorSpacesRemarkupRule' => 'applications/spaces/remarkup/PhabricatorSpacesRemarkupRule.php', + 'PhabricatorSpacesSchemaSpec' => 'applications/spaces/storage/PhabricatorSpacesSchemaSpec.php', 'PhabricatorSpacesTestCase' => 'applications/spaces/__tests__/PhabricatorSpacesTestCase.php', 'PhabricatorSpacesViewController' => 'applications/spaces/controller/PhabricatorSpacesViewController.php', 'PhabricatorStandardCustomField' => 'infrastructure/customfield/standard/PhabricatorStandardCustomField.php', @@ -6110,6 +6111,7 @@ phutil_register_library_map(array( 'PhabricatorSpacesNamespaceTransaction' => 'PhabricatorApplicationTransaction', 'PhabricatorSpacesNamespaceTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhabricatorSpacesRemarkupRule' => 'PhabricatorObjectRemarkupRule', + 'PhabricatorSpacesSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhabricatorSpacesTestCase' => 'PhabricatorTestCase', 'PhabricatorSpacesViewController' => 'PhabricatorSpacesController', 'PhabricatorStandardCustomField' => 'PhabricatorCustomField', diff --git a/src/applications/spaces/controller/PhabricatorSpacesEditController.php b/src/applications/spaces/controller/PhabricatorSpacesEditController.php index b64a16ab97..4dfeeed7ed 100644 --- a/src/applications/spaces/controller/PhabricatorSpacesEditController.php +++ b/src/applications/spaces/controller/PhabricatorSpacesEditController.php @@ -54,6 +54,7 @@ final class PhabricatorSpacesEditController $validation_exception = null; $e_name = true; $v_name = $space->getNamespaceName(); + $v_desc = $space->getDescription(); $v_view = $space->getViewPolicy(); $v_edit = $space->getEditPolicy(); @@ -62,10 +63,12 @@ final class PhabricatorSpacesEditController $e_name = null; $v_name = $request->getStr('name'); + $v_desc = $request->getStr('description'); $v_view = $request->getStr('viewPolicy'); $v_edit = $request->getStr('editPolicy'); $type_name = PhabricatorSpacesNamespaceTransaction::TYPE_NAME; + $type_desc = PhabricatorSpacesNamespaceTransaction::TYPE_DESCRIPTION; $type_default = PhabricatorSpacesNamespaceTransaction::TYPE_DEFAULT; $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; @@ -74,6 +77,10 @@ final class PhabricatorSpacesEditController ->setTransactionType($type_name) ->setNewValue($v_name); + $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) + ->setTransactionType($type_desc) + ->setNewValue($v_desc); + $xactions[] = id(new PhabricatorSpacesNamespaceTransaction()) ->setTransactionType($type_view) ->setNewValue($v_view); @@ -128,6 +135,11 @@ final class PhabricatorSpacesEditController ->setName('name') ->setValue($v_name) ->setError($e_name)) + ->appendControl( + id(new PhabricatorRemarkupControl()) + ->setLabel(pht('Description')) + ->setName('description') + ->setValue($v_desc)) ->appendChild( id(new AphrontFormPolicyControl()) ->setUser($viewer) diff --git a/src/applications/spaces/controller/PhabricatorSpacesViewController.php b/src/applications/spaces/controller/PhabricatorSpacesViewController.php index 911549234f..46e82627ec 100644 --- a/src/applications/spaces/controller/PhabricatorSpacesViewController.php +++ b/src/applications/spaces/controller/PhabricatorSpacesViewController.php @@ -75,6 +75,20 @@ final class PhabricatorSpacesViewController pht('Editable By'), $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); + $description = $space->getDescription(); + if (strlen($description)) { + $description = PhabricatorMarkupEngine::renderOneObject( + id(new PhabricatorMarkupOneOff())->setContent($description), + 'default', + $viewer); + + $list->addSectionHeader( + pht('Description'), + PHUIPropertyListView::ICON_SUMMARY); + + $list->addTextContent($description); + } + return $list; } diff --git a/src/applications/spaces/editor/PhabricatorSpacesNamespaceEditor.php b/src/applications/spaces/editor/PhabricatorSpacesNamespaceEditor.php index 23b01531e9..3b6c7bb6e6 100644 --- a/src/applications/spaces/editor/PhabricatorSpacesNamespaceEditor.php +++ b/src/applications/spaces/editor/PhabricatorSpacesNamespaceEditor.php @@ -15,6 +15,7 @@ final class PhabricatorSpacesNamespaceEditor $types = parent::getTransactionTypes(); $types[] = PhabricatorSpacesNamespaceTransaction::TYPE_NAME; + $types[] = PhabricatorSpacesNamespaceTransaction::TYPE_DESCRIPTION; $types[] = PhabricatorSpacesNamespaceTransaction::TYPE_DEFAULT; $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; @@ -34,6 +35,11 @@ final class PhabricatorSpacesNamespaceEditor return null; } return $name; + case PhabricatorSpacesNamespaceTransaction::TYPE_DESCRIPTION: + if ($this->getIsNewObject()) { + return null; + } + return $object->getDescription(); case PhabricatorSpacesNamespaceTransaction::TYPE_DEFAULT: return $object->getIsDefaultNamespace() ? 1 : null; case PhabricatorTransactions::TYPE_VIEW_POLICY: @@ -51,6 +57,7 @@ final class PhabricatorSpacesNamespaceEditor switch ($xaction->getTransactionType()) { case PhabricatorSpacesNamespaceTransaction::TYPE_NAME: + case PhabricatorSpacesNamespaceTransaction::TYPE_DESCRIPTION: case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: return $xaction->getNewValue(); @@ -71,6 +78,9 @@ final class PhabricatorSpacesNamespaceEditor case PhabricatorSpacesNamespaceTransaction::TYPE_NAME: $object->setNamespaceName($new); return; + case PhabricatorSpacesNamespaceTransaction::TYPE_DESCRIPTION: + $object->setDescription($new); + return; case PhabricatorSpacesNamespaceTransaction::TYPE_DEFAULT: $object->setIsDefaultNamespace($new ? 1 : null); return; @@ -91,6 +101,7 @@ final class PhabricatorSpacesNamespaceEditor switch ($xaction->getTransactionType()) { case PhabricatorSpacesNamespaceTransaction::TYPE_NAME: + case PhabricatorSpacesNamespaceTransaction::TYPE_DESCRIPTION: case PhabricatorSpacesNamespaceTransaction::TYPE_DEFAULT: case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: diff --git a/src/applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php b/src/applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php index 22dfcffac4..710972e8f4 100644 --- a/src/applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php +++ b/src/applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php @@ -32,9 +32,12 @@ final class PhabricatorSpacesNamespacePHIDType foreach ($handles as $phid => $handle) { $namespace = $objects[$phid]; - $monogram = $namespace->getMonogram(); - $handle->setName($namespace->getNamespaceName()); + $monogram = $namespace->getMonogram(); + $name = $namespace->getNamespaceName(); + + $handle->setName($name); + $handle->setFullName(pht('%s %s', $monogram, $name)); $handle->setURI('/'.$monogram); } } diff --git a/src/applications/spaces/storage/PhabricatorSpacesNamespace.php b/src/applications/spaces/storage/PhabricatorSpacesNamespace.php index 8271f536cb..5b1098b1f8 100644 --- a/src/applications/spaces/storage/PhabricatorSpacesNamespace.php +++ b/src/applications/spaces/storage/PhabricatorSpacesNamespace.php @@ -11,6 +11,7 @@ final class PhabricatorSpacesNamespace protected $viewPolicy; protected $editPolicy; protected $isDefaultNamespace; + protected $description; public static function initializeNewNamespace(PhabricatorUser $actor) { $app = id(new PhabricatorApplicationQuery()) @@ -26,7 +27,8 @@ final class PhabricatorSpacesNamespace return id(new PhabricatorSpacesNamespace()) ->setIsDefaultNamespace(null) ->setViewPolicy($view_policy) - ->setEditPolicy($edit_policy); + ->setEditPolicy($edit_policy) + ->setDescription(''); } protected function getConfiguration() { @@ -35,6 +37,7 @@ final class PhabricatorSpacesNamespace self::CONFIG_COLUMN_SCHEMA => array( 'namespaceName' => 'text255', 'isDefaultNamespace' => 'bool?', + 'description' => 'text', ), self::CONFIG_KEY_SCHEMA => array( 'key_default' => array( diff --git a/src/applications/spaces/storage/PhabricatorSpacesNamespaceTransaction.php b/src/applications/spaces/storage/PhabricatorSpacesNamespaceTransaction.php index 672cb9d8ad..ef7d8f210f 100644 --- a/src/applications/spaces/storage/PhabricatorSpacesNamespaceTransaction.php +++ b/src/applications/spaces/storage/PhabricatorSpacesNamespaceTransaction.php @@ -5,6 +5,7 @@ final class PhabricatorSpacesNamespaceTransaction const TYPE_NAME = 'spaces:name'; const TYPE_DEFAULT = 'spaces:default'; + const TYPE_DESCRIPTION = 'spaces:description'; public function getApplicationName() { return 'spaces'; @@ -18,6 +19,38 @@ final class PhabricatorSpacesNamespaceTransaction return null; } + public function shouldHide() { + $old = $this->getOldValue(); + + switch ($this->getTransactionType()) { + case self::TYPE_DESCRIPTION: + return ($old === null); + } + + return parent::shouldHide(); + } + + public function hasChangeDetails() { + switch ($this->getTransactionType()) { + case self::TYPE_DESCRIPTION: + return true; + } + + return parent::hasChangeDetails(); + } + + public function getRemarkupBlocks() { + $blocks = parent::getRemarkupBlocks(); + + switch ($this->getTransactionType()) { + case self::TYPE_DESCRIPTION: + $blocks[] = $this->getNewValue(); + break; + } + + return $blocks; + } + public function getTitle() { $old = $this->getOldValue(); $new = $this->getNewValue(); @@ -37,6 +70,10 @@ final class PhabricatorSpacesNamespaceTransaction $old, $new); } + case self::TYPE_DESCRIPTION: + return pht( + '%s updated the description for this space.', + $this->renderHandleLink($author_phid)); case self::TYPE_DEFAULT: return pht( '%s made this the default space.', diff --git a/src/applications/spaces/storage/PhabricatorSpacesSchemaSpec.php b/src/applications/spaces/storage/PhabricatorSpacesSchemaSpec.php new file mode 100644 index 0000000000..d69772ef7c --- /dev/null +++ b/src/applications/spaces/storage/PhabricatorSpacesSchemaSpec.php @@ -0,0 +1,10 @@ +buildEdgeSchemata(new PhabricatorSpacesNamespace()); + } + +}