2011-02-02 01:42:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
Resolve great internal confusion about left vs right inline comments
Summary:
This code was just all kinds of wrong, but got all the common cases anyone cares
about correct.
- In edit-inline-comments.js, if isOnRight() is true, use data.right, not
data.left (derp).
- Set data.left correctly, not to the same value as data.right (derp derp).
- Set "isNewFile" based on $is_new, not $on_right (derp derp derp).
Test Plan:
- Added JS debugging code to print "OLD" vs "NEW" and "LEFT" vs "RIGHT".
Clicked the left and right sides of diff-vs-base and diff-vs-diff diffs,
verified output was accurate in all cases.
- Added comments to the left-display-side of a diff-of-diffs, saved them, they
showed up where I put them.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: aran, epriestley
Maniphest Tasks: T543
Differential Revision: https://secure.phabricator.com/D1567
2012-02-04 00:26:47 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-02-02 01:42:36 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DifferentialInlineCommentEditController extends DifferentialController {
|
|
|
|
|
|
|
|
private $revisionID;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->revisionID = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$changeset = $request->getInt('changeset');
|
Fix "reply" link in Differential
Summary:
Fixes the issue caused by rPa0af5b66437719dba6136579c051982ab275e6a0. Prior to
that patch, isCommentInNewFile() returned $comment->getIsNewFile(). While this
was often the wrong value, it came from the database and was the integer 1 if
true.
After the patch, the function returns 'true' as a boolean, which is passed to JS
and then back to PHP, interpreted as an integer, and evaluates to 0.
To avoid this issue in general, provide an isBool() method on AphrontRequest
which interprets this correctly.
I will also revert the revert of rPa0af5b66437719dba6136579c051982ab275e6a0 when
I land this.
Test Plan:
Clicked "reply" on the right hand side of a diff, got a right-hand-side inline
comment.
Reviewed By: rm
Reviewers: tuomaspelkonen, jungejason, aran, rm
CC: simpkins, aran, epriestley, rm
Differential Revision: 250
2011-05-07 19:42:40 +02:00
|
|
|
$is_new = $request->getBool('is_new');
|
|
|
|
$on_right = $request->getBool('on_right');
|
2011-02-02 01:42:36 +01:00
|
|
|
$number = $request->getInt('number');
|
|
|
|
$length = $request->getInt('length');
|
|
|
|
$text = $request->getStr('text');
|
|
|
|
$op = $request->getStr('op');
|
2011-02-02 19:10:25 +01:00
|
|
|
$inline_id = $request->getInt('id');
|
2011-02-02 01:42:36 +01:00
|
|
|
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$submit_uri = '/differential/comment/inline/edit/'.$this->revisionID.'/';
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
$edit_dialog = new AphrontDialogView();
|
|
|
|
$edit_dialog->setUser($user);
|
|
|
|
$edit_dialog->setSubmitURI($submit_uri);
|
|
|
|
|
|
|
|
$edit_dialog->addHiddenInput('on_right', $on_right);
|
|
|
|
|
|
|
|
$edit_dialog->addSubmitButton();
|
|
|
|
$edit_dialog->addCancelButton('#');
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
switch ($op) {
|
|
|
|
case 'delete':
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
$inline = $this->loadInlineCommentForEditing($inline_id);
|
2011-02-02 19:10:25 +01:00
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
if ($request->isFormPost()) {
|
2011-02-02 19:10:25 +01:00
|
|
|
$inline->delete();
|
2011-04-20 10:58:05 +02:00
|
|
|
return $this->buildEmptyResponse();
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
$edit_dialog->setTitle('Really delete this comment?');
|
|
|
|
$edit_dialog->addHiddenInput('id', $inline_id);
|
|
|
|
$edit_dialog->addHiddenInput('op', 'delete');
|
|
|
|
$edit_dialog->appendChild(
|
|
|
|
'<p>Delete this inline comment?</p>');
|
2011-02-02 01:42:36 +01:00
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
return id(new AphrontDialogResponse())->setDialog($edit_dialog);
|
2011-02-02 01:42:36 +01:00
|
|
|
case 'edit':
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
$inline = $this->loadInlineCommentForEditing($inline_id);
|
2011-02-02 19:10:25 +01:00
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
if (strlen($text)) {
|
|
|
|
$inline->setContent($text);
|
2011-02-03 04:38:43 +01:00
|
|
|
$inline->setCache(null);
|
2011-02-02 19:10:25 +01:00
|
|
|
$inline->save();
|
|
|
|
return $this->buildRenderedCommentResponse(
|
|
|
|
$inline,
|
|
|
|
$on_right);
|
|
|
|
} else {
|
|
|
|
$inline->delete();
|
2011-04-20 10:58:05 +02:00
|
|
|
return $this->buildEmptyResponse();
|
2011-02-02 19:10:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$edit_dialog->setTitle('Edit Inline Comment');
|
2011-02-02 01:42:36 +01:00
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
$edit_dialog->addHiddenInput('id', $inline_id);
|
|
|
|
$edit_dialog->addHiddenInput('op', 'edit');
|
|
|
|
|
|
|
|
$edit_dialog->appendChild(
|
|
|
|
$this->renderTextArea(
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
nonempty($text, $inline->getContent())));
|
2011-02-02 19:10:25 +01:00
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($edit_dialog);
|
2011-02-02 01:42:36 +01:00
|
|
|
case 'create':
|
|
|
|
|
|
|
|
if (!$request->isFormPost() || !strlen($text)) {
|
2011-04-20 10:58:05 +02:00
|
|
|
return $this->buildEmptyResponse();
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
|
|
|
|
2011-05-29 21:10:36 +02:00
|
|
|
// 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!");
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
$inline = id(new DifferentialInlineComment())
|
|
|
|
->setRevisionID($this->revisionID)
|
|
|
|
->setChangesetID($changeset)
|
|
|
|
->setCommentID(null)
|
|
|
|
->setAuthorPHID($user->getPHID())
|
|
|
|
->setLineNumber($number)
|
|
|
|
->setLineLength($length)
|
Resolve great internal confusion about left vs right inline comments
Summary:
This code was just all kinds of wrong, but got all the common cases anyone cares
about correct.
- In edit-inline-comments.js, if isOnRight() is true, use data.right, not
data.left (derp).
- Set data.left correctly, not to the same value as data.right (derp derp).
- Set "isNewFile" based on $is_new, not $on_right (derp derp derp).
Test Plan:
- Added JS debugging code to print "OLD" vs "NEW" and "LEFT" vs "RIGHT".
Clicked the left and right sides of diff-vs-base and diff-vs-diff diffs,
verified output was accurate in all cases.
- Added comments to the left-display-side of a diff-of-diffs, saved them, they
showed up where I put them.
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: aran, epriestley
Maniphest Tasks: T543
Differential Revision: https://secure.phabricator.com/D1567
2012-02-04 00:26:47 +01:00
|
|
|
->setIsNewFile($is_new)
|
2011-02-02 01:42:36 +01:00
|
|
|
->setContent($text)
|
|
|
|
->save();
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
return $this->buildRenderedCommentResponse($inline, $on_right);
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
|
|
|
|
case 'reply':
|
2011-02-02 01:42:36 +01:00
|
|
|
default:
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
2011-02-02 19:10:25 +01:00
|
|
|
|
|
|
|
$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);
|
|
|
|
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
$edit_dialog->appendChild($this->renderTextArea($text));
|
2011-02-02 19:10:25 +01:00
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($edit_dialog);
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
private function buildRenderedCommentResponse(
|
|
|
|
DifferentialInlineComment $inline,
|
|
|
|
$on_right) {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
Generalize the markup engine factory
Summary:
This thing services every app but it lives inside Differential right now. Pull
it out, and separate the factory interfaces per-application.
This will let us accommodate changes we need to make for Phriction to support
wiki linking.
Test Plan: Tested remarkup in differential, diffusion, maniphest, people,
slowvote.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran
CC: aran, hsb
Differential Revision: 646
2011-07-12 00:58:32 +02:00
|
|
|
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
|
2011-02-02 19:10:25 +01:00
|
|
|
|
|
|
|
$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(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-04-20 10:58:05 +02:00
|
|
|
private function buildEmptyResponse() {
|
2011-02-02 19:10:25 +01:00
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(
|
|
|
|
array(
|
|
|
|
'markup' => '',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderTextArea($text) {
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
return javelin_render_tag(
|
2011-02-02 19:10:25 +01:00
|
|
|
'textarea',
|
|
|
|
array(
|
2011-02-05 02:53:14 +01:00
|
|
|
'class' => 'differential-inline-comment-edit-textarea',
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
'sigil' => 'differential-inline-comment-edit-textarea',
|
2011-02-02 19:10:25 +01:00
|
|
|
'name' => 'text',
|
|
|
|
),
|
2011-04-30 05:18:12 +02:00
|
|
|
phutil_escape_html($text));
|
2011-02-02 19:10:25 +01:00
|
|
|
}
|
|
|
|
|
Add "Undo" for editing Differential inline comments
Summary:
When a user hits 'cancel' on a 'new', 'edit', or 'reply' operation, add a little
"Changes discarded. __Undo__" insert so they can get their change back. No undo
for delete since there's an explicit prompt. Once this lands we can make
'escape' work again to close dialogs.
This change started feeling really good when I was merging all the duplicate
code and making things more consistent, but by the time I started writing client
rendering it felt gross. I'm not really thrilled with it but I guess it's a step
forward? The feature seems pretty OK in practice. Let me know how much barfing
this causes and I can try to remedy the most acute concerns.
This also fixes a bug where replies always (?) appear on the 'new' side of the
diff (I think?).
Test Plan:
Applied 'new', 'edit', 'delete' and 'reply' operations, pressed 'cancel' and
'okay' in each case, with and without changing text where relevant. All
behaviors seem to conform with expectations, except that canceling out of 'edit'
without changing the text gives you an option to undo when it shouldn't really.
There's no super easy way to get at the original text right now.
Reviewed By: aran
Reviewers: aran, jungejason, tuomaspelkonen
CC: simpkins, aran, epriestley
Differential Revision: 406
2011-06-08 01:11:10 +02:00
|
|
|
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)) {
|
|
|
|
throw new Exception("That comment is not editable!");
|
|
|
|
}
|
|
|
|
return $inline;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function canEditInlineComment(
|
|
|
|
PhabricatorUser $user,
|
|
|
|
DifferentialInlineComment $inline,
|
|
|
|
$revision_id) {
|
|
|
|
|
|
|
|
// Only the author may edit a comment.
|
|
|
|
if ($inline->getAuthorPHID() != $user->getPHID()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Saved comments may not be edited.
|
|
|
|
if ($inline->getCommentID()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inline must be attached to the active revision.
|
|
|
|
if ($inline->getRevisionID() != $revision_id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|