Add project to changeBaseURL calls
Gerrit.RESTClientBehavior provides a changeBaseURL method that is
currently only used to construct download links. These links need to
incorporate the project of the change into their hrefs. Since all call
sites have a change detail object in scope, we can just pass the project
name directly to changeBaseURL.
Change-Id: I899c1e486f20b0097d1aa9617d9944909a3a528f
(cherry picked from commit 90b4dc4803
)
This commit is contained in:

committed by
David Pursehouse

parent
6cd6fad3e1
commit
537b7336fe
@@ -110,8 +110,9 @@ limitations under the License.
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
changeBaseURL(changeNum, patchNum) {
|
||||
let v = this.getBaseUrl() + '/changes/' + changeNum;
|
||||
changeBaseURL(project, changeNum, patchNum) {
|
||||
let v = this.getBaseUrl() + '/changes/' +
|
||||
encodeURIComponent(project) + '~' + changeNum;
|
||||
if (patchNum) {
|
||||
v += '/revisions/' + patchNum;
|
||||
}
|
||||
|
@@ -68,8 +68,8 @@ limitations under the License.
|
||||
|
||||
test('changeBaseURL', () => {
|
||||
assert.deepEqual(
|
||||
element.changeBaseURL('1', '1'),
|
||||
'/r/changes/1/revisions/1'
|
||||
element.changeBaseURL('test/project', '1', '2'),
|
||||
'/r/changes/test%2Fproject~1/revisions/2'
|
||||
);
|
||||
});
|
||||
|
||||
|
@@ -115,8 +115,8 @@
|
||||
* @return {string} Not sure why there was a mismatch
|
||||
*/
|
||||
_computeDownloadLink(change, patchNum, opt_zip) {
|
||||
return this.changeBaseURL(change._number, patchNum) + '/patch?' +
|
||||
(opt_zip ? 'zip' : 'download');
|
||||
return this.changeBaseURL(change.project, change._number, patchNum) +
|
||||
'/patch?' + (opt_zip ? 'zip' : 'download');
|
||||
},
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
},
|
||||
|
||||
_computeArchiveDownloadLink(change, patchNum, format) {
|
||||
return this.changeBaseURL(change._number, patchNum) +
|
||||
return this.changeBaseURL(change.project, change._number, patchNum) +
|
||||
'/archive?format=' + format;
|
||||
},
|
||||
|
||||
|
@@ -172,8 +172,8 @@ limitations under the License.
|
||||
|
||||
test('computed fields', () => {
|
||||
assert.equal(element._computeArchiveDownloadLink(
|
||||
{_number: 123}, 2, 'tgz'),
|
||||
'/changes/123/revisions/2/archive?format=tgz');
|
||||
{project: 'test/project', _number: 123}, 2, 'tgz'),
|
||||
'/changes/test%2Fproject~123/revisions/2/archive?format=tgz');
|
||||
});
|
||||
|
||||
test('close event', done => {
|
||||
|
@@ -269,7 +269,7 @@ limitations under the License.
|
||||
<a
|
||||
class="downloadLink"
|
||||
download
|
||||
href$="[[_computeDownloadLink(_changeNum, _patchRange, _path)]]">
|
||||
href$="[[_computeDownloadLink(_change.project, _changeNum, _patchRange, _path)]]">
|
||||
Download
|
||||
</a>
|
||||
</span>
|
||||
|
@@ -883,8 +883,8 @@
|
||||
history.replaceState(null, '', url);
|
||||
},
|
||||
|
||||
_computeDownloadLink(changeNum, patchRange, path) {
|
||||
let url = this.changeBaseURL(changeNum, patchRange.patchNum);
|
||||
_computeDownloadLink(project, changeNum, patchRange, path) {
|
||||
let url = this.changeBaseURL(project, changeNum, patchRange.patchNum);
|
||||
url += '/patch?zip&path=' + encodeURIComponent(path);
|
||||
return url;
|
||||
},
|
||||
|
@@ -556,6 +556,7 @@ limitations under the License.
|
||||
});
|
||||
|
||||
test('download link', () => {
|
||||
element._change = {project: 'test'},
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: PARENT,
|
||||
@@ -566,7 +567,7 @@ limitations under the License.
|
||||
flushAsynchronousOperations();
|
||||
const link = element.$$('.downloadLink');
|
||||
assert.equal(link.getAttribute('href'),
|
||||
'/changes/42/revisions/10/patch?zip&path=glados.txt');
|
||||
'/changes/test~42/revisions/10/patch?zip&path=glados.txt');
|
||||
assert.isTrue(link.hasAttribute('download'));
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user