Disallow commenting on an edit base
Bug: Issue 8289 Change-Id: I934f8b4ac2a6f1993ddb1ad55c3c05f9fd0182f9
This commit is contained in:
@@ -33,6 +33,7 @@ limitations under the License.
|
||||
/** @polymerBehavior this */
|
||||
Gerrit.PatchSetBehavior = {
|
||||
EDIT_NAME: 'edit',
|
||||
PARENT_NAME: 'PARENT',
|
||||
|
||||
/**
|
||||
* As patchNum can be either a string (e.g. 'edit', 'PARENT') OR a number,
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
'use strict';
|
||||
|
||||
const ERR_COMMENT_ON_EDIT = 'You cannot comment on an edit.';
|
||||
const ERR_COMMENT_ON_EDIT_BASE = 'You cannot comment on the base patch set ' +
|
||||
'of an edit.';
|
||||
const ERR_INVALID_LINE = 'Invalid line number: ';
|
||||
const MSG_EMPTY_BLAME = 'No blame information for this diff.';
|
||||
|
||||
@@ -358,9 +360,16 @@
|
||||
this.patchRange.basePatchNum :
|
||||
this.patchRange.patchNum;
|
||||
|
||||
if (this.patchNumEquals(patchNum, this.EDIT_NAME)) {
|
||||
const isEdit = this.patchNumEquals(patchNum, this.EDIT_NAME);
|
||||
const isEditBase = this.patchNumEquals(patchNum, this.PARENT_NAME) &&
|
||||
this.patchNumEquals(this.patchRange.patchNum, this.EDIT_NAME);
|
||||
|
||||
if (isEdit) {
|
||||
this.fire('show-alert', {message: ERR_COMMENT_ON_EDIT});
|
||||
return false;
|
||||
} else if (isEditBase) {
|
||||
this.fire('show-alert', {message: ERR_COMMENT_ON_EDIT_BASE});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -838,6 +838,7 @@ limitations under the License.
|
||||
getPreferences() {
|
||||
return Promise.resolve({time_format: 'HHMM_12'});
|
||||
},
|
||||
getAccountCapabilities() { return Promise.resolve(); },
|
||||
});
|
||||
element = fixture('basic');
|
||||
element.patchRange = {};
|
||||
@@ -881,6 +882,24 @@ limitations under the License.
|
||||
});
|
||||
});
|
||||
|
||||
test('addDraftAtLine on an edit base', done => {
|
||||
element.patchRange.patchNum = element.EDIT_NAME;
|
||||
element.patchRange.basePatchNum = element.PARENT_NAME;
|
||||
sandbox.stub(element, '_selectLine');
|
||||
sandbox.stub(element, '_createComment');
|
||||
const loggedInErrorSpy = sandbox.spy();
|
||||
const alertSpy = sandbox.spy();
|
||||
element.addEventListener('show-auth-required', loggedInErrorSpy);
|
||||
element.addEventListener('show-alert', alertSpy);
|
||||
element.addDraftAtLine(fakeLineEl);
|
||||
flush(() => {
|
||||
assert.isFalse(loggedInErrorSpy.called);
|
||||
assert.isTrue(alertSpy.called);
|
||||
assert.isFalse(element._createComment.called);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite('change in preferences', () => {
|
||||
setup(() => {
|
||||
element._diff = {
|
||||
|
||||
Reference in New Issue
Block a user