mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 10:12:41 +01:00
Add inline comments to Diffusion/Audit
Summary: - Add inline comments to Audits, like Differential. - Creates new storage for the comments in the Audits database. - Creates a new PhabricatorAuditInlineComment class, similar to DifferentialInlineComment. - Defines an Interface which Differential and Audit comments conform to. - Makes consumers of DifferentialInlineComments consume objects which implement that interface instead. - Adds save NOTE: Some features are still missing! Wanted to cut this off before it got crazy: - Inline comments aren't shown in the main comment list. - Inline comments aren't shown in the emails. - Inline comments aren't previewed. I'll followup with those but this was getting pretty big. @vrana, does the SQL change look correct? Test Plan: - Created, edited, deleted, replied to, reloaded and saved inline comments in Diffusion, on the left and right side of diffs. - Created, edited, deleted, replied to, reloaded and saved inline comments in Differentila, on the left and right side of primary and diff-versus-diff diffs. Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T904 Differential Revision: https://secure.phabricator.com/D1898
This commit is contained in:
parent
f0e9df1fda
commit
900190b2fe
26 changed files with 829 additions and 236 deletions
16
resources/sql/patches/118.auditinline.sql
Normal file
16
resources/sql/patches/118.auditinline.sql
Normal file
|
@ -0,0 +1,16 @@
|
|||
CREATE TABLE phabricator_audit.audit_inlinecomment (
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
authorPHID varchar(64) COLLATE utf8_bin NOT NULL,
|
||||
commitPHID varchar(64) COLLATE utf8_bin NOT NULL,
|
||||
pathID INT UNSIGNED NOT NULL,
|
||||
auditCommentID INT UNSIGNED,
|
||||
isNewFile BOOL NOT NULL,
|
||||
lineNumber INT UNSIGNED NOT NULL,
|
||||
lineLength INT UNSIGNED NOT NULL,
|
||||
content LONGTEXT COLLATE utf8_bin,
|
||||
cache LONGTEXT COLLATE utf8_bin,
|
||||
dateCreated INT UNSIGNED NOT NULL,
|
||||
dateModified INT UNSIGNED NOT NULL,
|
||||
KEY (commitPHID, pathID),
|
||||
KEY (authorPHID, commitPHID, auditCommentID)
|
||||
) ENGINE=InnoDB, COLLATE utf8_general_ci;
|
|
@ -309,6 +309,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionHistoryQuery' => 'applications/diffusion/query/history/base',
|
||||
'DiffusionHistoryTableView' => 'applications/diffusion/view/historytable',
|
||||
'DiffusionHomeController' => 'applications/diffusion/controller/home',
|
||||
'DiffusionInlineCommentController' => 'applications/diffusion/controller/inline',
|
||||
'DiffusionLastModifiedController' => 'applications/diffusion/controller/lastmodified',
|
||||
'DiffusionLastModifiedQuery' => 'applications/diffusion/query/lastmodified/base',
|
||||
'DiffusionMercurialBranchQuery' => 'applications/diffusion/query/branch/mercurial',
|
||||
|
@ -456,6 +457,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorAuditCommitStatusConstants' => 'applications/audit/constants/commitstatus',
|
||||
'PhabricatorAuditController' => 'applications/audit/controller/base',
|
||||
'PhabricatorAuditDAO' => 'applications/audit/storage/base',
|
||||
'PhabricatorAuditInlineComment' => 'applications/audit/storage/inlinecommment',
|
||||
'PhabricatorAuditListController' => 'applications/audit/controller/list',
|
||||
'PhabricatorAuditListView' => 'applications/audit/view/list',
|
||||
'PhabricatorAuditPreviewController' => 'applications/audit/controller/preview',
|
||||
|
@ -590,6 +592,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorIRCWhatsNewHandler' => 'infrastructure/daemon/irc/handler/whatsnew',
|
||||
'PhabricatorImageTransformer' => 'applications/files/transform',
|
||||
'PhabricatorInfrastructureTestCase' => 'infrastructure/__tests__',
|
||||
'PhabricatorInlineCommentController' => 'infrastructure/diff/controller',
|
||||
'PhabricatorInlineCommentInterface' => 'infrastructure/diff/interface/inline',
|
||||
'PhabricatorJavelinLinter' => 'infrastructure/lint/linter/javelin',
|
||||
'PhabricatorJumpNavHandler' => 'applications/search/engine/jumpnav',
|
||||
'PhabricatorLintEngine' => 'infrastructure/lint/engine',
|
||||
|
@ -1097,7 +1101,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialHostFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialHunk' => 'DifferentialDAO',
|
||||
'DifferentialInlineComment' => 'DifferentialDAO',
|
||||
'DifferentialInlineCommentEditController' => 'DifferentialController',
|
||||
'DifferentialInlineCommentEditController' => 'PhabricatorInlineCommentController',
|
||||
'DifferentialInlineCommentEditView' => 'AphrontView',
|
||||
'DifferentialInlineCommentPreviewController' => 'DifferentialController',
|
||||
'DifferentialInlineCommentView' => 'AphrontView',
|
||||
|
@ -1157,6 +1161,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionHistoryController' => 'DiffusionController',
|
||||
'DiffusionHistoryTableView' => 'DiffusionView',
|
||||
'DiffusionHomeController' => 'DiffusionController',
|
||||
'DiffusionInlineCommentController' => 'PhabricatorInlineCommentController',
|
||||
'DiffusionLastModifiedController' => 'DiffusionController',
|
||||
'DiffusionMercurialBranchQuery' => 'DiffusionBranchQuery',
|
||||
'DiffusionMercurialBrowseQuery' => 'DiffusionBrowseQuery',
|
||||
|
@ -1260,6 +1265,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorAuditCommitListView' => 'AphrontView',
|
||||
'PhabricatorAuditController' => 'PhabricatorController',
|
||||
'PhabricatorAuditDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorAuditInlineComment' => 'PhabricatorAuditDAO',
|
||||
'PhabricatorAuditListController' => 'PhabricatorAuditController',
|
||||
'PhabricatorAuditListView' => 'AphrontView',
|
||||
'PhabricatorAuditPreviewController' => 'PhabricatorAuditController',
|
||||
|
@ -1371,6 +1377,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorIRCProtocolHandler' => 'PhabricatorIRCHandler',
|
||||
'PhabricatorIRCWhatsNewHandler' => 'PhabricatorIRCHandler',
|
||||
'PhabricatorInfrastructureTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorInlineCommentController' => 'PhabricatorController',
|
||||
'PhabricatorJavelinLinter' => 'ArcanistLinter',
|
||||
'PhabricatorLintEngine' => 'PhutilLintEngine',
|
||||
'PhabricatorLiskDAO' => 'LiskDAO',
|
||||
|
@ -1628,5 +1635,13 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'requires_interface' =>
|
||||
array(
|
||||
'DifferentialInlineComment' =>
|
||||
array(
|
||||
0 => 'PhabricatorInlineCommentInterface',
|
||||
),
|
||||
'PhabricatorAuditInlineComment' =>
|
||||
array(
|
||||
0 => 'PhabricatorInlineCommentInterface',
|
||||
),
|
||||
),
|
||||
));
|
||||
|
|
|
@ -272,6 +272,7 @@ class AphrontDefaultApplicationConfiguration
|
|||
'(?:[;](?P<commit>[a-z0-9]+))?'
|
||||
=> 'DiffusionLastModifiedController',
|
||||
),
|
||||
'inline/(?P<phid>[^/]+)/' => 'DiffusionInlineCommentController',
|
||||
'services/' => array(
|
||||
'path/' => array(
|
||||
'complete/' => 'DiffusionPathCompleteController',
|
||||
|
|
|
@ -43,6 +43,7 @@ final class PhabricatorAuditAddCommentController
|
|||
|
||||
id(new PhabricatorAuditCommentEditor($commit))
|
||||
->setUser($user)
|
||||
->setAttachInlineComments(true)
|
||||
->addComment($comment);
|
||||
|
||||
$phids = array($commit_phid);
|
||||
|
|
|
@ -21,6 +21,8 @@ final class PhabricatorAuditCommentEditor {
|
|||
private $commit;
|
||||
private $user;
|
||||
|
||||
private $attachInlineComments;
|
||||
|
||||
public function __construct(PhabricatorRepositoryCommit $commit) {
|
||||
$this->commit = $commit;
|
||||
return $this;
|
||||
|
@ -31,6 +33,11 @@ final class PhabricatorAuditCommentEditor {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setAttachInlineComments($attach_inline_comments) {
|
||||
$this->attachInlineComments = $attach_inline_comments;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addComment(PhabricatorAuditComment $comment) {
|
||||
|
||||
$commit = $this->commit;
|
||||
|
@ -40,11 +47,27 @@ final class PhabricatorAuditCommentEditor {
|
|||
'targetPHID = %s',
|
||||
$commit->getPHID());
|
||||
|
||||
$inline_comments = array();
|
||||
if ($this->attachInlineComments) {
|
||||
$inline_comments = id(new PhabricatorAuditInlineComment())->loadAllWhere(
|
||||
'authorPHID = %s AND commitPHID = %s
|
||||
AND auditCommentID IS NULL',
|
||||
$user->getPHID(),
|
||||
$commit->getPHID());
|
||||
}
|
||||
|
||||
$comment
|
||||
->setActorPHID($user->getPHID())
|
||||
->setTargetPHID($commit->getPHID())
|
||||
->save();
|
||||
|
||||
if ($inline_comments) {
|
||||
foreach ($inline_comments as $inline) {
|
||||
$inline->setAuditCommentID($comment->getID());
|
||||
$inline->save();
|
||||
}
|
||||
}
|
||||
|
||||
// When a user submits an audit comment, we update all the audit requests
|
||||
// they have authority over to reflect the most recent status. The general
|
||||
// idea here is that if audit has triggered for, e.g., several packages, but
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
phutil_require_module('phabricator', 'applications/audit/constants/action');
|
||||
phutil_require_module('phabricator', 'applications/audit/constants/status');
|
||||
phutil_require_module('phabricator', 'applications/audit/storage/auditcomment');
|
||||
phutil_require_module('phabricator', 'applications/audit/storage/inlinecommment');
|
||||
phutil_require_module('phabricator', 'applications/feed/constants/story');
|
||||
phutil_require_module('phabricator', 'applications/feed/publisher');
|
||||
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class PhabricatorAuditInlineComment
|
||||
extends PhabricatorAuditDAO
|
||||
implements PhabricatorInlineCommentInterface {
|
||||
|
||||
protected $commitPHID;
|
||||
protected $pathID;
|
||||
protected $auditCommentID;
|
||||
|
||||
protected $authorPHID;
|
||||
protected $isNewFile;
|
||||
protected $lineNumber;
|
||||
protected $lineLength;
|
||||
protected $content;
|
||||
protected $cache;
|
||||
|
||||
private $syntheticAuthor;
|
||||
|
||||
public function setSyntheticAuthor($synthetic_author) {
|
||||
$this->syntheticAuthor = $synthetic_author;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSyntheticAuthor() {
|
||||
return $this->syntheticAuthor;
|
||||
}
|
||||
|
||||
public function isCompatible(PhabricatorInlineCommentInterface $comment) {
|
||||
return
|
||||
($this->getAuthorPHID() === $comment->getAuthorPHID()) &&
|
||||
($this->getSyntheticAuthor() === $comment->getSyntheticAuthor()) &&
|
||||
($this->getContent() === $comment->getContent());
|
||||
}
|
||||
|
||||
public function setContent($content) {
|
||||
$this->setCache(null);
|
||||
$this->writeField('content', $content);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContent() {
|
||||
return $this->readField('content');
|
||||
}
|
||||
|
||||
public function isDraft() {
|
||||
return !$this->getAuditCommentID();
|
||||
}
|
||||
|
||||
public function setChangesetID($id) {
|
||||
return $this->setPathID($id);
|
||||
}
|
||||
|
||||
public function getChangesetID() {
|
||||
return $this->getPathID();
|
||||
}
|
||||
|
||||
// NOTE: We need to provide implementations so we conform to the shared
|
||||
// interface; these are all trivial and just explicit versions of the Lisk
|
||||
// defaults.
|
||||
|
||||
public function setIsNewFile($is_new) {
|
||||
$this->writeField('isNewFile', $is_new);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsNewFile() {
|
||||
return $this->readField('isNewFile');
|
||||
}
|
||||
|
||||
public function setLineNumber($number) {
|
||||
$this->writeField('lineNumber', $number);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLineNumber() {
|
||||
return $this->readField('lineNumber');
|
||||
}
|
||||
|
||||
public function setLineLength($length) {
|
||||
$this->writeField('lineLength', $length);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLineLength() {
|
||||
return $this->readField('lineLength');
|
||||
}
|
||||
|
||||
public function setCache($cache) {
|
||||
$this->writeField('cache', $cache);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCache() {
|
||||
return $this->readField('cache');
|
||||
}
|
||||
|
||||
public function setAuthorPHID($phid) {
|
||||
$this->writeField('authorPHID', $phid);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAuthorPHID() {
|
||||
return $this->readField('authorPHID');
|
||||
}
|
||||
|
||||
}
|
13
src/applications/audit/storage/inlinecommment/__init__.php
Normal file
13
src/applications/audit/storage/inlinecommment/__init__.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/audit/storage/base');
|
||||
phutil_require_module('phabricator', 'infrastructure/diff/interface/inline');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorAuditInlineComment.php');
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
final class DifferentialInlineCommentEditController
|
||||
extends DifferentialController {
|
||||
extends PhabricatorInlineCommentController {
|
||||
|
||||
private $revisionID;
|
||||
|
||||
|
@ -25,199 +25,35 @@ final class DifferentialInlineCommentEditController
|
|||
$this->revisionID = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
protected function createComment() {
|
||||
|
||||
$changeset = $request->getInt('changeset');
|
||||
$is_new = $request->getBool('is_new');
|
||||
$on_right = $request->getBool('on_right');
|
||||
$number = $request->getInt('number');
|
||||
$length = $request->getInt('length');
|
||||
$text = $request->getStr('text');
|
||||
$op = $request->getStr('op');
|
||||
$inline_id = $request->getInt('id');
|
||||
// Verify revision and changeset correspond to actual objects.
|
||||
$revision_id = $this->revisionID;
|
||||
$changeset_id = $this->getChangesetID();
|
||||
|
||||
$user = $request->getUser();
|
||||
|
||||
$submit_uri = '/differential/comment/inline/edit/'.$this->revisionID.'/';
|
||||
|
||||
$edit_dialog = new DifferentialInlineCommentEditView();
|
||||
$edit_dialog->setUser($user);
|
||||
$edit_dialog->setSubmitURI($submit_uri);
|
||||
|
||||
$edit_dialog->setOnRight($on_right);
|
||||
|
||||
switch ($op) {
|
||||
case 'delete':
|
||||
$inline = $this->loadInlineCommentForEditing($inline_id);
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$inline->delete();
|
||||
return $this->buildEmptyResponse();
|
||||
}
|
||||
|
||||
$dialog = new AphrontDialogView();
|
||||
$dialog->setUser($user);
|
||||
$dialog->setSubmitURI($submit_uri);
|
||||
|
||||
$dialog->setTitle('Really delete this comment?');
|
||||
$dialog->addHiddenInput('id', $inline_id);
|
||||
$dialog->addHiddenInput('op', 'delete');
|
||||
$dialog->appendChild('<p>Delete this inline comment?</p>');
|
||||
|
||||
$dialog->addCancelButton('#');
|
||||
$dialog->addSubmitButton();
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
case 'edit':
|
||||
$inline = $this->loadInlineCommentForEditing($inline_id);
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
if (strlen($text)) {
|
||||
$inline->setContent($text);
|
||||
$inline->setCache(null);
|
||||
$inline->save();
|
||||
return $this->buildRenderedCommentResponse(
|
||||
$inline,
|
||||
$on_right);
|
||||
} else {
|
||||
$inline->delete();
|
||||
return $this->buildEmptyResponse();
|
||||
}
|
||||
}
|
||||
|
||||
$edit_dialog->setTitle('Edit Inline Comment');
|
||||
|
||||
$edit_dialog->addHiddenInput('id', $inline_id);
|
||||
$edit_dialog->addHiddenInput('op', 'edit');
|
||||
|
||||
$edit_dialog->appendChild(
|
||||
$this->renderTextArea(
|
||||
nonempty($text, $inline->getContent())));
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($edit_dialog->render());
|
||||
case 'create':
|
||||
|
||||
if (!$request->isFormPost() || !strlen($text)) {
|
||||
return $this->buildEmptyResponse();
|
||||
}
|
||||
|
||||
// Verify revision and changeset correspond to actual objects.
|
||||
$revision_obj = id(new DifferentialRevision())->load($this->revisionID);
|
||||
$changeset_obj = id(new DifferentialChangeset())->load($changeset);
|
||||
if (!$revision_obj || !$changeset_obj) {
|
||||
throw new Exception("Invalid revision ID or changeset ID!");
|
||||
}
|
||||
|
||||
$inline = id(new DifferentialInlineComment())
|
||||
->setRevisionID($this->revisionID)
|
||||
->setChangesetID($changeset)
|
||||
->setCommentID(null)
|
||||
->setAuthorPHID($user->getPHID())
|
||||
->setLineNumber($number)
|
||||
->setLineLength($length)
|
||||
->setIsNewFile($is_new)
|
||||
->setContent($text)
|
||||
->save();
|
||||
|
||||
return $this->buildRenderedCommentResponse($inline, $on_right);
|
||||
|
||||
case 'reply':
|
||||
default:
|
||||
if ($op == 'reply') {
|
||||
$inline = $this->loadInlineComment($inline_id);
|
||||
// Override defaults.
|
||||
$changeset = $inline->getChangesetID();
|
||||
$is_new = $inline->getIsNewFile();
|
||||
$number = $inline->getLineNumber();
|
||||
$length = $inline->getLineLength();
|
||||
$edit_dialog->setTitle('Reply to Inline Comment');
|
||||
} else {
|
||||
$edit_dialog->setTitle('New Inline Comment');
|
||||
}
|
||||
|
||||
$edit_dialog->addHiddenInput('op', 'create');
|
||||
$edit_dialog->addHiddenInput('changeset', $changeset);
|
||||
$edit_dialog->addHiddenInput('is_new', $is_new);
|
||||
$edit_dialog->addHiddenInput('number', $number);
|
||||
$edit_dialog->addHiddenInput('length', $length);
|
||||
|
||||
$edit_dialog->appendChild($this->renderTextArea($text));
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($edit_dialog->render());
|
||||
if (!id(new DifferentialRevision())->load($revision_id)) {
|
||||
throw new Exception("Invalid revision ID!");
|
||||
}
|
||||
|
||||
if (!id(new DifferentialChangeset())->load($changeset_id)) {
|
||||
throw new Exception("Invalid changeset ID!");
|
||||
}
|
||||
|
||||
return id(new DifferentialInlineComment())
|
||||
->setRevisionID($revision_id)
|
||||
->setChangesetID($changeset_id);
|
||||
}
|
||||
|
||||
private function buildRenderedCommentResponse(
|
||||
DifferentialInlineComment $inline,
|
||||
$on_right) {
|
||||
protected function loadComment($id) {
|
||||
return id(new DifferentialInlineComment())->load($id);
|
||||
}
|
||||
|
||||
protected function loadCommentForEdit($id) {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
|
||||
|
||||
$phids = array($user->getPHID());
|
||||
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||
->loadHandles();
|
||||
|
||||
$view = new DifferentialInlineCommentView();
|
||||
$view->setInlineComment($inline);
|
||||
$view->setOnRight($on_right);
|
||||
$view->setBuildScaffolding(true);
|
||||
$view->setMarkupEngine($engine);
|
||||
$view->setHandles($handles);
|
||||
$view->setEditable(true);
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent(
|
||||
array(
|
||||
'inlineCommentID' => $inline->getID(),
|
||||
'markup' => $view->render(),
|
||||
));
|
||||
}
|
||||
|
||||
private function buildEmptyResponse() {
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent(
|
||||
array(
|
||||
'markup' => '',
|
||||
));
|
||||
}
|
||||
|
||||
private function renderTextArea($text) {
|
||||
return javelin_render_tag(
|
||||
'textarea',
|
||||
array(
|
||||
'class' => 'differential-inline-comment-edit-textarea',
|
||||
'sigil' => 'differential-inline-comment-edit-textarea',
|
||||
'name' => 'text',
|
||||
),
|
||||
phutil_escape_html($text));
|
||||
}
|
||||
|
||||
private function loadInlineComment($id) {
|
||||
$inline = null;
|
||||
|
||||
if ($id) {
|
||||
$inline = id(new DifferentialInlineComment())->load($id);
|
||||
}
|
||||
|
||||
if (!$inline) {
|
||||
throw new Exception("No such inline comment!");
|
||||
}
|
||||
|
||||
return $inline;
|
||||
}
|
||||
|
||||
private function loadInlineCommentForEditing($id) {
|
||||
$inline = $this->loadInlineComment($id);
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
if (!$this->canEditInlineComment($user, $inline, $this->revisionID)) {
|
||||
$inline = $this->loadComment($id);
|
||||
if (!$this->canEditInlineComment($user, $inline)) {
|
||||
throw new Exception("That comment is not editable!");
|
||||
}
|
||||
return $inline;
|
||||
|
@ -225,8 +61,7 @@ final class DifferentialInlineCommentEditController
|
|||
|
||||
private function canEditInlineComment(
|
||||
PhabricatorUser $user,
|
||||
DifferentialInlineComment $inline,
|
||||
$revision_id) {
|
||||
DifferentialInlineComment $inline) {
|
||||
|
||||
// Only the author may edit a comment.
|
||||
if ($inline->getAuthorPHID() != $user->getPHID()) {
|
||||
|
@ -239,7 +74,7 @@ final class DifferentialInlineCommentEditController
|
|||
}
|
||||
|
||||
// Inline must be attached to the active revision.
|
||||
if ($inline->getRevisionID() != $revision_id) {
|
||||
if ($inline->getRevisionID() != $this->revisionID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,20 +6,11 @@
|
|||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/ajax');
|
||||
phutil_require_module('phabricator', 'aphront/response/dialog');
|
||||
phutil_require_module('phabricator', 'applications/differential/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/changeset');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/inlinecomment');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/revision');
|
||||
phutil_require_module('phabricator', 'applications/differential/view/inlinecomment');
|
||||
phutil_require_module('phabricator', 'applications/differential/view/inlinecommentedit');
|
||||
phutil_require_module('phabricator', 'applications/markup/engine');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'infrastructure/javelin/markup');
|
||||
phutil_require_module('phabricator', 'view/dialog');
|
||||
phutil_require_module('phabricator', 'infrastructure/diff/controller');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
|
|
|
@ -237,10 +237,14 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
|||
|
||||
$changeset_view = new DifferentialChangesetListView();
|
||||
$changeset_view->setChangesets($visible_changesets);
|
||||
$changeset_view->setEditable(!$viewer_is_anonymous);
|
||||
|
||||
if (!$viewer_is_anonymous) {
|
||||
$changeset_view->setInlineCommentControllerURI(
|
||||
'/differential/comment/inline/edit/'.$revision->getID().'/');
|
||||
}
|
||||
|
||||
$changeset_view->setStandaloneViews(true);
|
||||
$changeset_view->setUser($user);
|
||||
$changeset_view->setRevision($revision);
|
||||
$changeset_view->setDiff($target);
|
||||
$changeset_view->setRenderingReferences($rendering_references);
|
||||
$changeset_view->setVsMap($vs_map);
|
||||
|
|
|
@ -250,7 +250,9 @@ final class DifferentialChangesetParser {
|
|||
}
|
||||
}
|
||||
|
||||
public function parseInlineComment(DifferentialInlineComment $comment) {
|
||||
public function parseInlineComment(
|
||||
PhabricatorInlineCommentInterface $comment) {
|
||||
|
||||
// Parse only comments which are actually visible.
|
||||
if ($this->isCommentVisibleOnRenderedDiff($comment)) {
|
||||
$this->comments[] = $comment;
|
||||
|
@ -1067,11 +1069,11 @@ final class DifferentialChangesetParser {
|
|||
* taking into consideration which halves of which changesets will actually
|
||||
* be shown.
|
||||
*
|
||||
* @param DifferentialInlineComment Comment to test for visibility.
|
||||
* @param PhabricatorInlineCommentInterface Comment to test for visibility.
|
||||
* @return bool True if the comment is visible on the rendered diff.
|
||||
*/
|
||||
private function isCommentVisibleOnRenderedDiff(
|
||||
DifferentialInlineComment $comment) {
|
||||
PhabricatorInlineCommentInterface $comment) {
|
||||
|
||||
$changeset_id = $comment->getChangesetID();
|
||||
$is_new = $comment->getIsNewFile();
|
||||
|
@ -1095,11 +1097,12 @@ final class DifferentialChangesetParser {
|
|||
* Note that the comment must appear somewhere on the rendered changeset, as
|
||||
* per isCommentVisibleOnRenderedDiff().
|
||||
*
|
||||
* @param DifferentialInlineComment Comment to test for display location.
|
||||
* @param PhabricatorInlineCommentInterface Comment to test for display
|
||||
* location.
|
||||
* @return bool True for right, false for left.
|
||||
*/
|
||||
private function isCommentOnRightSideWhenDisplayed(
|
||||
DifferentialInlineComment $comment) {
|
||||
PhabricatorInlineCommentInterface $comment) {
|
||||
|
||||
if (!$this->isCommentVisibleOnRenderedDiff($comment)) {
|
||||
throw new Exception("Comment is not visible on changeset!");
|
||||
|
@ -1444,12 +1447,13 @@ final class DifferentialChangesetParser {
|
|||
return implode('', $html);
|
||||
}
|
||||
|
||||
private function renderInlineComment(DifferentialInlineComment $comment) {
|
||||
private function renderInlineComment(
|
||||
PhabricatorInlineCommentInterface $comment) {
|
||||
|
||||
$user = $this->user;
|
||||
$edit = $user &&
|
||||
($comment->getAuthorPHID() == $user->getPHID()) &&
|
||||
(!$comment->getCommentID());
|
||||
($comment->isDraft());
|
||||
|
||||
$on_right = $this->isCommentOnRightSideWhenDisplayed($comment);
|
||||
|
||||
|
|
|
@ -16,18 +16,18 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class DifferentialInlineComment extends DifferentialDAO {
|
||||
final class DifferentialInlineComment
|
||||
extends DifferentialDAO
|
||||
implements PhabricatorInlineCommentInterface {
|
||||
|
||||
protected $revisionID;
|
||||
protected $commentID;
|
||||
protected $authorPHID;
|
||||
|
||||
protected $changesetID;
|
||||
protected $isNewFile;
|
||||
protected $commentID;
|
||||
|
||||
protected $authorPHID;
|
||||
protected $isNewFile;
|
||||
protected $lineNumber;
|
||||
protected $lineLength;
|
||||
|
||||
protected $content;
|
||||
protected $cache;
|
||||
|
||||
|
@ -42,11 +42,83 @@ final class DifferentialInlineComment extends DifferentialDAO {
|
|||
return $this->syntheticAuthor;
|
||||
}
|
||||
|
||||
public function isCompatible(DifferentialInlineComment $comment) {
|
||||
public function isCompatible(PhabricatorInlineCommentInterface $comment) {
|
||||
return
|
||||
$this->authorPHID === $comment->authorPHID &&
|
||||
$this->syntheticAuthor === $comment->syntheticAuthor &&
|
||||
$this->content === $comment->content;
|
||||
($this->getAuthorPHID() === $comment->getAuthorPHID()) &&
|
||||
($this->getSyntheticAuthor() === $comment->getSyntheticAuthor()) &&
|
||||
($this->getContent() === $comment->getContent());
|
||||
}
|
||||
|
||||
public function setContent($content) {
|
||||
$this->setCache(null);
|
||||
$this->writeField('content', $content);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContent() {
|
||||
return $this->readField('content');
|
||||
}
|
||||
|
||||
public function isDraft() {
|
||||
return !$this->getCommentID();
|
||||
}
|
||||
|
||||
// NOTE: We need to provide implementations so we conform to the shared
|
||||
// interface; these are all trivial and just explicit versions of the Lisk
|
||||
// defaults.
|
||||
|
||||
public function setChangesetID($id) {
|
||||
$this->writeField('changesetID', $id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChangesetID() {
|
||||
return $this->readField('changesetID');
|
||||
}
|
||||
|
||||
public function setIsNewFile($is_new) {
|
||||
$this->writeField('isNewFile', $is_new);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsNewFile() {
|
||||
return $this->readField('isNewFile');
|
||||
}
|
||||
|
||||
public function setLineNumber($number) {
|
||||
$this->writeField('lineNumber', $number);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLineNumber() {
|
||||
return $this->readField('lineNumber');
|
||||
}
|
||||
|
||||
public function setLineLength($length) {
|
||||
$this->writeField('lineLength', $length);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLineLength() {
|
||||
return $this->readField('lineLength');
|
||||
}
|
||||
|
||||
public function setCache($cache) {
|
||||
$this->writeField('cache', $cache);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCache() {
|
||||
return $this->readField('cache');
|
||||
}
|
||||
|
||||
public function setAuthorPHID($phid) {
|
||||
$this->writeField('authorPHID', $phid);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAuthorPHID() {
|
||||
return $this->readField('authorPHID');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/base');
|
||||
phutil_require_module('phabricator', 'infrastructure/diff/interface/inline');
|
||||
|
||||
|
||||
phutil_require_source('DifferentialInlineComment.php');
|
||||
|
|
|
@ -20,8 +20,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
|
||||
private $changesets = array();
|
||||
private $references = array();
|
||||
private $editable;
|
||||
private $revision;
|
||||
private $inlineURI;
|
||||
private $renderURI = '/differential/changeset/';
|
||||
private $whitespace;
|
||||
private $standaloneViews;
|
||||
|
@ -36,8 +35,8 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setEditable($editable) {
|
||||
$this->editable = $editable;
|
||||
public function setInlineCommentControllerURI($uri) {
|
||||
$this->inlineURI = $uri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -51,11 +50,6 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setRevision(DifferentialRevision $revision) {
|
||||
$this->revision = $revision;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRepository(PhabricatorRepository $repository) {
|
||||
$this->repository = $repository;
|
||||
return $this;
|
||||
|
@ -114,7 +108,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
foreach ($changesets as $key => $changeset) {
|
||||
$file = $changeset->getFilename();
|
||||
$class = 'differential-changeset';
|
||||
if (!$this->editable) {
|
||||
if (!$this->inlineURI) {
|
||||
$class .= ' differential-changeset-noneditable';
|
||||
}
|
||||
|
||||
|
@ -206,15 +200,13 @@ final class DifferentialChangesetListView extends AphrontView {
|
|||
|
||||
Javelin::initBehavior('differential-comment-jump', array());
|
||||
|
||||
if ($this->editable) {
|
||||
|
||||
if ($this->inlineURI) {
|
||||
$undo_templates = $this->renderUndoTemplates();
|
||||
|
||||
$revision = $this->revision;
|
||||
Javelin::initBehavior('differential-edit-inline-comments', array(
|
||||
'uri' => '/differential/comment/inline/edit/'.$revision->getID().'/',
|
||||
'undo_templates' => $undo_templates,
|
||||
'stage' => 'differential-review-stage',
|
||||
'uri' => $this->inlineURI,
|
||||
'undo_templates' => $undo_templates,
|
||||
'stage' => 'differential-review-stage',
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ final class DifferentialInlineCommentView extends AphrontView {
|
|||
private $editable;
|
||||
private $preview;
|
||||
|
||||
public function setInlineComment(DifferentialInlineComment $comment) {
|
||||
public function setInlineComment(PhabricatorInlineCommentInterface $comment) {
|
||||
$this->inlineComment = $comment;
|
||||
return $this;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ final class DifferentialInlineCommentView extends AphrontView {
|
|||
}
|
||||
|
||||
$is_draft = false;
|
||||
if (!$inline->getCommentID() && !$is_synthetic) {
|
||||
if ($inline->isDraft() && !$is_synthetic) {
|
||||
$links[] = 'Not Submitted Yet';
|
||||
$is_draft = true;
|
||||
}
|
||||
|
|
|
@ -199,12 +199,26 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
$references[$key] = $reference;
|
||||
}
|
||||
|
||||
// TOOD: Some parts of the views still rely on properties of the
|
||||
// DifferentialChangeset. Make the objects ephemeral to make sure we don't
|
||||
// accidentally save them, and then set their ID to the appropriate ID for
|
||||
// this application (the path IDs).
|
||||
$pquery = new DiffusionPathIDQuery(mpull($changesets, 'getFilename'));
|
||||
$path_ids = $pquery->loadPathIDs();
|
||||
foreach ($changesets as $changeset) {
|
||||
$changeset->makeEphemeral();
|
||||
$changeset->setID($path_ids[$changeset->getFilename()]);
|
||||
}
|
||||
|
||||
$change_list = new DifferentialChangesetListView();
|
||||
$change_list->setChangesets($changesets);
|
||||
$change_list->setRenderingReferences($references);
|
||||
$change_list->setRenderURI('/diffusion/'.$callsign.'/diff/');
|
||||
$change_list->setUser($user);
|
||||
|
||||
$change_list->setInlineCommentControllerURI(
|
||||
'/diffusion/inline/'.phutil_escape_uri($commit->getPHID()).'/');
|
||||
|
||||
// TODO: This is pretty awkward, unify the CSS between Diffusion and
|
||||
// Differential better.
|
||||
require_celerity_resource('differential-core-view-css');
|
||||
|
|
|
@ -18,6 +18,7 @@ phutil_require_module('phabricator', 'applications/diffusion/controller/base');
|
|||
phutil_require_module('phabricator', 'applications/diffusion/data/pathchange');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/contains/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/pathchange/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/pathid/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/commentlist');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/commitchangetable');
|
||||
phutil_require_module('phabricator', 'applications/draft/storage/draft');
|
||||
|
|
|
@ -33,6 +33,7 @@ final class DiffusionDiffController extends DiffusionController {
|
|||
public function processRequest() {
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$diff_query = DiffusionDiffQuery::newFromDiffusionRequest($drequest);
|
||||
$changeset = $diff_query->loadChangeset();
|
||||
|
@ -44,9 +45,34 @@ final class DiffusionDiffController extends DiffusionController {
|
|||
$parser = new DifferentialChangesetParser();
|
||||
$parser->setChangeset($changeset);
|
||||
$parser->setRenderingReference($diff_query->getRenderingReference());
|
||||
|
||||
$pquery = new DiffusionPathIDQuery(array($changeset->getFilename()));
|
||||
$ids = $pquery->loadPathIDs();
|
||||
$path_id = $ids[$changeset->getFilename()];
|
||||
|
||||
$parser->setLeftSideCommentMapping($path_id, false);
|
||||
$parser->setRightSideCommentMapping($path_id, true);
|
||||
|
||||
$parser->setWhitespaceMode(
|
||||
DifferentialChangesetParser::WHITESPACE_SHOW_ALL);
|
||||
|
||||
$inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere(
|
||||
'commitPHID = %s AND pathID = %d AND
|
||||
(authorPHID = %s OR auditCommentID IS NOT NULL)',
|
||||
$drequest->loadCommit()->getPHID(),
|
||||
$path_id,
|
||||
$user->getPHID());
|
||||
|
||||
if ($inlines) {
|
||||
foreach ($inlines as $inline) {
|
||||
$parser->parseInlineComment($inline);
|
||||
}
|
||||
|
||||
$phids = mpull($inlines, 'getAuthorPHID');
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
||||
$parser->setHandles($handles);
|
||||
}
|
||||
|
||||
$spec = $request->getStr('range');
|
||||
list($range_s, $range_e, $mask) =
|
||||
DifferentialChangesetParser::parseRangeSpecification($spec);
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'applications/audit/storage/inlinecommment');
|
||||
phutil_require_module('phabricator', 'applications/differential/parser/changeset');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/diff/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/pathid/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/request/base');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'infrastructure/diff/response');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class DiffusionInlineCommentController
|
||||
extends PhabricatorInlineCommentController {
|
||||
|
||||
private $commitPHID;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->commitPHID = $data['phid'];
|
||||
}
|
||||
|
||||
protected function createComment() {
|
||||
|
||||
// Verify commit and path correspond to actual objects.
|
||||
$commit_phid = $this->commitPHID;
|
||||
$path_id = $this->getChangesetID();
|
||||
|
||||
$commit = id(new PhabricatorRepositoryCommit())->loadOneWhere(
|
||||
'phid = %s',
|
||||
$commit_phid);
|
||||
if (!$commit) {
|
||||
throw new Exception("Invalid commit ID!");
|
||||
}
|
||||
|
||||
// TODO: Write a real PathQuery object?
|
||||
|
||||
$path = queryfx_one(
|
||||
id(new PhabricatorRepository())->establishConnection('r'),
|
||||
'SELECT path FROM %T WHERE id = %d',
|
||||
PhabricatorRepository::TABLE_PATH,
|
||||
$path_id);
|
||||
|
||||
if (!$path) {
|
||||
throw new Exception("Invalid path ID!");
|
||||
}
|
||||
|
||||
return id(new PhabricatorAuditInlineComment())
|
||||
->setCommitPHID($commit_phid)
|
||||
->setPathID($path_id);
|
||||
}
|
||||
|
||||
protected function loadComment($id) {
|
||||
return id(new PhabricatorAuditInlineComment())->load($id);
|
||||
}
|
||||
|
||||
protected function loadCommentForEdit($id) {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$inline = $this->loadComment($id);
|
||||
if (!$this->canEditInlineComment($user, $inline)) {
|
||||
throw new Exception("That comment is not editable!");
|
||||
}
|
||||
return $inline;
|
||||
}
|
||||
|
||||
private function canEditInlineComment(
|
||||
PhabricatorUser $user,
|
||||
PhabricatorAuditInlineComment $inline) {
|
||||
|
||||
// Only the author may edit a comment.
|
||||
if ($inline->getAuthorPHID() != $user->getPHID()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Saved comments may not be edited.
|
||||
if ($inline->getAuditCommentID()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Inline must be attached to the active revision.
|
||||
if ($inline->getCommitPHID() != $this->commitPHID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
18
src/applications/diffusion/controller/inline/__init__.php
Normal file
18
src/applications/diffusion/controller/inline/__init__.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/audit/storage/inlinecommment');
|
||||
phutil_require_module('phabricator', 'applications/repository/storage/commit');
|
||||
phutil_require_module('phabricator', 'applications/repository/storage/repository');
|
||||
phutil_require_module('phabricator', 'infrastructure/diff/controller');
|
||||
phutil_require_module('phabricator', 'storage/queryfx');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('DiffusionInlineCommentController.php');
|
|
@ -0,0 +1,257 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
abstract class PhabricatorInlineCommentController
|
||||
extends PhabricatorController {
|
||||
|
||||
abstract protected function createComment();
|
||||
abstract protected function loadComment($id);
|
||||
abstract protected function loadCommentForEdit($id);
|
||||
|
||||
private $changesetID;
|
||||
private $isNewFile;
|
||||
private $isOnRight;
|
||||
private $lineNumber;
|
||||
private $lineLength;
|
||||
private $commentText;
|
||||
private $operation;
|
||||
private $commentID;
|
||||
|
||||
public function getCommentID() {
|
||||
return $this->commentID;
|
||||
}
|
||||
|
||||
public function getOperation() {
|
||||
return $this->operation;
|
||||
}
|
||||
|
||||
public function getCommentText() {
|
||||
return $this->commentText;
|
||||
}
|
||||
|
||||
public function getLineLength() {
|
||||
return $this->lineLength;
|
||||
}
|
||||
|
||||
public function getLineNumber() {
|
||||
return $this->lineNumber;
|
||||
}
|
||||
|
||||
public function getIsOnRight() {
|
||||
return $this->isOnRight;
|
||||
}
|
||||
|
||||
public function getChangesetID() {
|
||||
return $this->changesetID;
|
||||
}
|
||||
|
||||
public function getIsNewFile() {
|
||||
return $this->isNewFile;
|
||||
}
|
||||
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$this->readRequestParameters();
|
||||
|
||||
switch ($this->getOperation()) {
|
||||
case 'delete':
|
||||
$inline = $this->loadCommentForEdit($this->getCommentID());
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$inline->delete();
|
||||
return $this->buildEmptyResponse();
|
||||
}
|
||||
|
||||
$dialog = new AphrontDialogView();
|
||||
$dialog->setUser($user);
|
||||
$dialog->setSubmitURI($request->getRequestURI());
|
||||
|
||||
$dialog->setTitle('Really delete this comment?');
|
||||
$dialog->addHiddenInput('id', $this->getCommentID());
|
||||
$dialog->addHiddenInput('op', 'delete');
|
||||
$dialog->appendChild('<p>Delete this inline comment?</p>');
|
||||
|
||||
$dialog->addCancelButton('#');
|
||||
$dialog->addSubmitButton('Delete');
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
case 'edit':
|
||||
$inline = $this->loadCommentForEdit($this->getCommentID());
|
||||
|
||||
$text = $this->getCommentText();
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
if (strlen($text)) {
|
||||
$inline->setContent($text);
|
||||
$inline->save();
|
||||
return $this->buildRenderedCommentResponse(
|
||||
$inline,
|
||||
$this->getIsOnRight());
|
||||
} else {
|
||||
$inline->delete();
|
||||
return $this->buildEmptyResponse();
|
||||
}
|
||||
}
|
||||
|
||||
$edit_dialog = $this->buildEditDialog();
|
||||
$edit_dialog->setTitle('Edit Inline Comment');
|
||||
|
||||
$edit_dialog->addHiddenInput('id', $this->getCommentID());
|
||||
$edit_dialog->addHiddenInput('op', 'edit');
|
||||
|
||||
$edit_dialog->appendChild(
|
||||
$this->renderTextArea(
|
||||
nonempty($text, $inline->getContent())));
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($edit_dialog->render());
|
||||
case 'create':
|
||||
|
||||
$text = $this->getCommentText();
|
||||
|
||||
if (!$request->isFormPost() || !strlen($text)) {
|
||||
return $this->buildEmptyResponse();
|
||||
}
|
||||
|
||||
$inline = $this->createComment()
|
||||
->setChangesetID($this->getChangesetID())
|
||||
->setAuthorPHID($user->getPHID())
|
||||
->setLineNumber($this->getLineNumber())
|
||||
->setLineLength($this->getLineLength())
|
||||
->setIsNewFile($this->getIsNewFile())
|
||||
->setContent($text)
|
||||
->save();
|
||||
|
||||
return $this->buildRenderedCommentResponse(
|
||||
$inline,
|
||||
$this->getIsOnRight());
|
||||
case 'reply':
|
||||
default:
|
||||
$edit_dialog = $this->buildEditDialog();
|
||||
|
||||
if ($this->getOperation() == 'reply') {
|
||||
$inline = $this->loadComment($this->getCommentID());
|
||||
|
||||
$edit_dialog->setTitle('Reply to Inline Comment');
|
||||
$changeset = $inline->getChangesetID();
|
||||
$is_new = $inline->getIsNewFile();
|
||||
$number = $inline->getLineNumber();
|
||||
$length = $inline->getLineLength();
|
||||
} else {
|
||||
$edit_dialog->setTitle('New Inline Comment');
|
||||
$changeset = $this->getChangesetID();
|
||||
$is_new = $this->getIsNewFile();
|
||||
$number = $this->getLineNumber();
|
||||
$length = $this->getLineLength();
|
||||
}
|
||||
|
||||
$edit_dialog->addHiddenInput('op', 'create');
|
||||
$edit_dialog->addHiddenInput('changeset', $changeset);
|
||||
$edit_dialog->addHiddenInput('is_new', $is_new);
|
||||
$edit_dialog->addHiddenInput('number', $number);
|
||||
$edit_dialog->addHiddenInput('length', $length);
|
||||
|
||||
$text_area = $this->renderTextArea($this->getCommentText());
|
||||
$edit_dialog->appendChild($text_area);
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($edit_dialog->render());
|
||||
}
|
||||
}
|
||||
|
||||
private function readRequestParameters() {
|
||||
$request = $this->getRequest();
|
||||
|
||||
// NOTE: This isn't necessarily a DifferentialChangeset ID, just an
|
||||
// application identifier for the changeset. In Diffusion, it's a Path ID.
|
||||
$this->changesetID = $request->getInt('changeset');
|
||||
|
||||
$this->isNewFile = $request->getBool('is_new');
|
||||
$this->isOnRight = $request->getBool('on_right');
|
||||
$this->lineNumber = $request->getInt('number');
|
||||
$this->lineLength = $request->getInt('length');
|
||||
$this->commentText = $request->getStr('text');
|
||||
$this->commentID = $request->getInt('id');
|
||||
$this->operation = $request->getStr('op');
|
||||
}
|
||||
|
||||
private function buildEditDialog() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$edit_dialog = new DifferentialInlineCommentEditView();
|
||||
$edit_dialog->setUser($user);
|
||||
$edit_dialog->setSubmitURI($request->getRequestURI());
|
||||
$edit_dialog->setOnRight($this->getIsOnRight());
|
||||
|
||||
return $edit_dialog;
|
||||
}
|
||||
|
||||
private function buildEmptyResponse() {
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent(
|
||||
array(
|
||||
'markup' => '',
|
||||
));
|
||||
}
|
||||
|
||||
private function buildRenderedCommentResponse(
|
||||
PhabricatorInlineCommentInterface $inline,
|
||||
$on_right) {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
|
||||
|
||||
$phids = array($user->getPHID());
|
||||
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||
->loadHandles();
|
||||
|
||||
$view = new DifferentialInlineCommentView();
|
||||
$view->setInlineComment($inline);
|
||||
$view->setOnRight($on_right);
|
||||
$view->setBuildScaffolding(true);
|
||||
$view->setMarkupEngine($engine);
|
||||
$view->setHandles($handles);
|
||||
$view->setEditable(true);
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent(
|
||||
array(
|
||||
'inlineCommentID' => $inline->getID(),
|
||||
'markup' => $view->render(),
|
||||
));
|
||||
}
|
||||
|
||||
private function renderTextArea($text) {
|
||||
return javelin_render_tag(
|
||||
'textarea',
|
||||
array(
|
||||
'class' => 'differential-inline-comment-edit-textarea',
|
||||
'sigil' => 'differential-inline-comment-edit-textarea',
|
||||
'name' => 'text',
|
||||
),
|
||||
phutil_escape_html($text));
|
||||
}
|
||||
|
||||
}
|
23
src/infrastructure/diff/controller/__init__.php
Normal file
23
src/infrastructure/diff/controller/__init__.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/ajax');
|
||||
phutil_require_module('phabricator', 'aphront/response/dialog');
|
||||
phutil_require_module('phabricator', 'applications/base/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/differential/view/inlinecomment');
|
||||
phutil_require_module('phabricator', 'applications/differential/view/inlinecommentedit');
|
||||
phutil_require_module('phabricator', 'applications/markup/engine');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'infrastructure/javelin/markup');
|
||||
phutil_require_module('phabricator', 'view/dialog');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorInlineCommentController.php');
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Shared interface used by Differential and Diffusion inline comments.
|
||||
*/
|
||||
interface PhabricatorInlineCommentInterface {
|
||||
|
||||
public function setChangesetID($id);
|
||||
public function getChangesetID();
|
||||
|
||||
public function setIsNewFile($is_new);
|
||||
public function getIsNewFile();
|
||||
|
||||
public function setLineNumber($number);
|
||||
public function getLineNumber();
|
||||
|
||||
public function setLineLength($length);
|
||||
public function getLineLength();
|
||||
|
||||
public function setContent($content);
|
||||
public function getContent();
|
||||
|
||||
public function setCache($cache);
|
||||
public function getCache();
|
||||
|
||||
public function setAuthorPHID($phid);
|
||||
public function getAuthorPHID();
|
||||
|
||||
public function setSyntheticAuthor($synthetic_author);
|
||||
public function getSyntheticAuthor();
|
||||
|
||||
public function isCompatible(PhabricatorInlineCommentInterface $inline);
|
||||
public function isDraft();
|
||||
|
||||
public function save();
|
||||
public function delete();
|
||||
|
||||
}
|
10
src/infrastructure/diff/interface/inline/__init__.php
Normal file
10
src/infrastructure/diff/interface/inline/__init__.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorInlineCommentInterface.php');
|
Loading…
Reference in a new issue