JS API: Expose logged in user
Plugins may want to access currently logged in user. For example in onSubmit() action implementation the user can be warned when she is about to submit someone's else change: Gerrit.install(function(self) { function onSubmitChange(c, r) { if (self.getCurrentUser()._account_id != c.owner._account_id) { return confirm("Really submit change:\n" + c.id + "\n" + "revision: " + r.name + "\n" + "from: " + c.owner.name + "?"); } return true; } Gerrit.on('submitchange', onSubmitChange); }); Bug: issue 461 Change-Id: Icec244fa8e07e428e287ff3d90fec3b1f810cf10
This commit is contained in:

committed by
David Pursehouse

parent
c8c17ec5fb
commit
0a4c0ffa5a
@@ -16,6 +16,7 @@ package com.google.gerrit.client.api;
|
||||
|
||||
import com.google.gerrit.client.ErrorDialog;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.account.AccountInfo;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
import com.google.gwt.user.client.History;
|
||||
@@ -66,6 +67,7 @@ public class ApiGlue {
|
||||
refresh: @com.google.gerrit.client.api.ApiGlue::refresh(),
|
||||
refreshMenuBar: @com.google.gerrit.client.api.ApiGlue::refreshMenuBar(),
|
||||
showError: @com.google.gerrit.client.api.ApiGlue::showError(Ljava/lang/String;),
|
||||
getCurrentUser: @com.google.gerrit.client.api.ApiGlue::getCurrentUser(),
|
||||
|
||||
on: function (e,f){(this.events[e] || (this.events[e]=[])).push(f)},
|
||||
onAction: function (t,n,c){this._onAction(this.getPluginName(),t,n,c)},
|
||||
@@ -194,6 +196,10 @@ public class ApiGlue {
|
||||
Gerrit.display(History.getToken());
|
||||
}
|
||||
|
||||
private static final AccountInfo getCurrentUser() {
|
||||
return Gerrit.getUserAccountInfo();
|
||||
}
|
||||
|
||||
private static final void refreshMenuBar() {
|
||||
Gerrit.refreshMenuBar();
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@ final class Plugin extends JavaScriptObject {
|
||||
var G = $wnd.Gerrit;
|
||||
@com.google.gerrit.client.api.Plugin::TYPE.prototype = {
|
||||
getPluginName: function(){return this.name},
|
||||
getCurrentUser: @com.google.gerrit.client.api.ApiGlue::getCurrentUser(),
|
||||
go: @com.google.gerrit.client.api.ApiGlue::go(Ljava/lang/String;),
|
||||
refresh: @com.google.gerrit.client.api.ApiGlue::refresh(),
|
||||
refreshMenuBar: @com.google.gerrit.client.api.ApiGlue::refreshMenuBar(),
|
||||
|
Reference in New Issue
Block a user