1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

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
This commit is contained in:
epriestley 2013-07-14 16:02:04 -07:00
parent fca534d6b6
commit ef1bedef02
6 changed files with 102 additions and 1 deletions

View file

@ -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 = '';

View file

@ -26,6 +26,9 @@ final class PhabricatorSlowvoteCreateController
$poll->setShuffle((int)$request->getBool('shuffle', false)); $poll->setShuffle((int)$request->getBool('shuffle', false));
$poll->setMethod($request->getInt('method')); $poll->setMethod($request->getInt('method'));
$poll->setDescription('');
$poll->setViewPolicy(PhabricatorPolicies::POLICY_USER);
if (!strlen($poll->getQuestion())) { if (!strlen($poll->getQuestion())) {
$e_question = pht('Required'); $e_question = pht('Required');
$errors[] = pht('You must ask a poll question.'); $errors[] = pht('You must ask a poll question.');

View file

@ -14,10 +14,12 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO
const METHOD_APPROVAL = 1; const METHOD_APPROVAL = 1;
protected $question; protected $question;
protected $description;
protected $authorPHID; protected $authorPHID;
protected $responseVisibility; protected $responseVisibility;
protected $shuffle; protected $shuffle;
protected $method; protected $method;
protected $viewPolicy;
public function getConfiguration() { public function getConfiguration() {
return array( return array(
@ -42,7 +44,12 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO
} }
public function getPolicy($capability) { 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) { public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {

View file

@ -0,0 +1,27 @@
<?php
final class PhabricatorSlowvoteTransaction
extends PhabricatorApplicationTransaction {
const TYPE_NAME = 'vote:name';
const TYPE_DESCRIPTION = 'vote:description';
const TYPE_OPTION = 'vote:option';
public function getApplicationName() {
return 'slowvote';
}
public function getApplicationTransactionType() {
return PhabricatorPHIDConstants::PHID_TYPE_POLL;
}
public function getApplicationTransactionCommentObject() {
return new PhabricatorMacroTransactionComment();
}
public function getApplicationObjectTypeName() {
return pht('vote');
}
}

View file

@ -0,0 +1,11 @@
<?php
final class PhabricatorSlowvoteTransactionComment
extends PhabricatorApplicationTransactionComment {
public function getApplicationTransactionObject() {
return new PhabricatorSlowvoteTransaction();
}
}

View file

@ -1442,6 +1442,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'php', 'type' => 'php',
'name' => $this->getPatchPath('20130711.trimrealnames.php'), 'name' => $this->getPatchPath('20130711.trimrealnames.php'),
), ),
'20130714.votexactions.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('20130714.votexactions.sql'),
),
); );
} }
} }