mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 12:52:42 +01:00
Add ability to hide answers in Ponder
Summary: Ref T9173, adds basic hide support for answers. Answer authors and Moderators can hide answers, unhide them. Test Plan: Hide answer, log into other account, see hidden message. Mark as visible, see answer again. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9173 Differential Revision: https://secure.phabricator.com/D13894
This commit is contained in:
parent
3b987a93ce
commit
603c91e08a
10 changed files with 132 additions and 4 deletions
2
resources/sql/autopatches/20150812.ponder.answer.1.sql
Normal file
2
resources/sql/autopatches/20150812.ponder.answer.1.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_ponder.ponder_answer
|
||||||
|
ADD status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT};
|
2
resources/sql/autopatches/20150812.ponder.answer.2.sql
Normal file
2
resources/sql/autopatches/20150812.ponder.answer.2.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
UPDATE {$NAMESPACE}_ponder.ponder_answer
|
||||||
|
SET status = 'visible' WHERE status = '';
|
|
@ -3395,6 +3395,7 @@ phutil_register_library_map(array(
|
||||||
'PonderAnswerPHIDType' => 'applications/ponder/phid/PonderAnswerPHIDType.php',
|
'PonderAnswerPHIDType' => 'applications/ponder/phid/PonderAnswerPHIDType.php',
|
||||||
'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php',
|
'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php',
|
||||||
'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php',
|
'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php',
|
||||||
|
'PonderAnswerStatus' => 'applications/ponder/constants/PonderAnswerStatus.php',
|
||||||
'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php',
|
'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php',
|
||||||
'PonderAnswerTransactionComment' => 'applications/ponder/storage/PonderAnswerTransactionComment.php',
|
'PonderAnswerTransactionComment' => 'applications/ponder/storage/PonderAnswerTransactionComment.php',
|
||||||
'PonderAnswerTransactionQuery' => 'applications/ponder/query/PonderAnswerTransactionQuery.php',
|
'PonderAnswerTransactionQuery' => 'applications/ponder/query/PonderAnswerTransactionQuery.php',
|
||||||
|
@ -7581,6 +7582,7 @@ phutil_register_library_map(array(
|
||||||
'PonderAnswerPHIDType' => 'PhabricatorPHIDType',
|
'PonderAnswerPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PonderAnswerSaveController' => 'PonderController',
|
'PonderAnswerSaveController' => 'PonderController',
|
||||||
|
'PonderAnswerStatus' => 'PonderConstants',
|
||||||
'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction',
|
'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'PonderAnswerTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
'PonderAnswerTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||||
'PonderAnswerTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'PonderAnswerTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
|
|
24
src/applications/ponder/constants/PonderAnswerStatus.php
Normal file
24
src/applications/ponder/constants/PonderAnswerStatus.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PonderAnswerStatus extends PonderConstants {
|
||||||
|
|
||||||
|
const ANSWER_STATUS_VISIBLE = 'visible';
|
||||||
|
const ANSWER_STATUS_HIDDEN = 'hidden';
|
||||||
|
|
||||||
|
public static function getAnswerStatusMap() {
|
||||||
|
return array(
|
||||||
|
self::ANSWER_STATUS_VISIBLE => pht('Visible'),
|
||||||
|
self::ANSWER_STATUS_HIDDEN => pht('Hidden'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAnswerStatusName($status) {
|
||||||
|
$map = array(
|
||||||
|
self::ANSWER_STATUS_VISIBLE => pht('Visible'),
|
||||||
|
self::ANSWER_STATUS_HIDDEN => pht('Hidden'),
|
||||||
|
);
|
||||||
|
return idx($map, $status, pht('Unknown'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -7,6 +7,9 @@ final class PonderQuestionStatus extends PonderConstants {
|
||||||
const STATUS_CLOSED_OBSOLETE = 'obsolete';
|
const STATUS_CLOSED_OBSOLETE = 'obsolete';
|
||||||
const STATUS_CLOSED_DUPLICATE = 'duplicate';
|
const STATUS_CLOSED_DUPLICATE = 'duplicate';
|
||||||
|
|
||||||
|
const ANSWER_STATUS_VISIBLE = 'visible';
|
||||||
|
const ANSWER_STATUS_HIDDEN = 'hidden';
|
||||||
|
|
||||||
public static function getQuestionStatusMap() {
|
public static function getQuestionStatusMap() {
|
||||||
return array(
|
return array(
|
||||||
self::STATUS_OPEN => pht('Open'),
|
self::STATUS_OPEN => pht('Open'),
|
||||||
|
@ -86,5 +89,20 @@ final class PonderQuestionStatus extends PonderConstants {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAnswerStatusMap() {
|
||||||
|
return array(
|
||||||
|
self::ANSWER_STATUS_VISIBLE => pht('Visible'),
|
||||||
|
self::ANSWER_STATUS_HIDDEN => pht('Hidden'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAnswerStatusName($status) {
|
||||||
|
$map = array(
|
||||||
|
self::ANSWER_STATUS_VISIBLE => pht('Visible'),
|
||||||
|
self::ANSWER_STATUS_HIDDEN => pht('Hidden'),
|
||||||
|
);
|
||||||
|
return idx($map, $status, pht('Unknown'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ final class PonderAnswerEditController extends PonderController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$v_content = $answer->getContent();
|
$v_content = $answer->getContent();
|
||||||
|
$v_status = $answer->getStatus();
|
||||||
$e_content = true;
|
$e_content = true;
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ final class PonderAnswerEditController extends PonderController {
|
||||||
$errors = array();
|
$errors = array();
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$v_content = $request->getStr('content');
|
$v_content = $request->getStr('content');
|
||||||
|
$v_status = $request->getStr('status');
|
||||||
|
|
||||||
if (!strlen($v_content)) {
|
if (!strlen($v_content)) {
|
||||||
$errors[] = pht('You must provide some substance in your answer.');
|
$errors[] = pht('You must provide some substance in your answer.');
|
||||||
|
@ -43,6 +45,10 @@ final class PonderAnswerEditController extends PonderController {
|
||||||
->setTransactionType(PonderAnswerTransaction::TYPE_CONTENT)
|
->setTransactionType(PonderAnswerTransaction::TYPE_CONTENT)
|
||||||
->setNewValue($v_content);
|
->setNewValue($v_content);
|
||||||
|
|
||||||
|
$xactions[] = id(new PonderAnswerTransaction())
|
||||||
|
->setTransactionType(PonderAnswerTransaction::TYPE_STATUS)
|
||||||
|
->setNewValue($v_status);
|
||||||
|
|
||||||
$editor = id(new PonderAnswerEditor())
|
$editor = id(new PonderAnswerEditor())
|
||||||
->setActor($viewer)
|
->setActor($viewer)
|
||||||
->setContentSourceFromRequest($request)
|
->setContentSourceFromRequest($request)
|
||||||
|
@ -63,6 +69,12 @@ final class PonderAnswerEditController extends PonderController {
|
||||||
id(new AphrontFormStaticControl())
|
id(new AphrontFormStaticControl())
|
||||||
->setLabel(pht('Question'))
|
->setLabel(pht('Question'))
|
||||||
->setValue($question->getTitle()))
|
->setValue($question->getTitle()))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormSelectControl())
|
||||||
|
->setLabel(pht('Status'))
|
||||||
|
->setName('status')
|
||||||
|
->setValue($v_status)
|
||||||
|
->setOptions(PonderAnswerStatus::getAnswerStatusMap()))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new PhabricatorRemarkupControl())
|
id(new PhabricatorRemarkupControl())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
|
@ -73,7 +85,7 @@ final class PonderAnswerEditController extends PonderController {
|
||||||
->setError($e_content))
|
->setError($e_content))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue(pht('Update Answer'))
|
->setValue(pht('Submit'))
|
||||||
->addCancelButton($answer_uri));
|
->addCancelButton($answer_uri));
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
|
|
|
@ -12,6 +12,7 @@ final class PonderAnswerEditor extends PonderEditor {
|
||||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||||
|
|
||||||
$types[] = PonderAnswerTransaction::TYPE_CONTENT;
|
$types[] = PonderAnswerTransaction::TYPE_CONTENT;
|
||||||
|
$types[] = PonderAnswerTransaction::TYPE_STATUS;
|
||||||
$types[] = PonderAnswerTransaction::TYPE_QUESTION_ID;
|
$types[] = PonderAnswerTransaction::TYPE_QUESTION_ID;
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
|
@ -23,6 +24,7 @@ final class PonderAnswerEditor extends PonderEditor {
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PonderAnswerTransaction::TYPE_CONTENT:
|
case PonderAnswerTransaction::TYPE_CONTENT:
|
||||||
|
case PonderAnswerTransaction::TYPE_STATUS:
|
||||||
return $object->getContent();
|
return $object->getContent();
|
||||||
case PonderAnswerTransaction::TYPE_QUESTION_ID:
|
case PonderAnswerTransaction::TYPE_QUESTION_ID:
|
||||||
return $object->getQuestionID();
|
return $object->getQuestionID();
|
||||||
|
@ -35,6 +37,7 @@ final class PonderAnswerEditor extends PonderEditor {
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PonderAnswerTransaction::TYPE_CONTENT:
|
case PonderAnswerTransaction::TYPE_CONTENT:
|
||||||
|
case PonderAnswerTransaction::TYPE_STATUS:
|
||||||
case PonderAnswerTransaction::TYPE_QUESTION_ID:
|
case PonderAnswerTransaction::TYPE_QUESTION_ID:
|
||||||
return $xaction->getNewValue();
|
return $xaction->getNewValue();
|
||||||
}
|
}
|
||||||
|
@ -48,6 +51,9 @@ final class PonderAnswerEditor extends PonderEditor {
|
||||||
case PonderAnswerTransaction::TYPE_CONTENT:
|
case PonderAnswerTransaction::TYPE_CONTENT:
|
||||||
$object->setContent($xaction->getNewValue());
|
$object->setContent($xaction->getNewValue());
|
||||||
break;
|
break;
|
||||||
|
case PonderAnswerTransaction::TYPE_STATUS:
|
||||||
|
$object->setStatus($xaction->getNewValue());
|
||||||
|
break;
|
||||||
case PonderAnswerTransaction::TYPE_QUESTION_ID:
|
case PonderAnswerTransaction::TYPE_QUESTION_ID:
|
||||||
$object->setQuestionID($xaction->getNewValue());
|
$object->setQuestionID($xaction->getNewValue());
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -17,8 +17,9 @@ final class PonderAnswer extends PonderDAO
|
||||||
|
|
||||||
protected $content;
|
protected $content;
|
||||||
protected $mailKey;
|
protected $mailKey;
|
||||||
|
protected $status;
|
||||||
protected $voteCount;
|
protected $voteCount;
|
||||||
|
|
||||||
private $vote;
|
private $vote;
|
||||||
private $question = self::ATTACHABLE;
|
private $question = self::ATTACHABLE;
|
||||||
private $comments;
|
private $comments;
|
||||||
|
@ -35,7 +36,8 @@ final class PonderAnswer extends PonderDAO
|
||||||
->setQuestionID(0)
|
->setQuestionID(0)
|
||||||
->setContent('')
|
->setContent('')
|
||||||
->setAuthorPHID($actor->getPHID())
|
->setAuthorPHID($actor->getPHID())
|
||||||
->setVoteCount(0);
|
->setVoteCount(0)
|
||||||
|
->setStatus(PonderAnswerStatus::ANSWER_STATUS_VISIBLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +86,7 @@ final class PonderAnswer extends PonderDAO
|
||||||
self::CONFIG_COLUMN_SCHEMA => array(
|
self::CONFIG_COLUMN_SCHEMA => array(
|
||||||
'voteCount' => 'sint32',
|
'voteCount' => 'sint32',
|
||||||
'content' => 'text',
|
'content' => 'text',
|
||||||
|
'status' => 'text32',
|
||||||
'mailKey' => 'bytes20',
|
'mailKey' => 'bytes20',
|
||||||
),
|
),
|
||||||
self::CONFIG_KEY_SCHEMA => array(
|
self::CONFIG_KEY_SCHEMA => array(
|
||||||
|
@ -102,6 +105,9 @@ final class PonderAnswer extends PonderDAO
|
||||||
'authorPHID' => array(
|
'authorPHID' => array(
|
||||||
'columns' => array('authorPHID'),
|
'columns' => array('authorPHID'),
|
||||||
),
|
),
|
||||||
|
'status' => array(
|
||||||
|
'columns' => array('status'),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ final class PonderAnswerTransaction
|
||||||
extends PhabricatorApplicationTransaction {
|
extends PhabricatorApplicationTransaction {
|
||||||
|
|
||||||
const TYPE_CONTENT = 'ponder.answer:content';
|
const TYPE_CONTENT = 'ponder.answer:content';
|
||||||
|
const TYPE_STATUS = 'ponder.answer:status';
|
||||||
const TYPE_QUESTION_ID = 'ponder.answer:question-id';
|
const TYPE_QUESTION_ID = 'ponder.answer:question-id';
|
||||||
|
|
||||||
public function getApplicationName() {
|
public function getApplicationName() {
|
||||||
|
@ -27,6 +28,7 @@ final class PonderAnswerTransaction
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case self::TYPE_CONTENT:
|
case self::TYPE_CONTENT:
|
||||||
|
case self::TYPE_STATUS:
|
||||||
$phids[] = $this->getObjectPHID();
|
$phids[] = $this->getObjectPHID();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +77,19 @@ final class PonderAnswerTransaction
|
||||||
$this->renderHandleLink($object_phid));
|
$this->renderHandleLink($object_phid));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case self::TYPE_STATUS:
|
||||||
|
if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) {
|
||||||
|
return pht(
|
||||||
|
'%s marked %s as visible.',
|
||||||
|
$this->renderHandleLink($author_phid),
|
||||||
|
$this->renderHandleLink($object_phid));
|
||||||
|
} else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
|
||||||
|
return pht(
|
||||||
|
'%s marked %s as hidden.',
|
||||||
|
$this->renderHandleLink($author_phid),
|
||||||
|
$this->renderHandleLink($object_phid));
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getTitle();
|
return parent::getTitle();
|
||||||
|
@ -101,6 +116,19 @@ final class PonderAnswerTransaction
|
||||||
$this->renderHandleLink($object_phid));
|
$this->renderHandleLink($object_phid));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case self::TYPE_STATUS:
|
||||||
|
if ($new == PonderAnswerStatus::ANSWER_STATUS_VISIBLE) {
|
||||||
|
return pht(
|
||||||
|
'%s marked %s as visible.',
|
||||||
|
$this->renderHandleLink($author_phid),
|
||||||
|
$this->renderHandleLink($object_phid));
|
||||||
|
} else if ($new == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
|
||||||
|
return pht(
|
||||||
|
'%s marked %s as hidden.',
|
||||||
|
$this->renderHandleLink($author_phid),
|
||||||
|
$this->renderHandleLink($object_phid));
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getTitleForFeed();
|
return parent::getTitleForFeed();
|
||||||
|
|
|
@ -31,8 +31,37 @@ final class PonderAnswerView extends AphrontTagView {
|
||||||
require_celerity_resource('ponder-view-css');
|
require_celerity_resource('ponder-view-css');
|
||||||
$answer = $this->answer;
|
$answer = $this->answer;
|
||||||
$viewer = $this->getUser();
|
$viewer = $this->getUser();
|
||||||
|
$status = $answer->getStatus();
|
||||||
$author_phid = $answer->getAuthorPHID();
|
$author_phid = $answer->getAuthorPHID();
|
||||||
$actions = $this->buildAnswerActions();
|
$actions = $this->buildAnswerActions();
|
||||||
|
$id = $answer->getID();
|
||||||
|
|
||||||
|
if ($status == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
|
||||||
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||||
|
$viewer,
|
||||||
|
$answer,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
|
$message = array();
|
||||||
|
$message[] = phutil_tag(
|
||||||
|
'em',
|
||||||
|
array(),
|
||||||
|
pht('This answer has been hidden.'));
|
||||||
|
|
||||||
|
if ($can_edit) {
|
||||||
|
$message[] = phutil_tag(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => "/ponder/answer/edit/{$id}/",
|
||||||
|
),
|
||||||
|
pht('Edit Answer'));
|
||||||
|
}
|
||||||
|
$message = phutil_implode_html(' ', $message);
|
||||||
|
|
||||||
|
return id(new PHUIInfoView())
|
||||||
|
->setSeverity(PHUIInfoView::SEVERITY_NODATA)
|
||||||
|
->appendChild($message);
|
||||||
|
}
|
||||||
|
|
||||||
$action_button = id(new PHUIButtonView())
|
$action_button = id(new PHUIButtonView())
|
||||||
->setTag('a')
|
->setTag('a')
|
||||||
|
@ -57,7 +86,6 @@ final class PonderAnswerView extends AphrontTagView {
|
||||||
$answer->getMarkupField(),
|
$answer->getMarkupField(),
|
||||||
$viewer));
|
$viewer));
|
||||||
|
|
||||||
$id = $answer->getID();
|
|
||||||
$anchor = id(new PhabricatorAnchorView())
|
$anchor = id(new PhabricatorAnchorView())
|
||||||
->setAnchorName("A$id");
|
->setAnchorName("A$id");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue