Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15489150
D13818.id33377.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
17 KB
Referenced Files
None
Subscribers
None
D13818.id33377.diff
View Options
diff --git a/resources/sql/autopatches/.DS_Store b/resources/sql/autopatches/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6
GIT binary patch
literal 6148
zc%1FnJqp4w7{>AEjTr(i86C5D0B;aVdjc=u;1%3+bS>|L1Zu&pMV}v(f1uw>+Z2Ee
zkNXA401~`7<D<l7A#`KoF+@Z}WZ%q_j@w>_i0sh(d?;*Xo7cELu(8`GvxTi}^BT7c
zY-AIg*}_(~dHK*XPCkrhHqKBivxTkS->=9&Ie7B?{-3Zq{}+)TW^ufZ1KtyY<p!_i
a){Pt1KLUdPEIf7l7Phj@s}BK@tvmrps|slV
literal 0
Hc$@<O00001
diff --git a/resources/sql/autopatches/20150806.ponder.answer.1.sql b/resources/sql/autopatches/20150806.ponder.answer.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150806.ponder.answer.1.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_ponder.ponder_answer
+ DROP COLUMN contentSource;
diff --git a/resources/sql/autopatches/20150806.ponder.editpolicy.2.sql b/resources/sql/autopatches/20150806.ponder.editpolicy.2.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150806.ponder.editpolicy.2.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_ponder.ponder_question
+ DROP COLUMN 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
@@ -3401,11 +3401,11 @@
'PonderConstants' => 'applications/ponder/constants/PonderConstants.php',
'PonderController' => 'applications/ponder/controller/PonderController.php',
'PonderDAO' => 'applications/ponder/storage/PonderDAO.php',
+ 'PonderDefaultModerateCapability' => 'applications/ponder/capability/PonderDefaultModerateCapability.php',
+ 'PonderDefaultViewCapability' => 'applications/ponder/capability/PonderDefaultViewCapability.php',
'PonderEditor' => 'applications/ponder/editor/PonderEditor.php',
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php',
- 'PonderQuestionDefaultEditCapability' => 'applications/ponder/capability/PonderQuestionDefaultEditCapability.php',
- 'PonderQuestionDefaultViewCapability' => 'applications/ponder/capability/PonderQuestionDefaultViewCapability.php',
'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php',
'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php',
'PonderQuestionHasVotingUserEdgeType' => 'applications/ponder/edge/PonderQuestionHasVotingUserEdgeType.php',
@@ -7589,6 +7589,8 @@
'PonderConstants' => 'Phobject',
'PonderController' => 'PhabricatorController',
'PonderDAO' => 'PhabricatorLiskDAO',
+ 'PonderDefaultModerateCapability' => 'PhabricatorPolicyCapability',
+ 'PonderDefaultViewCapability' => 'PhabricatorPolicyCapability',
'PonderEditor' => 'PhabricatorApplicationTransactionEditor',
'PonderQuestion' => array(
'PonderDAO',
@@ -7604,8 +7606,6 @@
'PhabricatorSpacesInterface',
),
'PonderQuestionCommentController' => 'PonderController',
- 'PonderQuestionDefaultEditCapability' => 'PhabricatorPolicyCapability',
- 'PonderQuestionDefaultViewCapability' => 'PhabricatorPolicyCapability',
'PonderQuestionEditController' => 'PonderController',
'PonderQuestionEditor' => 'PonderEditor',
'PonderQuestionHasVotingUserEdgeType' => '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
@@ -93,11 +93,12 @@
protected function getCustomCapabilities() {
return array(
- PonderQuestionDefaultViewCapability::CAPABILITY => array(
+ PonderDefaultViewCapability::CAPABILITY => array(
'template' => PonderQuestionPHIDType::TYPECONST,
'capability' => PhabricatorPolicyCapability::CAN_VIEW,
),
- PonderQuestionDefaultEditCapability::CAPABILITY => array(
+ PonderDefaultModerateCapability::CAPABILITY => array(
+ 'default' => PhabricatorPolicies::POLICY_ADMIN,
'template' => PonderQuestionPHIDType::TYPECONST,
'capability' => PhabricatorPolicyCapability::CAN_EDIT,
),
diff --git a/src/applications/ponder/capability/.DS_Store b/src/applications/ponder/capability/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6
GIT binary patch
literal 6148
zc%1FnJqp4w7{>AEjTr(i86C5D0B;aVdjc=u;1%3+bS>|L1Zu&pMV}v(f1uw>+Z2Ee
zkNXA401~`7<D<l7A#`KoF+@Z}WZ%q_j@w>_i0sh(d?;*Xo7cELu(8`GvxTi}^BT7c
zY-AIg*}_(~dHK*XPCkrhHqKBivxTkS->=9&Ie7B?{-3Zq{}+)TW^ufZ1KtyY<p!_i
a){Pt1KLUdPEIf7l7Phj@s}BK@tvmrps|slV
literal 0
Hc$@<O00001
diff --git a/src/applications/ponder/capability/PonderDefaultModerateCapability.php b/src/applications/ponder/capability/PonderDefaultModerateCapability.php
new file mode 100644
--- /dev/null
+++ b/src/applications/ponder/capability/PonderDefaultModerateCapability.php
@@ -0,0 +1,12 @@
+<?php
+
+final class PonderDefaultModerateCapability
+ extends PhabricatorPolicyCapability {
+
+ const CAPABILITY = 'ponder.default.moderate';
+
+ public function getCapabilityName() {
+ return pht('Default Moderate Policy');
+ }
+
+}
diff --git a/src/applications/ponder/capability/PonderQuestionDefaultViewCapability.php b/src/applications/ponder/capability/PonderDefaultViewCapability.php
rename from src/applications/ponder/capability/PonderQuestionDefaultViewCapability.php
rename to src/applications/ponder/capability/PonderDefaultViewCapability.php
--- a/src/applications/ponder/capability/PonderQuestionDefaultViewCapability.php
+++ b/src/applications/ponder/capability/PonderDefaultViewCapability.php
@@ -1,12 +1,12 @@
<?php
-final class PonderQuestionDefaultViewCapability
+final class PonderDefaultViewCapability
extends PhabricatorPolicyCapability {
- const CAPABILITY = 'ponder.question.default.view';
+ const CAPABILITY = 'ponder.default.view';
public function getCapabilityName() {
- return pht('Default Question View Policy');
+ return pht('Default View Policy');
}
public function shouldAllowPublicPolicySetting() {
diff --git a/src/applications/ponder/capability/PonderQuestionDefaultEditCapability.php b/src/applications/ponder/capability/PonderQuestionDefaultEditCapability.php
deleted file mode 100644
--- a/src/applications/ponder/capability/PonderQuestionDefaultEditCapability.php
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-
-final class PonderQuestionDefaultEditCapability
- extends PhabricatorPolicyCapability {
-
- const CAPABILITY = 'ponder.question.default.edit';
-
- public function getCapabilityName() {
- return pht('Default Question 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'))
@@ -32,18 +32,9 @@
return id(new AphrontDialogResponse())->setDialog($dialog);
}
- $content_source = PhabricatorContentSource::newForSource(
- PhabricatorContentSource::SOURCE_WEB,
- array(
- 'ip' => $request->getRemoteAddr(),
- ));
+ $answer = PonderAnswer::initializeNewAnswer($viewer);
- $res = id(new PonderAnswer())
- ->setAuthorPHID($viewer->getPHID())
- ->setQuestionID($question->getID())
- ->setContent($answer)
- ->setVoteCount(0)
- ->setContentSource($content_source);
+ // Question Editor
$xactions = array();
$xactions[] = id(new PonderQuestionTransaction())
@@ -51,7 +42,7 @@
->setNewValue(
array(
'+' => array(
- array('answer' => $res),
+ array('answer' => $answer),
),
));
@@ -61,6 +52,27 @@
$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);
+
+ $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/controller/PonderQuestionEditController.php b/src/applications/ponder/controller/PonderQuestionEditController.php
--- a/src/applications/ponder/controller/PonderQuestionEditController.php
+++ b/src/applications/ponder/controller/PonderQuestionEditController.php
@@ -31,7 +31,6 @@
$v_title = $question->getTitle();
$v_content = $question->getContent();
$v_view = $question->getViewPolicy();
- $v_edit = $question->getEditPolicy();
$v_space = $question->getSpacePHID();
$errors = array();
@@ -41,7 +40,6 @@
$v_content = $request->getStr('content');
$v_projects = $request->getArr('projects');
$v_view = $request->getStr('viewPolicy');
- $v_edit = $request->getStr('editPolicy');
$v_space = $request->getStr('spacePHID');
$len = phutil_utf8_strlen($v_title);
@@ -70,10 +68,6 @@
->setNewValue($v_view);
$xactions[] = id(clone $template)
- ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
- ->setNewValue($v_edit);
-
- $xactions[] = id(clone $template)
->setTransactionType(PhabricatorTransactions::TYPE_SPACE)
->setNewValue($v_space);
@@ -123,14 +117,7 @@
->setSpacePHID($v_space)
->setPolicies($policies)
->setValue($v_view)
- ->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
- ->appendControl(
- id(new AphrontFormPolicyControl())
- ->setName('editPolicy')
- ->setPolicyObject($question)
- ->setPolicies($policies)
- ->setValue($v_edit)
- ->setCapability(PhabricatorPolicyCapability::CAN_EDIT));
+ ->setCapability(PhabricatorPolicyCapability::CAN_VIEW));
$form->appendControl(
id(new AphrontFormTokenizerControl())
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,9 @@
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT;
+
$types[] = PonderAnswerTransaction::TYPE_CONTENT;
+ $types[] = PonderAnswerTransaction::TYPE_QUESTION_ID;
return $types;
}
@@ -22,6 +24,8 @@
switch ($xaction->getTransactionType()) {
case PonderAnswerTransaction::TYPE_CONTENT:
return $object->getContent();
+ case PonderAnswerTransaction::TYPE_QUESTION_ID:
+ return $object->getQuestionID();
}
}
@@ -31,6 +35,7 @@
switch ($xaction->getTransactionType()) {
case PonderAnswerTransaction::TYPE_CONTENT:
+ case PonderAnswerTransaction::TYPE_QUESTION_ID:
return $xaction->getNewValue();
}
}
@@ -43,6 +48,9 @@
case PonderAnswerTransaction::TYPE_CONTENT:
$object->setContent($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
@@ -17,7 +17,6 @@
protected $questionID;
protected $content;
- protected $contentSource;
protected $mailKey;
protected $voteCount;
@@ -27,6 +26,20 @@
private $userVotes = array();
+ public static function initializeNewAnswer(PhabricatorUser $actor) {
+ $app = id(new PhabricatorApplicationQuery())
+ ->setViewer($actor)
+ ->withClasses(array('PhabricatorPonderApplication'))
+ ->executeOne();
+
+ return id(new PonderAnswer())
+ ->setQuestionID(0)
+ ->setContent('')
+ ->setAuthorPHID($actor->getPHID())
+ ->setVoteCount(0);
+
+ }
+
public function attachQuestion(PonderQuestion $question = null) {
$this->question = $question;
return $this;
@@ -73,10 +86,6 @@
'voteCount' => 'sint32',
'content' => 'text',
'mailKey' => 'bytes20',
-
- // T6203/NULLABILITY
- // This should always exist.
- 'contentSource' => 'text?',
),
self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null,
@@ -102,15 +111,6 @@
return PhabricatorPHID::generateNewPHID(PonderAnswerPHIDType::TYPECONST);
}
- public function setContentSource(PhabricatorContentSource $content_source) {
- $this->contentSource = $content_source->serialize();
- return $this;
- }
-
- public function getContentSource() {
- return PhabricatorContentSource::newFromSerialized($this->contentSource);
- }
-
public function getMarkupField() {
return self::MARKUP_FIELD_CONTENT;
}
@@ -198,7 +198,9 @@
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getQuestion()->getPolicy($capability);
case PhabricatorPolicyCapability::CAN_EDIT:
- return PhabricatorPolicies::POLICY_NOONE;
+ $app = PhabricatorApplication::getByClass(
+ 'PhabricatorPonderApplication');
+ return $app->getPolicy(PonderDefaultModerateCapability::CAPABILITY);
}
}
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,7 @@
extends PhabricatorApplicationTransaction {
const TYPE_CONTENT = 'ponder.answer:content';
+ const TYPE_QUESTION_ID = 'ponder.answer:question-id';
public function getApplicationName() {
return 'ponder';
@@ -45,16 +46,35 @@
return $blocks;
}
+ public function shouldHide() {
+ switch ($this->getTransactionType()) {
+ case self::TYPE_QUESTION_ID:
+ 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 +84,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();
diff --git a/src/applications/ponder/storage/PonderQuestion.php b/src/applications/ponder/storage/PonderQuestion.php
--- a/src/applications/ponder/storage/PonderQuestion.php
+++ b/src/applications/ponder/storage/PonderQuestion.php
@@ -23,7 +23,6 @@
protected $content;
protected $contentSource;
protected $viewPolicy;
- protected $editPolicy;
protected $spacePHID;
protected $voteCount;
@@ -44,14 +43,11 @@
->executeOne();
$view_policy = $app->getPolicy(
- PonderQuestionDefaultViewCapability::CAPABILITY);
- $edit_policy = $app->getPolicy(
- PonderQuestionDefaultEditCapability::CAPABILITY);
+ PonderDefaultViewCapability::CAPABILITY);
return id(new PonderQuestion())
->setAuthorPHID($actor->getPHID())
->setViewPolicy($view_policy)
- ->setEditPolicy($edit_policy)
->setStatus(PonderQuestionStatus::STATUS_OPEN)
->setVoteCount(0)
->setAnswerCount(0)
@@ -275,7 +271,9 @@
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
- return $this->getEditPolicy();
+ $app = PhabricatorApplication::getByClass(
+ 'PhabricatorPonderApplication');
+ return $app->getPolicy(PonderDefaultModerateCapability::CAPABILITY);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 12, 6:25 AM (1 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7706327
Default Alt Text
D13818.id33377.diff (17 KB)
Attached To
Mode
D13818: Add a default moderation policy to Ponder
Attached
Detach File
Event Timeline
Log In to Comment