Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15466958
D13818.id33371.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D13818.id33371.diff
View Options
diff --git a/resources/sql/autopatches/20150806.ponder.policy.1.sql b/resources/sql/autopatches/20150806.ponder.policy.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150806.ponder.policy.1.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_ponder.ponder_answer
+ ADD editPolicy VARBINARY(64) NOT NULL;
diff --git a/resources/sql/autopatches/20150806.ponder.policy.2.sql b/resources/sql/autopatches/20150806.ponder.policy.2.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150806.ponder.policy.2.sql
@@ -0,0 +1,2 @@
+UPDATE {$NAMESPACE}_ponder.ponder_answer
+ SET editPolicy = 'admin' WHERE editPolicy = '';
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -3388,6 +3388,7 @@
'PonderAddAnswerView' => 'applications/ponder/view/PonderAddAnswerView.php',
'PonderAnswer' => 'applications/ponder/storage/PonderAnswer.php',
'PonderAnswerCommentController' => 'applications/ponder/controller/PonderAnswerCommentController.php',
+ 'PonderAnswerDefaultEditCapability' => 'applications/ponder/capability/PonderAnswerDefaultEditCapability.php',
'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php',
'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php',
'PonderAnswerHasVotingUserEdgeType' => 'applications/ponder/edge/PonderAnswerHasVotingUserEdgeType.php',
@@ -7576,6 +7577,7 @@
'PhabricatorDestructibleInterface',
),
'PonderAnswerCommentController' => 'PonderController',
+ 'PonderAnswerDefaultEditCapability' => 'PhabricatorPolicyCapability',
'PonderAnswerEditController' => 'PonderController',
'PonderAnswerEditor' => 'PonderEditor',
'PonderAnswerHasVotingUserEdgeType' => 'PhabricatorEdgeType',
diff --git a/src/applications/ponder/application/PhabricatorPonderApplication.php b/src/applications/ponder/application/PhabricatorPonderApplication.php
--- a/src/applications/ponder/application/PhabricatorPonderApplication.php
+++ b/src/applications/ponder/application/PhabricatorPonderApplication.php
@@ -101,6 +101,11 @@
'template' => PonderQuestionPHIDType::TYPECONST,
'capability' => PhabricatorPolicyCapability::CAN_EDIT,
),
+ PonderAnswerDefaultEditCapability::CAPABILITY => array(
+ 'default' => PhabricatorPolicies::POLICY_ADMIN,
+ 'template' => PonderAnswerPHIDType::TYPECONST,
+ 'capability' => PhabricatorPolicyCapability::CAN_EDIT,
+ ),
);
}
diff --git a/src/applications/ponder/capability/PonderAnswerDefaultEditCapability.php b/src/applications/ponder/capability/PonderAnswerDefaultEditCapability.php
new file mode 100644
--- /dev/null
+++ b/src/applications/ponder/capability/PonderAnswerDefaultEditCapability.php
@@ -0,0 +1,12 @@
+<?php
+
+final class PonderAnswerDefaultEditCapability
+ extends PhabricatorPolicyCapability {
+
+ const CAPABILITY = 'ponder.answer.default.edit';
+
+ public function getCapabilityName() {
+ return pht('Default Answer Edit Policy');
+ }
+
+}
diff --git a/src/applications/ponder/controller/PonderAnswerSaveController.php b/src/applications/ponder/controller/PonderAnswerSaveController.php
--- a/src/applications/ponder/controller/PonderAnswerSaveController.php
+++ b/src/applications/ponder/controller/PonderAnswerSaveController.php
@@ -19,9 +19,9 @@
return new Aphront404Response();
}
- $answer = $request->getStr('answer');
+ $content = $request->getStr('answer');
- if (!strlen(trim($answer))) {
+ if (!strlen(trim($content))) {
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setTitle(pht('Empty Answer'))
@@ -38,12 +38,9 @@
'ip' => $request->getRemoteAddr(),
));
- $res = id(new PonderAnswer())
- ->setAuthorPHID($viewer->getPHID())
- ->setQuestionID($question->getID())
- ->setContent($answer)
- ->setVoteCount(0)
- ->setContentSource($content_source);
+ $answer = PonderAnswer::initializeNewAnswer($viewer);
+
+ // Question Editor
$xactions = array();
$xactions[] = id(new PonderQuestionTransaction())
@@ -51,7 +48,7 @@
->setNewValue(
array(
'+' => array(
- array('answer' => $res),
+ array('answer' => $answer),
),
));
@@ -61,6 +58,31 @@
$editor->applyTransactions($question, $xactions);
+ // Answer Editor
+
+ $template = id(new PonderAnswerTransaction());
+ $xactions = array();
+
+ $xactions[] = id(clone $template)
+ ->setTransactionType(PonderAnswerTransaction::TYPE_QUESTION_ID)
+ ->setNewValue($question->getID());
+
+ $xactions[] = id(clone $template)
+ ->setTransactionType(PonderAnswerTransaction::TYPE_CONTENT)
+ ->setNewValue($content);
+
+ $xactions[] = id(clone $template)
+ ->setTransactionType(PonderAnswerTransaction::TYPE_CONTENT_SOURCE)
+ ->setNewValue($content_source);
+
+ $editor = id(new PonderAnswerEditor())
+ ->setActor($viewer)
+ ->setContentSourceFromRequest($request)
+ ->setContinueOnNoEffect(true);
+
+ $editor->applyTransactions($answer, $xactions);
+
+
return id(new AphrontRedirectResponse())->setURI(
id(new PhutilURI('/Q'.$question->getID())));
}
diff --git a/src/applications/ponder/editor/PonderAnswerEditor.php b/src/applications/ponder/editor/PonderAnswerEditor.php
--- a/src/applications/ponder/editor/PonderAnswerEditor.php
+++ b/src/applications/ponder/editor/PonderAnswerEditor.php
@@ -10,7 +10,10 @@
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT;
+
$types[] = PonderAnswerTransaction::TYPE_CONTENT;
+ $types[] = PonderAnswerTransaction::TYPE_CONTENT_SOURCE;
+ $types[] = PonderAnswerTransaction::TYPE_QUESTION_ID;
return $types;
}
@@ -22,6 +25,10 @@
switch ($xaction->getTransactionType()) {
case PonderAnswerTransaction::TYPE_CONTENT:
return $object->getContent();
+ case PonderAnswerTransaction::TYPE_CONTENT_SOURCE:
+ return $object->getContentSource();
+ case PonderAnswerTransaction::TYPE_QUESTION_ID:
+ return $object->getQuestionID();
}
}
@@ -31,6 +38,8 @@
switch ($xaction->getTransactionType()) {
case PonderAnswerTransaction::TYPE_CONTENT:
+ case PonderAnswerTransaction::TYPE_CONTENT_SOURCE:
+ case PonderAnswerTransaction::TYPE_QUESTION_ID:
return $xaction->getNewValue();
}
}
@@ -43,6 +52,12 @@
case PonderAnswerTransaction::TYPE_CONTENT:
$object->setContent($xaction->getNewValue());
break;
+ case PonderAnswerTransaction::TYPE_CONTENT_SOURCE:
+ $object->setContentSource($xaction->getNewValue());
+ break;
+ case PonderAnswerTransaction::TYPE_QUESTION_ID:
+ $object->setQuestionID($xaction->getNewValue());
+ break;
}
}
diff --git a/src/applications/ponder/storage/PonderAnswer.php b/src/applications/ponder/storage/PonderAnswer.php
--- a/src/applications/ponder/storage/PonderAnswer.php
+++ b/src/applications/ponder/storage/PonderAnswer.php
@@ -19,6 +19,7 @@
protected $content;
protected $contentSource;
protected $mailKey;
+ protected $editPolicy;
protected $voteCount;
private $vote;
@@ -27,6 +28,29 @@
private $userVotes = array();
+ public static function initializeNewAnswer(PhabricatorUser $actor) {
+ $app = id(new PhabricatorApplicationQuery())
+ ->setViewer($actor)
+ ->withClasses(array('PhabricatorPonderApplication'))
+ ->executeOne();
+
+ $edit_policy = $app->getPolicy(
+ PonderAnswerDefaultEditCapability::CAPABILITY);
+
+ $content_source = PhabricatorContentSource::newForSource(
+ PhabricatorContentSource::SOURCE_UNKNOWN,
+ array());
+
+ return id(new PonderAnswer())
+ ->setQuestionID(0)
+ ->setContent('')
+ ->setContentSource($content_source)
+ ->setAuthorPHID($actor->getPHID())
+ ->setVoteCount(0)
+ ->setEditPolicy($edit_policy);
+
+ }
+
public function attachQuestion(PonderQuestion $question = null) {
$this->question = $question;
return $this;
@@ -198,8 +222,7 @@
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getQuestion()->getPolicy($capability);
case PhabricatorPolicyCapability::CAN_EDIT:
- return PhabricatorPolicies::POLICY_NOONE;
- }
+ return $this->getEditPolicy(); }
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
diff --git a/src/applications/ponder/storage/PonderAnswerTransaction.php b/src/applications/ponder/storage/PonderAnswerTransaction.php
--- a/src/applications/ponder/storage/PonderAnswerTransaction.php
+++ b/src/applications/ponder/storage/PonderAnswerTransaction.php
@@ -4,6 +4,8 @@
extends PhabricatorApplicationTransaction {
const TYPE_CONTENT = 'ponder.answer:content';
+ const TYPE_CONTENT_SOURCE = 'ponder.answer:content-source';
+ const TYPE_QUESTION_ID = 'ponder.answer:question-id';
public function getApplicationName() {
return 'ponder';
@@ -45,16 +47,36 @@
return $blocks;
}
+ public function shouldHide() {
+ switch ($this->getTransactionType()) {
+ case self::TYPE_QUESTION_ID:
+ case self::TYPE_CONTENT_SOURCE:
+ return true;
+ }
+ return parent::shouldHide();
+ }
+
public function getTitle() {
$author_phid = $this->getAuthorPHID();
$object_phid = $this->getObjectPHID();
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
switch ($this->getTransactionType()) {
case self::TYPE_CONTENT:
- return pht(
- '%s edited %s.',
- $this->renderHandleLink($author_phid),
- $this->renderHandleLink($object_phid));
+ if ($old === '') {
+ return pht(
+ '%s added %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ } else {
+ return pht(
+ '%s edited %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ }
+ break;
}
return parent::getTitle();
@@ -64,12 +86,23 @@
$author_phid = $this->getAuthorPHID();
$object_phid = $this->getObjectPHID();
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
switch ($this->getTransactionType()) {
case self::TYPE_CONTENT:
- return pht(
- '%s updated %s.',
- $this->renderHandleLink($author_phid),
- $this->renderHandleLink($object_phid));
+ if ($old === '') {
+ return pht(
+ '%s added %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ } else {
+ return pht(
+ '%s updated %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ }
+ break;
}
return parent::getTitleForFeed();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 4, 11:11 AM (1 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7728848
Default Alt Text
D13818.id33371.diff (10 KB)
Attached To
Mode
D13818: Add a default moderation policy to Ponder
Attached
Detach File
Event Timeline
Log In to Comment