From ef1bedef028f996441039d4cfec9339bf4bdaf33 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 14 Jul 2013 16:02:04 -0700 Subject: [PATCH] Add ApplicaionTransactions and a mutable view policy to Slowvote Summary: Schema changes to modernize this app. Test Plan: Ran schema changes, created a new slowvote. No real effects yet. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D6453 --- .../sql/patches/20130714.votexactions.sql | 49 +++++++++++++++++++ .../PhabricatorSlowvoteCreateController.php | 3 ++ .../storage/PhabricatorSlowvotePoll.php | 9 +++- .../PhabricatorSlowvoteTransaction.php | 27 ++++++++++ .../PhabricatorSlowvoteTransactionComment.php | 11 +++++ .../patch/PhabricatorBuiltinPatchList.php | 4 ++ 6 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 resources/sql/patches/20130714.votexactions.sql create mode 100644 src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php create mode 100644 src/applications/slowvote/storage/PhabricatorSlowvoteTransactionComment.php diff --git a/resources/sql/patches/20130714.votexactions.sql b/resources/sql/patches/20130714.votexactions.sql new file mode 100644 index 0000000000..41f6a75ceb --- /dev/null +++ b/resources/sql/patches/20130714.votexactions.sql @@ -0,0 +1,49 @@ +CREATE TABLE {$NAMESPACE}_slowvote.slowvote_transaction ( + id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + phid VARCHAR(64) NOT NULL COLLATE utf8_bin, + authorPHID VARCHAR(64) NOT NULL COLLATE utf8_bin, + objectPHID VARCHAR(64) NOT NULL COLLATE utf8_bin, + viewPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin, + editPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin, + commentPHID VARCHAR(64) COLLATE utf8_bin, + commentVersion INT UNSIGNED NOT NULL, + transactionType VARCHAR(32) NOT NULL COLLATE utf8_bin, + oldValue LONGTEXT NOT NULL COLLATE utf8_bin, + newValue LONGTEXT NOT NULL COLLATE utf8_bin, + contentSource LONGTEXT NOT NULL COLLATE utf8_bin, + metadata LONGTEXT NOT NULL COLLATE utf8_bin, + dateCreated INT UNSIGNED NOT NULL, + dateModified INT UNSIGNED NOT NULL, + + UNIQUE KEY `key_phid` (phid), + KEY `key_object` (objectPHID) + +) ENGINE=InnoDB, COLLATE utf8_general_ci; + +CREATE TABLE {$NAMESPACE}_slowvote.slowvote_transaction_comment ( + id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + phid VARCHAR(64) NOT NULL COLLATE utf8_bin, + transactionPHID VARCHAR(64) COLLATE utf8_bin, + authorPHID VARCHAR(64) NOT NULL COLLATE utf8_bin, + viewPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin, + editPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin, + commentVersion INT UNSIGNED NOT NULL, + content LONGTEXT NOT NULL COLLATE utf8_bin, + contentSource LONGTEXT NOT NULL COLLATE utf8_bin, + isDeleted BOOL NOT NULL, + dateCreated INT UNSIGNED NOT NULL, + dateModified INT UNSIGNED NOT NULL, + + UNIQUE KEY `key_phid` (phid), + UNIQUE KEY `key_version` (transactionPHID, commentVersion) + +) ENGINE=InnoDB, COLLATE utf8_general_ci; + +ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll + ADD description LONGTEXT NOT NULL COLLATE utf8_general_ci; + +ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll + ADD viewPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin; + +UPDATE {$NAMESPACE}_slowvote.slowvote_poll + SET viewPolicy = 'users' WHERE viewPolicy = ''; diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteCreateController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteCreateController.php index 9b2ea232a4..668042c2be 100644 --- a/src/applications/slowvote/controller/PhabricatorSlowvoteCreateController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvoteCreateController.php @@ -26,6 +26,9 @@ final class PhabricatorSlowvoteCreateController $poll->setShuffle((int)$request->getBool('shuffle', false)); $poll->setMethod($request->getInt('method')); + $poll->setDescription(''); + $poll->setViewPolicy(PhabricatorPolicies::POLICY_USER); + if (!strlen($poll->getQuestion())) { $e_question = pht('Required'); $errors[] = pht('You must ask a poll question.'); diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php index 85f3059ec5..6a76116c2f 100644 --- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php +++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php @@ -14,10 +14,12 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO const METHOD_APPROVAL = 1; protected $question; + protected $description; protected $authorPHID; protected $responseVisibility; protected $shuffle; protected $method; + protected $viewPolicy; public function getConfiguration() { return array( @@ -42,7 +44,12 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO } public function getPolicy($capability) { - return PhabricatorPolicies::POLICY_USER; + switch ($capability) { + case PhabricatorPolicyCapability::CAN_VIEW: + return $this->viewPolicy; + case PhabricatorPolicyCapability::CAN_EDIT: + return PhabricatorPolicies::POLICY_NOONE; + } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { diff --git a/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php b/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php new file mode 100644 index 0000000000..4f6131d9f6 --- /dev/null +++ b/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php @@ -0,0 +1,27 @@ + 'php', 'name' => $this->getPatchPath('20130711.trimrealnames.php'), ), + '20130714.votexactions.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('20130714.votexactions.sql'), + ), ); } }