Make context.call() call plugin actions correctly
In PolyGerrit, context.call() should will now use same context URL as in GWT UI. For change context: /changes/project~changeid/pluginname~action For revision context: /changes/project~changeid/revisions/revisionid/pluginname~action Feature: Issue 7685 Change-Id: I6db97ecdec9ab1f923148e2b65c8c347201f7ee3
This commit is contained in:
@@ -640,6 +640,9 @@
|
|||||||
// Plugin actions always contain ~ in the key.
|
// Plugin actions always contain ~ in the key.
|
||||||
if (a.indexOf('~') !== -1) {
|
if (a.indexOf('~') !== -1) {
|
||||||
pluginActions.push(actions[a]);
|
pluginActions.push(actions[a]);
|
||||||
|
const patchNum = type === ActionType.REVISION ? this.patchNum : null;
|
||||||
|
this.$.restAPI.getChangeActionURL(this.changeNum, patchNum, '/' + a)
|
||||||
|
.then(url => actions[a].__url = url);
|
||||||
// Add server-side provided plugin actions to overflow menu.
|
// Add server-side provided plugin actions to overflow menu.
|
||||||
this._overflowActions.push({
|
this._overflowActions.push({
|
||||||
type,
|
type,
|
||||||
|
|||||||
@@ -114,11 +114,32 @@ limitations under the License.
|
|||||||
assert.isFalse(element._shouldHideActions({base: ['test']}, false));
|
assert.isFalse(element._shouldHideActions({base: ['test']}, false));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('plugin actions', () => {
|
test('plugin revision actions', () => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getChangeActionURL').returns(
|
||||||
|
Promise.resolve('the-url'));
|
||||||
element.revisionActions = {
|
element.revisionActions = {
|
||||||
'plugin~action': {},
|
'plugin~action': {},
|
||||||
};
|
};
|
||||||
assert.isOk(element.revisionActions['plugin~action']);
|
assert.isOk(element.revisionActions['plugin~action']);
|
||||||
|
flush(() => {
|
||||||
|
assert.isTrue(element.$.restAPI.getChangeActionURL.calledWith(
|
||||||
|
element.changeNum, element.patchNum, '/plugin~action'));
|
||||||
|
assert.equal(element.revisionActions['plugin~action'].__url, 'the-url');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('plugin change actions', () => {
|
||||||
|
sandbox.stub(element.$.restAPI, 'getChangeActionURL').returns(
|
||||||
|
Promise.resolve('the-url'));
|
||||||
|
element.actions = {
|
||||||
|
'plugin~action': {},
|
||||||
|
};
|
||||||
|
assert.isOk(element.actions['plugin~action']);
|
||||||
|
flush(() => {
|
||||||
|
assert.isTrue(element.$.restAPI.getChangeActionURL.calledWith(
|
||||||
|
element.changeNum, null, '/plugin~action'));
|
||||||
|
assert.equal(element.revisionActions['plugin~action'].__url, 'the-url');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('not supported actions are filtered out', () => {
|
test('not supported actions are filtered out', () => {
|
||||||
|
|||||||
@@ -79,9 +79,18 @@
|
|||||||
return this.div(checkbox, this.msg(title));
|
return this.div(checkbox, this.msg(title));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GrPluginActionContext.prototype.prependLabel = function(title, checkbox) {
|
||||||
|
return this.label(checkbox, title);
|
||||||
|
};
|
||||||
|
|
||||||
GrPluginActionContext.prototype.call = function(payload, onSuccess) {
|
GrPluginActionContext.prototype.call = function(payload, onSuccess) {
|
||||||
this.plugin._send(
|
if (!this.action.__url) {
|
||||||
this.action.method, '/' + this.action.__key, onSuccess, payload);
|
console.warn(`Unable to ${this.action.method} to ${this.action.__key}!`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.plugin.restApi()
|
||||||
|
.send(this.action.method, this.action.__url, payload)
|
||||||
|
.then(onSuccess);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.GrPluginActionContext = GrPluginActionContext;
|
window.GrPluginActionContext = GrPluginActionContext;
|
||||||
|
|||||||
@@ -115,13 +115,17 @@ limitations under the License.
|
|||||||
instance.action = {
|
instance.action = {
|
||||||
method: 'METHOD',
|
method: 'METHOD',
|
||||||
__key: 'key',
|
__key: 'key',
|
||||||
|
__url: '/changes/1/revisions/2/foo~bar',
|
||||||
};
|
};
|
||||||
sandbox.stub(plugin, '_send');
|
const sendStub = sandbox.stub().returns(Promise.resolve());
|
||||||
|
sandbox.stub(plugin, 'restApi').returns({
|
||||||
|
send: sendStub,
|
||||||
|
});
|
||||||
const payload = {foo: 'foo'};
|
const payload = {foo: 'foo'};
|
||||||
const successStub = sandbox.stub();
|
const successStub = sandbox.stub();
|
||||||
instance.call(payload, successStub);
|
instance.call(payload, successStub);
|
||||||
assert.isTrue(
|
assert.isTrue(sendStub.calledWith(
|
||||||
plugin._send.calledWith('METHOD', '/key', successStub, payload));
|
'METHOD', '/changes/1/revisions/2/foo~bar', payload));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user