2012-08-10 10:44:04 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PonderAnswer extends PonderDAO
|
2013-07-26 13:19:49 -07:00
|
|
|
implements
|
Transactions - deploy buildTransactionTimeline to remaining applications
Summary:
Ref T4712. Specifically...
- Differential
- needed getApplicationTransactionViewObject() implemented
- Audit
- needed getApplicationTransactionViewObject() implemented
- Repository
- one object needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true)
- Ponder
- BONUS BUG FIX - leaving a comment on an answer had a bad redirect URI
- both PonderQuestion and PonderAnswer needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) on both "history" controllers
- left a "TODO" on buildAnswers on the question view controller, which is non-standard and should be re-written eventually
- Phortune
- BONUS BUG FIX - fix new user "createNewAccount" code to not fatal
- PhortuneAccount, PhortuneMerchant, and PhortuneCart needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) on Account view, merchant view, and cart view controller
- Fund
- Legalpad
- Nuance
- NuanceSource needed PhabricatorApplicationTransactionInterface implemented
- Releeph (this product is kind of a mess...)
- HACKQUEST - had to manually create an arcanist project to even be able to make a "product" and get started...!
- BONUS BUG FIX - make sure to "setName" on product edit
- ReleephProject (should be ReleepProduct...?), ReleephBranch, and ReleepRequest needed PhabricatorApplicationTransactionInterface implemented
- Harbormaster
- HarbormasterBuildable, HarbormasterBuild, HarbormasterBuildPlan, and HarbormasterBuildStep all needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) all over the place
Test Plan: foreach application, viewed the timeline(s) and made sure they still rendered
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T4712
Differential Revision: https://secure.phabricator.com/D10925
2014-12-03 15:35:47 -08:00
|
|
|
PhabricatorApplicationTransactionInterface,
|
2013-07-26 13:19:49 -07:00
|
|
|
PhabricatorMarkupInterface,
|
2013-07-28 17:23:04 -07:00
|
|
|
PhabricatorPolicyInterface,
|
2013-10-25 12:52:00 -07:00
|
|
|
PhabricatorFlaggableInterface,
|
2013-07-28 17:23:04 -07:00
|
|
|
PhabricatorSubscribableInterface,
|
2014-08-25 08:41:03 -07:00
|
|
|
PhabricatorDestructibleInterface {
|
2012-08-10 10:44:04 -07:00
|
|
|
|
|
|
|
const MARKUP_FIELD_CONTENT = 'markup:content';
|
|
|
|
|
|
|
|
protected $authorPHID;
|
|
|
|
protected $questionID;
|
|
|
|
|
|
|
|
protected $content;
|
2015-08-04 10:49:15 -07:00
|
|
|
protected $mailKey;
|
2015-08-14 09:25:02 -07:00
|
|
|
protected $status;
|
|
|
|
|
2013-07-26 13:13:38 -07:00
|
|
|
private $question = self::ATTACHABLE;
|
adding comments to ponder
Summary: This is pretty spartan, but it does the job.
Test Plan:
Patch, update storage, add some comment
to your favorite question or answer.
Reviewers: nh, vrana, epriestley
Reviewed By: epriestley
CC: aran, Korvin, starruler, syrneus, me.here, victorzarate7
Maniphest Tasks: T1645
Differential Revision: https://secure.phabricator.com/D3471
2012-09-11 12:13:20 -07:00
|
|
|
private $comments;
|
2012-08-10 10:44:04 -07:00
|
|
|
|
2015-10-13 09:09:07 -07:00
|
|
|
public static function initializeNewAnswer(
|
|
|
|
PhabricatorUser $actor,
|
|
|
|
PonderQuestion $question) {
|
2015-08-08 12:20:01 -07:00
|
|
|
$app = id(new PhabricatorApplicationQuery())
|
|
|
|
->setViewer($actor)
|
|
|
|
->withClasses(array('PhabricatorPonderApplication'))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
return id(new PonderAnswer())
|
2015-10-13 09:09:07 -07:00
|
|
|
->setQuestionID($question->getID())
|
2015-08-08 12:20:01 -07:00
|
|
|
->setContent('')
|
2015-10-13 09:09:07 -07:00
|
|
|
->attachQuestion($question)
|
2015-08-08 12:20:01 -07:00
|
|
|
->setAuthorPHID($actor->getPHID())
|
2016-02-23 07:23:58 -08:00
|
|
|
->setVoteCount('0')
|
2015-08-14 09:25:02 -07:00
|
|
|
->setStatus(PonderAnswerStatus::ANSWER_STATUS_VISIBLE);
|
2015-08-08 12:20:01 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-26 13:13:38 -07:00
|
|
|
public function attachQuestion(PonderQuestion $question = null) {
|
2012-08-10 10:44:04 -07:00
|
|
|
$this->question = $question;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getQuestion() {
|
2013-07-26 13:13:38 -07:00
|
|
|
return $this->assertAttached($this->question);
|
2012-08-10 10:44:04 -07:00
|
|
|
}
|
|
|
|
|
2013-09-18 15:15:25 -07:00
|
|
|
public function getURI() {
|
|
|
|
return '/Q'.$this->getQuestionID().'#A'.$this->getID();
|
|
|
|
}
|
|
|
|
|
adding comments to ponder
Summary: This is pretty spartan, but it does the job.
Test Plan:
Patch, update storage, add some comment
to your favorite question or answer.
Reviewers: nh, vrana, epriestley
Reviewed By: epriestley
CC: aran, Korvin, starruler, syrneus, me.here, victorzarate7
Maniphest Tasks: T1645
Differential Revision: https://secure.phabricator.com/D3471
2012-09-11 12:13:20 -07:00
|
|
|
public function setComments($comments) {
|
|
|
|
$this->comments = $comments;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getComments() {
|
|
|
|
return $this->comments;
|
|
|
|
}
|
|
|
|
|
2015-01-14 06:47:05 +11:00
|
|
|
protected function getConfiguration() {
|
2012-08-10 10:44:04 -07:00
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
2014-10-01 07:37:14 -07:00
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
|
|
|
'voteCount' => 'sint32',
|
|
|
|
'content' => 'text',
|
2015-08-14 09:25:02 -07:00
|
|
|
'status' => 'text32',
|
2015-08-04 10:49:15 -07:00
|
|
|
'mailKey' => 'bytes20',
|
2014-10-01 07:37:14 -07:00
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_phid' => null,
|
|
|
|
'phid' => array(
|
|
|
|
'columns' => array('phid'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
'key_oneanswerperquestion' => array(
|
|
|
|
'columns' => array('questionID', 'authorPHID'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
'questionID' => array(
|
|
|
|
'columns' => array('questionID'),
|
|
|
|
),
|
|
|
|
'authorPHID' => array(
|
|
|
|
'columns' => array('authorPHID'),
|
|
|
|
),
|
2015-08-14 09:25:02 -07:00
|
|
|
'status' => array(
|
|
|
|
'columns' => array('status'),
|
|
|
|
),
|
2014-10-01 07:37:14 -07:00
|
|
|
),
|
2012-08-10 10:44:04 -07:00
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
2014-07-24 08:05:46 +10:00
|
|
|
return PhabricatorPHID::generateNewPHID(PonderAnswerPHIDType::TYPECONST);
|
2012-08-10 10:44:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getMarkupField() {
|
|
|
|
return self::MARKUP_FIELD_CONTENT;
|
|
|
|
}
|
|
|
|
|
2015-08-04 10:49:15 -07:00
|
|
|
public function save() {
|
|
|
|
if (!$this->getMailKey()) {
|
|
|
|
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
|
|
|
}
|
|
|
|
return parent::save();
|
|
|
|
}
|
|
|
|
|
Transactions - deploy buildTransactionTimeline to remaining applications
Summary:
Ref T4712. Specifically...
- Differential
- needed getApplicationTransactionViewObject() implemented
- Audit
- needed getApplicationTransactionViewObject() implemented
- Repository
- one object needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true)
- Ponder
- BONUS BUG FIX - leaving a comment on an answer had a bad redirect URI
- both PonderQuestion and PonderAnswer needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) on both "history" controllers
- left a "TODO" on buildAnswers on the question view controller, which is non-standard and should be re-written eventually
- Phortune
- BONUS BUG FIX - fix new user "createNewAccount" code to not fatal
- PhortuneAccount, PhortuneMerchant, and PhortuneCart needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) on Account view, merchant view, and cart view controller
- Fund
- Legalpad
- Nuance
- NuanceSource needed PhabricatorApplicationTransactionInterface implemented
- Releeph (this product is kind of a mess...)
- HACKQUEST - had to manually create an arcanist project to even be able to make a "product" and get started...!
- BONUS BUG FIX - make sure to "setName" on product edit
- ReleephProject (should be ReleepProduct...?), ReleephBranch, and ReleepRequest needed PhabricatorApplicationTransactionInterface implemented
- Harbormaster
- HarbormasterBuildable, HarbormasterBuild, HarbormasterBuildPlan, and HarbormasterBuildStep all needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) all over the place
Test Plan: foreach application, viewed the timeline(s) and made sure they still rendered
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T4712
Differential Revision: https://secure.phabricator.com/D10925
2014-12-03 15:35:47 -08:00
|
|
|
|
|
|
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getApplicationTransactionEditor() {
|
|
|
|
return new PonderAnswerEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionObject() {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionTemplate() {
|
|
|
|
return new PonderAnswerTransaction();
|
|
|
|
}
|
|
|
|
|
2014-12-04 13:58:52 -08:00
|
|
|
public function willRenderTimeline(
|
|
|
|
PhabricatorApplicationTransactionView $timeline,
|
|
|
|
AphrontRequest $request) {
|
|
|
|
|
|
|
|
return $timeline;
|
|
|
|
}
|
|
|
|
|
Transactions - deploy buildTransactionTimeline to remaining applications
Summary:
Ref T4712. Specifically...
- Differential
- needed getApplicationTransactionViewObject() implemented
- Audit
- needed getApplicationTransactionViewObject() implemented
- Repository
- one object needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true)
- Ponder
- BONUS BUG FIX - leaving a comment on an answer had a bad redirect URI
- both PonderQuestion and PonderAnswer needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) on both "history" controllers
- left a "TODO" on buildAnswers on the question view controller, which is non-standard and should be re-written eventually
- Phortune
- BONUS BUG FIX - fix new user "createNewAccount" code to not fatal
- PhortuneAccount, PhortuneMerchant, and PhortuneCart needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) on Account view, merchant view, and cart view controller
- Fund
- Legalpad
- Nuance
- NuanceSource needed PhabricatorApplicationTransactionInterface implemented
- Releeph (this product is kind of a mess...)
- HACKQUEST - had to manually create an arcanist project to even be able to make a "product" and get started...!
- BONUS BUG FIX - make sure to "setName" on product edit
- ReleephProject (should be ReleepProduct...?), ReleephBranch, and ReleepRequest needed PhabricatorApplicationTransactionInterface implemented
- Harbormaster
- HarbormasterBuildable, HarbormasterBuild, HarbormasterBuildPlan, and HarbormasterBuildStep all needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) all over the place
Test Plan: foreach application, viewed the timeline(s) and made sure they still rendered
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T4712
Differential Revision: https://secure.phabricator.com/D10925
2014-12-03 15:35:47 -08:00
|
|
|
|
2012-08-10 10:44:04 -07:00
|
|
|
// Markup interface
|
|
|
|
|
|
|
|
public function getMarkupFieldKey($field) {
|
|
|
|
$hash = PhabricatorHash::digest($this->getMarkupText($field));
|
|
|
|
$id = $this->getID();
|
|
|
|
return "ponder:A{$id}:{$field}:{$hash}";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMarkupText($field) {
|
|
|
|
return $this->getContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newMarkupEngine($field) {
|
2013-08-05 10:47:26 -07:00
|
|
|
return PhabricatorMarkupEngine::getEngine();
|
2012-08-10 10:44:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function didMarkupText(
|
|
|
|
$field,
|
|
|
|
$output,
|
|
|
|
PhutilMarkupEngine $engine) {
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldUseMarkupCache($field) {
|
|
|
|
return (bool)$this->getID();
|
|
|
|
}
|
|
|
|
|
2013-07-26 13:19:49 -07:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return $this->getQuestion()->getPolicy($capability);
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
2015-08-08 12:20:01 -07:00
|
|
|
$app = PhabricatorApplication::getByClass(
|
|
|
|
'PhabricatorPonderApplication');
|
|
|
|
return $app->getPolicy(PonderModerateCapability::CAPABILITY);
|
2013-07-26 13:19:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
2013-09-27 08:43:41 -07:00
|
|
|
if ($this->getAuthorPHID() == $viewer->getPHID()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-26 13:19:49 -07:00
|
|
|
return $this->getQuestion()->hasAutomaticCapability(
|
|
|
|
$capability,
|
|
|
|
$viewer);
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return ($this->getAuthorPHID() == $viewer->getPHID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-28 17:23:04 -07:00
|
|
|
|
2013-09-27 08:43:41 -07:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
$out = array();
|
2014-06-09 11:36:49 -07:00
|
|
|
$out[] = pht('The author of an answer can always view and edit it.');
|
2013-09-27 08:43:41 -07:00
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
$out[] = pht(
|
2014-06-09 11:36:49 -07:00
|
|
|
'The user who asks a question can always view the answers.');
|
2015-08-08 12:20:01 -07:00
|
|
|
$out[] = pht(
|
|
|
|
'A moderator can always view the answers.');
|
2013-09-27 08:43:41 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-28 17:23:04 -07:00
|
|
|
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function isAutomaticallySubscribed($phid) {
|
|
|
|
return ($phid == $this->getAuthorPHID());
|
|
|
|
}
|
|
|
|
|
Make Projects a PhabricatorSubscribableInterface, but with restricted defaults
Summary:
Ref T4379. I want project subscriptions to work like this (yell if this seems whacky, since it makes subscriptions mean somethign a little different for projects than they do for other objects):
- You can only subscribe to a project if you're a project member.
- When you're added as a member, you're added as a subscriber.
- When you're removed as a member, you're removed as a subscriber.
- While you're a member, you can optionally unsubscribe.
From a UI perspective:
- We don't show the subscriber list, since it's going to be some uninteresting subset of the member list.
- We don't show CC transactions in history, since they're an uninteresting near-approximation of the membership transactions.
- You only see the subscription controls if you're a member.
To do this, I've augmented `PhabricatorSubscribableInterface` with two new methods. It would be nice if we were on PHP 5.4+ and could just use traits for this, but we should get data about version usage before we think about this. For now, copy/paste the default implementations into every implementing class.
Then, I implemented the interface in `PhabricatorProject` but with alternate defaults.
Test Plan:
- Used the normal interaction on existing objects.
- This has no actual effect on projects, verified no subscription stuff mysteriously appeared.
- Hit the new error case by fiddling with the UI.
Reviewers: btrahan
Reviewed By: btrahan
CC: chad, aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8165
2014-02-10 14:29:17 -08:00
|
|
|
public function shouldShowSubscribersProperty() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-25 08:41:03 -07:00
|
|
|
|
|
|
|
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function destroyObjectPermanently(
|
|
|
|
PhabricatorDestructionEngine $engine) {
|
|
|
|
|
|
|
|
$this->openTransaction();
|
|
|
|
$this->delete();
|
|
|
|
$this->saveTransaction();
|
|
|
|
}
|
|
|
|
|
2012-08-10 10:44:04 -07:00
|
|
|
}
|