Page MenuHomePhabricator

D13791.id33309.diff
No OneTemporary

D13791.id33309.diff

diff --git a/resources/sql/autopatches/20150804.ponder.question.1.sql b/resources/sql/autopatches/20150804.ponder.question.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150804.ponder.question.1.sql
@@ -0,0 +1,5 @@
+ALTER TABLE {$NAMESPACE}_ponder.ponder_question
+ ADD editPolicy VARBINARY(64) NOT NULL;
+
+ALTER TABLE {$NAMESPACE}_ponder.ponder_question
+ ADD viewPolicy VARBINARY(64) NOT NULL;
diff --git a/resources/sql/autopatches/20150804.ponder.question.2.sql b/resources/sql/autopatches/20150804.ponder.question.2.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150804.ponder.question.2.sql
@@ -0,0 +1,2 @@
+UPDATE {$NAMESPACE}_ponder.ponder_question
+ SET editPolicy = authorPHID 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
@@ -3398,6 +3398,8 @@
'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',
@@ -7588,6 +7590,8 @@
'PhabricatorDestructibleInterface',
),
'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
@@ -91,6 +91,19 @@
);
}
+ protected function getCustomCapabilities() {
+ return array(
+ PonderQuestionDefaultViewCapability::CAPABILITY => array(
+ 'template' => PonderQuestionPHIDType::TYPECONST,
+ 'capability' => PhabricatorPolicyCapability::CAN_VIEW,
+ ),
+ PonderQuestionDefaultEditCapability::CAPABILITY => array(
+ 'template' => PonderQuestionPHIDType::TYPECONST,
+ 'capability' => PhabricatorPolicyCapability::CAN_EDIT,
+ ),
+ );
+ }
+
public function getApplicationSearchDocumentTypes() {
return array(
PonderQuestionPHIDType::TYPECONST,
diff --git a/src/applications/ponder/capability/PonderQuestionDefaultEditCapability.php b/src/applications/ponder/capability/PonderQuestionDefaultEditCapability.php
new file mode 100644
--- /dev/null
+++ b/src/applications/ponder/capability/PonderQuestionDefaultEditCapability.php
@@ -0,0 +1,12 @@
+<?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/capability/PonderQuestionDefaultViewCapability.php b/src/applications/ponder/capability/PonderQuestionDefaultViewCapability.php
new file mode 100644
--- /dev/null
+++ b/src/applications/ponder/capability/PonderQuestionDefaultViewCapability.php
@@ -0,0 +1,16 @@
+<?php
+
+final class PonderQuestionDefaultViewCapability
+ extends PhabricatorPolicyCapability {
+
+ const CAPABILITY = 'ponder.question.default.view';
+
+ public function getCapabilityName() {
+ return pht('Default Question View Policy');
+ }
+
+ public function shouldAllowPublicPolicySetting() {
+ return true;
+ }
+
+}
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
@@ -3,12 +3,12 @@
final class PonderQuestionEditController extends PonderController {
public function handleRequest(AphrontRequest $request) {
- $user = $request->getViewer();
+ $viewer = $request->getViewer();
$id = $request->getURIData('id');
if ($id) {
$question = id(new PonderQuestionQuery())
- ->setViewer($user)
+ ->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
@@ -24,17 +24,14 @@
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
$v_projects = array_reverse($v_projects);
} else {
- $question = id(new PonderQuestion())
- ->setStatus(PonderQuestionStatus::STATUS_OPEN)
- ->setAuthorPHID($user->getPHID())
- ->setVoteCount(0)
- ->setAnswerCount(0)
- ->setHeat(0.0);
+ $question = PonderQuestion::initializeNewQuestion($viewer);
$v_projects = array();
}
$v_title = $question->getTitle();
$v_content = $question->getContent();
+ $v_view = $question->getViewPolicy();
+ $v_edit = $question->getEditPolicy();
$errors = array();
$e_title = true;
@@ -42,6 +39,8 @@
$v_title = $request->getStr('title');
$v_content = $request->getStr('content');
$v_projects = $request->getArr('projects');
+ $v_view = $request->getStr('viewPolicy');
+ $v_edit = $request->getStr('editPolicy');
$len = phutil_utf8_strlen($v_title);
if ($len < 1) {
@@ -64,6 +63,14 @@
->setTransactionType(PonderQuestionTransaction::TYPE_CONTENT)
->setNewValue($v_content);
+ $xactions[] = id(clone $template)
+ ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
+ ->setNewValue($v_view);
+
+ $xactions[] = id(clone $template)
+ ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
+ ->setNewValue($v_edit);
+
$proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
$xactions[] = id(new PonderQuestionTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
@@ -71,7 +78,7 @@
->setNewValue(array('=' => array_fuse($v_projects)));
$editor = id(new PonderQuestionEditor())
- ->setActor($user)
+ ->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true);
@@ -82,8 +89,13 @@
}
}
+ $policies = id(new PhabricatorPolicyQuery())
+ ->setViewer($viewer)
+ ->setObject($question)
+ ->execute();
+
$form = id(new AphrontFormView())
- ->setUser($user)
+ ->setUser($viewer)
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Question'))
@@ -92,12 +104,26 @@
->setError($e_title))
->appendChild(
id(new PhabricatorRemarkupControl())
- ->setUser($user)
+ ->setUser($viewer)
->setName('content')
->setID('content')
->setValue($v_content)
->setLabel(pht('Description'))
- ->setUser($user));
+ ->setUser($viewer))
+ ->appendControl(
+ id(new AphrontFormPolicyControl())
+ ->setName('viewPolicy')
+ ->setPolicyObject($question)
+ ->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));
$form->appendControl(
id(new AphrontFormTokenizerControl())
diff --git a/src/applications/ponder/editor/PonderQuestionEditor.php b/src/applications/ponder/editor/PonderQuestionEditor.php
--- a/src/applications/ponder/editor/PonderQuestionEditor.php
+++ b/src/applications/ponder/editor/PonderQuestionEditor.php
@@ -66,6 +66,9 @@
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_COMMENT;
+ $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
+ $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
+
$types[] = PonderQuestionTransaction::TYPE_TITLE;
$types[] = PonderQuestionTransaction::TYPE_CONTENT;
$types[] = PonderQuestionTransaction::TYPE_ANSWERS;
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
@@ -21,6 +21,8 @@
protected $status;
protected $content;
protected $contentSource;
+ protected $viewPolicy;
+ protected $editPolicy;
protected $voteCount;
protected $answerCount;
@@ -31,6 +33,27 @@
private $vote;
private $comments;
+ public static function initializeNewQuestion(PhabricatorUser $actor) {
+ $app = id(new PhabricatorApplicationQuery())
+ ->setViewer($actor)
+ ->withClasses(array('PhabricatorPonderApplication'))
+ ->executeOne();
+
+ $view_policy = $app->getPolicy(
+ PonderQuestionDefaultViewCapability::CAPABILITY);
+ $edit_policy = $app->getPolicy(
+ PonderQuestionDefaultEditCapability::CAPABILITY);
+
+ return id(new PonderQuestion())
+ ->setAuthorPHID($actor->getPHID())
+ ->setViewPolicy($view_policy)
+ ->setEditPolicy($edit_policy)
+ ->setStatus(PonderQuestionStatus::STATUS_OPEN)
+ ->setVoteCount(0)
+ ->setAnswerCount(0)
+ ->setHeat(0.0);
+ }
+
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
@@ -234,15 +257,12 @@
}
public function getPolicy($capability) {
- $policy = PhabricatorPolicies::POLICY_NOONE;
-
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
- $policy = PhabricatorPolicies::POLICY_USER;
- break;
+ return $this->getViewPolicy();
+ case PhabricatorPolicyCapability::CAN_EDIT:
+ return $this->getEditPolicy();
}
-
- return $policy;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 4, 6:44 PM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7386293
Default Alt Text
D13791.id33309.diff (10 KB)

Event Timeline