Merge branch 'stable-2.14'
* stable-2.14:
Remove usage of http password get api
Change-Id: I576da6ed3406a65ccb1f962ae123cb2e65d6cb5a
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/AddSshKey.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/AddSshKey.java
index c230aaf..f6a18e0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/AddSshKey.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/AddSshKey.java
@@ -24,10 +24,8 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
-import org.eclipse.jgit.errors.ConfigInvalidException;
-
import java.io.IOException;
+import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton
class AddSshKey implements RestModifyView<ServiceUserResource, Input> {
@@ -40,8 +38,7 @@
@Override
public Response<SshKeyInfo> apply(ServiceUserResource rsrc, Input input)
- throws AuthException, BadRequestException, OrmException, IOException,
- ConfigInvalidException {
+ throws AuthException, BadRequestException, OrmException, IOException, ConfigInvalidException {
return addSshKey.get().apply(rsrc.getUser(), input);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUser.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUser.java
index 4c3c591..cadde7b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUser.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUser.java
@@ -47,21 +47,14 @@
import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectLevelConfig;
+import com.google.gerrit.server.group.InternalGroup;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
-
import com.googlesource.gerrit.plugins.serviceuser.CreateServiceUser.Input;
import com.googlesource.gerrit.plugins.serviceuser.GetServiceUser.ServiceUserInfo;
-
-import org.eclipse.jgit.errors.ConfigInvalidException;
-import org.eclipse.jgit.lib.Config;
-import org.eclipse.jgit.lib.PersonIdent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -71,11 +64,16 @@
import java.util.Date;
import java.util.List;
import java.util.Locale;
+import java.util.Optional;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@RequiresCapability(CreateServiceUserCapability.ID)
class CreateServiceUser implements RestModifyView<ConfigResource, Input> {
- private static final Logger log =
- LoggerFactory.getLogger(CreateServiceUser.class);
+ private static final Logger log = LoggerFactory.getLogger(CreateServiceUser.class);
public static final String USER = "user";
public static final String KEY_CREATED_BY = "createdBy";
@@ -110,7 +108,8 @@
private final AccountLoader.Factory accountLoader;
@Inject
- CreateServiceUser(PluginConfigFactory cfgFactory,
+ CreateServiceUser(
+ PluginConfigFactory cfgFactory,
@PluginName String pluginName,
CreateAccount.Factory createAccountFactory,
GroupCache groupCache,
@@ -132,7 +131,8 @@
this.db = db;
this.username = username;
this.blockedNames =
- Lists.transform(Arrays.asList(cfg.getStringList("block")),
+ Lists.transform(
+ Arrays.asList(cfg.getStringList("block")),
new Function<String, String>() {
@Override
public String apply(String blockedName) {
@@ -143,10 +143,9 @@
this.metaDataUpdateFactory = metaDataUpdateFactory;
this.storage = projectCache.getAllProjects().getConfig(pluginName + ".db");
this.allProjects = projectCache.getAllProjects().getProject().getNameKey();
- this.rfc2822DateFormatter =
- new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
- this.rfc2822DateFormatter.setCalendar(Calendar.getInstance(
- gerritIdent.getTimeZone(), Locale.US));
+ this.rfc2822DateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
+ this.rfc2822DateFormatter.setCalendar(
+ Calendar.getInstance(gerritIdent.getTimeZone(), Locale.US));
this.getConfig = getConfig;
this.accountLoader = accountLoader;
}
@@ -154,8 +153,7 @@
@Override
public Response<ServiceUserInfo> apply(ConfigResource resource, Input input)
throws AuthException, BadRequestException, ResourceConflictException,
- UnprocessableEntityException, OrmException, IOException,
- ConfigInvalidException {
+ UnprocessableEntityException, OrmException, IOException, ConfigInvalidException {
CurrentUser user = userProvider.get();
if (user == null || !user.isIdentifiedUser()) {
throw new AuthException("authentication required");
@@ -172,8 +170,8 @@
}
if (blockedNames.contains(username.toLowerCase())) {
- throw new BadRequestException("The username '" + username
- + "' is not allowed as name for service users.");
+ throw new BadRequestException(
+ "The username '" + username + "' is not allowed as name for service users.");
}
input.email = Strings.emptyToNull(input.email);
@@ -184,16 +182,14 @@
}
}
- AccountInput in =
- new ServiceUserInput(username, input.email, input.sshKey);
+ AccountInput in = new ServiceUserInput(username, input.email, input.sshKey);
Response<AccountInfo> response =
createAccountFactory.create(username).apply(TopLevelResource.INSTANCE, in);
- addToGroups(new Account.Id(response.value()._accountId),
- cfg.getStringList("group"));
+ addToGroups(new Account.Id(response.value()._accountId), cfg.getStringList("group"));
String creator = user.getUserName();
- Account.Id creatorId = ((IdentifiedUser)user).getAccountId();
+ Account.Id creatorId = ((IdentifiedUser) user).getAccountId();
String creationDate = rfc2822DateFormatter.format(new Date());
Config db = storage.get();
@@ -218,19 +214,22 @@
private void addToGroups(Account.Id accountId, String[] groupNames)
throws OrmException, IOException {
for (String groupName : groupNames) {
- AccountGroup group = groupCache.get(new AccountGroup.NameKey(groupName));
- if (group != null) {
+ Optional<InternalGroup> group = groupCache.get(new AccountGroup.NameKey(groupName));
+ if (group.isPresent()) {
AccountGroupMember m =
- new AccountGroupMember(new AccountGroupMember.Key(
- accountId, group.getId()));
- db.get().accountGroupMembersAudit().insert(Collections.singleton(
- new AccountGroupMemberAudit(
- m, currentUser.get().getAccountId(), TimeUtil.nowTs())));
+ new AccountGroupMember(new AccountGroupMember.Key(accountId, group.get().getId()));
+ db.get()
+ .accountGroupMembersAudit()
+ .insert(
+ Collections.singleton(
+ new AccountGroupMemberAudit(
+ m, currentUser.get().getAccountId(), TimeUtil.nowTs())));
db.get().accountGroupMembers().insert(Collections.singleton(m));
} else {
- log.error(String.format(
- "Could not add new service user %s to group %s: group not found",
- username, groupName));
+ log.error(
+ String.format(
+ "Could not add new service user %s to group %s: group not found",
+ username, groupName));
}
}
if (groupNames.length > 0) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCapability.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCapability.java
index ae782ec..eb7c789 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCapability.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCapability.java
@@ -18,10 +18,10 @@
class CreateServiceUserCapability extends CapabilityDefinition {
- public final static String ID = "createServiceUser";
+ public static final String ID = "createServiceUser";
@Override
public String getDescription() {
- return "Create Service User";
+ return "Create Service User";
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCommand.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCommand.java
index 98a0556..c102c50 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserCommand.java
@@ -21,15 +21,13 @@
import com.google.gerrit.sshd.SshCommand;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
-
-import org.eclipse.jgit.errors.ConfigInvalidException;
-import org.kohsuke.args4j.Argument;
-import org.kohsuke.args4j.Option;
-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
@RequiresCapability(CreateServiceUserCapability.ID)
@CommandMetaData(name = "create", description = "Create Service User")
@@ -38,15 +36,18 @@
@Argument(index = 0, required = true, metaVar = "USERNAME", usage = "name of the service user")
private String username;
- @Option(name = "--ssh-key", required = true, metaVar = "-|KEY", usage = "public key for SSH authentication")
+ @Option(
+ name = "--ssh-key",
+ required = true,
+ metaVar = "-|KEY",
+ usage = "public key for SSH authentication"
+ )
private String sshKey;
- @Inject
- private CreateServiceUser.Factory createServiceUser;
+ @Inject private CreateServiceUser.Factory createServiceUser;
@Override
- protected void run() throws OrmException, IOException, UnloggedFailure,
- ConfigInvalidException {
+ protected void run() throws OrmException, IOException, UnloggedFailure, ConfigInvalidException {
CreateServiceUser.Input input = new CreateServiceUser.Input();
input.sshKey = readSshKey();
@@ -63,8 +64,7 @@
}
if ("-".equals(sshKey)) {
sshKey = "";
- BufferedReader br =
- new BufferedReader(new InputStreamReader(in, "UTF-8"));
+ BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line;
while ((line = br.readLine()) != null) {
sshKey += line + "\n";
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserNotes.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserNotes.java
index 7c8140c..ba3f099 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/CreateServiceUserNotes.java
@@ -25,10 +25,10 @@
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
-
import com.googlesource.gerrit.plugins.serviceuser.GetServiceUser.ServiceUserInfo;
-
+import java.io.IOException;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
+import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
@@ -41,11 +41,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-
class CreateServiceUserNotes {
- private static final Logger log =
- LoggerFactory.getLogger(CreateServiceUserNotes.class);
+ private static final Logger log = LoggerFactory.getLogger(CreateServiceUserNotes.class);
interface Factory {
CreateServiceUserNotes create(Project.NameKey project, Repository git);
@@ -65,7 +62,8 @@
private StringBuilder message;
@Inject
- CreateServiceUserNotes(@GerritPersonIdent PersonIdent gerritIdent,
+ CreateServiceUserNotes(
+ @GerritPersonIdent PersonIdent gerritIdent,
NotesBranchUtil.Factory notesBranchUtilFactory,
ServiceUserResolver serviceUserResolver,
@AnonymousCowardName String anonymousCowardName,
@@ -80,7 +78,7 @@
}
void createNotes(String branch, ObjectId oldObjectId, ObjectId newObjectId)
- throws IOException, OrmException {
+ throws IOException, OrmException, ConfigInvalidException {
if (ObjectId.zeroId().equals(newObjectId)) {
return;
}
@@ -100,8 +98,7 @@
}
for (RevCommit c : rw) {
- ServiceUserInfo serviceUser =
- serviceUserResolver.getAsServiceUser(c.getCommitterIdent());
+ ServiceUserInfo serviceUser = serviceUserResolver.getAsServiceUser(c.getCommitterIdent());
if (serviceUser != null) {
ObjectId content = createNoteContent(branch, serviceUser);
getNotes().set(c, content);
@@ -118,9 +115,10 @@
}
message.insert(0, "Update notes for service user commits\n\n");
- notesBranchUtilFactory.create(project, git, inserter)
- .commitAllNotes(serviceUserNotes, REFS_NOTES_SERVICEUSER, gerritServerIdent,
- message.toString());
+ notesBranchUtilFactory
+ .create(project, git, inserter)
+ .commitAllNotes(
+ serviceUserNotes, REFS_NOTES_SERVICEUSER, gerritServerIdent, message.toString());
} finally {
if (inserter != null) {
inserter.close();
@@ -128,8 +126,7 @@
}
}
- private void markUninteresting(Repository git, String branch, RevWalk rw,
- ObjectId oldObjectId) {
+ private void markUninteresting(Repository git, String branch, RevWalk rw, ObjectId oldObjectId) {
for (Ref r : git.getAllRefs().values()) {
try {
if (r.getName().equals(branch)) {
@@ -150,15 +147,13 @@
private ObjectId createNoteContent(String branch, ServiceUserInfo serviceUser)
throws IOException, OrmException {
- return getInserter().insert(Constants.OBJ_BLOB,
- createServiceUserNote(branch, serviceUser).getBytes("UTF-8"));
+ return getInserter()
+ .insert(Constants.OBJ_BLOB, createServiceUserNote(branch, serviceUser).getBytes("UTF-8"));
}
- private String createServiceUserNote(String branch,
- ServiceUserInfo serviceUser) throws OrmException {
- HeaderFormatter fmt =
- new HeaderFormatter(gerritServerIdent.getTimeZone(),
- anonymousCowardName);
+ private String createServiceUserNote(String branch, ServiceUserInfo serviceUser)
+ throws OrmException {
+ HeaderFormatter fmt = new HeaderFormatter(gerritServerIdent.getTimeZone(), anonymousCowardName);
fmt.appendDate();
fmt.append("Project", project.get());
fmt.append("Branch", branch);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/DeleteActive.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/DeleteActive.java
index fd4a7f5..58532fd 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/DeleteActive.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/DeleteActive.java
@@ -22,8 +22,8 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import java.io.IOException;
+import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton
class DeleteActive implements RestModifyView<ServiceUserResource, Input> {
@@ -36,7 +36,7 @@
@Override
public Response<?> apply(ServiceUserResource rsrc, Input input)
- throws RestApiException, OrmException, IOException {
+ throws RestApiException, OrmException, IOException, ConfigInvalidException {
return deleteActive.get().apply(rsrc, input);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/DeleteSshKey.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/DeleteSshKey.java
index d3685cc..09031bc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/DeleteSshKey.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/DeleteSshKey.java
@@ -19,32 +19,30 @@
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.server.account.AccountResource;
import com.google.gerrit.server.account.DeleteSshKey.Input;
+import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
+import java.io.IOException;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
-import java.io.IOException;
-
@Singleton
-class DeleteSshKey
- implements RestModifyView<ServiceUserResource.SshKey, Input> {
+class DeleteSshKey implements RestModifyView<ServiceUserResource.SshKey, Input> {
private final Provider<com.google.gerrit.server.account.DeleteSshKey> deleteSshKey;
@Inject
- DeleteSshKey(
- Provider<com.google.gerrit.server.account.DeleteSshKey> deleteSshKey) {
+ DeleteSshKey(Provider<com.google.gerrit.server.account.DeleteSshKey> deleteSshKey) {
this.deleteSshKey = deleteSshKey;
}
@Override
public Response<?> apply(ServiceUserResource.SshKey rsrc, Input input)
- throws OrmException, AuthException, RepositoryNotFoundException,
- IOException, ConfigInvalidException {
- return deleteSshKey.get().apply(
- new AccountResource.SshKey(rsrc.getUser(), rsrc.getSshKey()), input);
+ throws OrmException, AuthException, RepositoryNotFoundException, IOException,
+ ConfigInvalidException, PermissionBackendException {
+ return deleteSshKey
+ .get()
+ .apply(new AccountResource.SshKey(rsrc.getUser(), rsrc.getSshKey()), input);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetConfig.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetConfig.java
index 86bf244..cd30b45 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetConfig.java
@@ -15,7 +15,6 @@
package com.googlesource.gerrit.plugins.serviceuser;
import com.google.common.base.Strings;
-import com.google.gerrit.common.data.GroupDescriptions;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.common.GroupInfo;
import com.google.gerrit.extensions.restapi.RestReadView;
@@ -25,17 +24,18 @@
import com.google.gerrit.server.config.PluginConfig;
import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.gerrit.server.group.GroupJson;
+import com.google.gerrit.server.group.InternalGroup;
+import com.google.gerrit.server.group.InternalGroupDescription;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.TreeMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@Singleton
class GetConfig implements RestReadView<ConfigResource> {
@@ -47,8 +47,11 @@
private final GroupJson groupJson;
@Inject
- public GetConfig(PluginConfigFactory cfgFactory,
- @PluginName String pluginName, GroupCache groupCache, GroupJson groupJson) {
+ public GetConfig(
+ PluginConfigFactory cfgFactory,
+ @PluginName String pluginName,
+ GroupCache groupCache,
+ GroupJson groupJson) {
this.cfgFactory = cfgFactory;
this.pluginName = pluginName;
this.groupCache = groupCache;
@@ -74,9 +77,9 @@
String[] groups = cfg.getStringList("group");
info.groups = new TreeMap<>();
for (String g : groups) {
- AccountGroup group = groupCache.get(new AccountGroup.NameKey(g));
- if (group != null) {
- GroupInfo groupInfo = groupJson.format(GroupDescriptions.forAccountGroup(group));
+ Optional<InternalGroup> group = groupCache.get(new AccountGroup.NameKey(g));
+ if (group.isPresent()) {
+ GroupInfo groupInfo = groupJson.format(new InternalGroupDescription(group.get()));
groupInfo.name = null;
info.groups.put(g, groupInfo);
} else {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetOwner.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetOwner.java
index de8ccc2..8eb5031 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetOwner.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetOwner.java
@@ -39,8 +39,11 @@
private final GroupJson json;
@Inject
- GetOwner(GroupsCollection groups, @PluginName String pluginName,
- ProjectCache projectCache, GroupJson json) {
+ GetOwner(
+ GroupsCollection groups,
+ @PluginName String pluginName,
+ ProjectCache projectCache,
+ GroupJson json) {
this.groups = groups;
this.pluginName = pluginName;
this.projectCache = projectCache;
@@ -54,9 +57,8 @@
String owner = storage.get().getString(USER, rsrc.getUser().getUserName(), KEY_OWNER);
if (owner != null) {
GroupDescription.Basic group = groups.parseId(owner);
- return Response.<GroupInfo> ok(json.format(group));
- } else {
- return Response.none();
+ return Response.<GroupInfo>ok(json.format(group));
}
+ return Response.none();
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetServiceUser.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetServiceUser.java
index 2f9d56b..5ce479e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetServiceUser.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetServiceUser.java
@@ -34,7 +34,6 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import org.eclipse.jgit.lib.Config;
@Singleton
@@ -46,9 +45,12 @@
private final AccountLoader.Factory accountLoader;
@Inject
- GetServiceUser(Provider<GetAccount> getAccount,
- @PluginName String pluginName, ProjectCache projectCache,
- GetOwner getOwner, AccountLoader.Factory accountLoader) {
+ GetServiceUser(
+ Provider<GetAccount> getAccount,
+ @PluginName String pluginName,
+ ProjectCache projectCache,
+ GetOwner getOwner,
+ AccountLoader.Factory accountLoader) {
this.getAccount = getAccount;
this.pluginName = pluginName;
this.projectCache = projectCache;
@@ -68,8 +70,7 @@
ServiceUserInfo info = new ServiceUserInfo(getAccount.get().apply(rsrc));
AccountLoader al = accountLoader.create(true);
- info.createdBy =
- al.get(new Account.Id(db.getInt(USER, username, KEY_CREATOR_ID, -1)));
+ info.createdBy = al.get(new Account.Id(db.getInt(USER, username, KEY_CREATOR_ID, -1)));
al.fill();
info.createdAt = db.getString(USER, username, KEY_CREATED_AT);
info.inactive = !rsrc.getUser().getAccount().isActive() ? true : null;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetSshKey.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetSshKey.java
index b9f55f7..baab715 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetSshKey.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetSshKey.java
@@ -32,7 +32,6 @@
@Override
public SshKeyInfo apply(ServiceUserResource.SshKey rsrc) {
- return getSshKey.get().apply(
- new AccountResource.SshKey(rsrc.getUser(), rsrc.getSshKey()));
+ return getSshKey.get().apply(new AccountResource.SshKey(rsrc.getUser(), rsrc.getSshKey()));
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetSshKeys.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetSshKeys.java
index 1948329..be08a69 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetSshKeys.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/GetSshKeys.java
@@ -21,12 +21,10 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
-import org.eclipse.jgit.errors.ConfigInvalidException;
-import org.eclipse.jgit.errors.RepositoryNotFoundException;
-
import java.io.IOException;
import java.util.List;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.errors.RepositoryNotFoundException;
@Singleton
class GetSshKeys implements RestReadView<ServiceUserResource> {
@@ -39,8 +37,8 @@
@Override
public List<SshKeyInfo> apply(ServiceUserResource rsrc)
- throws AuthException, OrmException, RepositoryNotFoundException,
- IOException, ConfigInvalidException {
+ throws AuthException, OrmException, RepositoryNotFoundException, IOException,
+ ConfigInvalidException {
return getSshKeys.get().apply(rsrc.getUser());
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/HeaderFormatter.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/HeaderFormatter.java
index 44bc973..38e9197 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/HeaderFormatter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/HeaderFormatter.java
@@ -16,7 +16,6 @@
import com.google.common.base.Strings;
import com.google.gerrit.extensions.common.AccountInfo;
-
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -31,8 +30,7 @@
HeaderFormatter(TimeZone tz, String anonymousCowardName) {
this.anonymousCowardName = anonymousCowardName;
- rfc2822DateFormatter =
- new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
+ rfc2822DateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
rfc2822DateFormatter.setCalendar(Calendar.getInstance(tz, Locale.US));
}
@@ -41,8 +39,7 @@
}
void appendDate() {
- sb.append("Date: ").append(rfc2822DateFormatter.format(new Date()))
- .append("\n");
+ sb.append("Date: ").append(rfc2822DateFormatter.format(new Date())).append("\n");
}
void appendUser(String key, AccountInfo user) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/HttpModule.java
index 53ef9b0..47196c3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/HttpModule.java
@@ -23,7 +23,6 @@
@Override
protected void configureServlets() {
- DynamicSet.bind(binder(), WebUiPlugin.class)
- .toInstance(new GwtPlugin("serviceuser"));
+ DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new GwtPlugin("serviceuser"));
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ListServiceUsers.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ListServiceUsers.java
index e6e4e06..3b696bc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ListServiceUsers.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ListServiceUsers.java
@@ -27,17 +27,17 @@
import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.config.ConfigResource;
import com.google.gerrit.server.git.ProjectLevelConfig;
+import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import com.googlesource.gerrit.plugins.serviceuser.GetServiceUser.ServiceUserInfo;
-
-import org.eclipse.jgit.lib.Config;
-
+import java.io.IOException;
import java.util.Map;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.lib.Config;
@Singleton
class ListServiceUsers implements RestReadView<ConfigResource> {
@@ -49,9 +49,12 @@
private final Provider<GetServiceUser> getServiceUser;
@Inject
- ListServiceUsers(Provider<CurrentUser> userProvider,
- @PluginName String pluginName, ProjectCache projectCache,
- AccountCache accountCache, Provider<ServiceUserCollection> serviceUsers,
+ ListServiceUsers(
+ Provider<CurrentUser> userProvider,
+ @PluginName String pluginName,
+ ProjectCache projectCache,
+ AccountCache accountCache,
+ Provider<ServiceUserCollection> serviceUsers,
Provider<GetServiceUser> getServiceUser) {
this.userProvider = userProvider;
this.pluginName = pluginName;
@@ -63,7 +66,8 @@
@Override
public Map<String, ServiceUserInfo> apply(ConfigResource rscr)
- throws OrmException, AuthException {
+ throws OrmException, IOException, AuthException, PermissionBackendException,
+ ConfigInvalidException {
ProjectLevelConfig storage = projectCache.getAllProjects().getConfig(pluginName + ".db");
CurrentUser user = userProvider.get();
if (user == null || !user.isIdentifiedUser()) {
@@ -78,8 +82,7 @@
ServiceUserInfo info;
try {
ServiceUserResource serviceUserResource =
- serviceUsers.get().parse(new ConfigResource(),
- IdString.fromDecoded(username));
+ serviceUsers.get().parse(new ConfigResource(), IdString.fromDecoded(username));
info = getServiceUser.get().apply(serviceUserResource);
info.username = null;
accounts.put(username, info);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/Module.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/Module.java
index 33a4024..97cda35 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/Module.java
@@ -37,41 +37,40 @@
.annotatedWith(Exports.named(CreateServiceUserCapability.ID))
.to(CreateServiceUserCapability.class);
DynamicSet.bind(binder(), TopMenu.class).to(ServiceUserMenu.class);
- DynamicSet.bind(binder(), GitReferenceUpdatedListener.class)
- .to(RefUpdateListener.class);
- DynamicSet.bind(binder(), CommitValidationListener.class)
- .to(ValidateServiceUserCommits.class);
+ DynamicSet.bind(binder(), GitReferenceUpdatedListener.class).to(RefUpdateListener.class);
+ DynamicSet.bind(binder(), CommitValidationListener.class).to(ValidateServiceUserCommits.class);
install(new FactoryModuleBuilder().build(CreateServiceUserNotes.Factory.class));
- install(new RestApiModule() {
- @Override
- protected void configure() {
- DynamicMap.mapOf(binder(), SERVICE_USER_KIND);
- DynamicMap.mapOf(binder(), SERVICE_USER_SSH_KEY_KIND);
- bind(ServiceUserCollection.class);
- child(CONFIG_KIND, "serviceusers").to(ServiceUserCollection.class);
- get(SERVICE_USER_KIND).to(GetServiceUser.class);
- install(new FactoryModuleBuilder().build(CreateServiceUser.Factory.class));
- get(CONFIG_KIND, "config").to(GetConfig.class);
- put(CONFIG_KIND, "config").to(PutConfig.class);
- child(SERVICE_USER_KIND, "sshkeys").to(SshKeys.class);
- get(SERVICE_USER_SSH_KEY_KIND).to(GetSshKey.class);
- post(SERVICE_USER_KIND, "sshkeys").to(AddSshKey.class);
- delete(SERVICE_USER_SSH_KEY_KIND).to(DeleteSshKey.class);
- get(SERVICE_USER_KIND, "name").to(GetName.class);
- put(SERVICE_USER_KIND, "name").to(PutName.class);
- delete(SERVICE_USER_KIND, "name").to(PutName.class);
- get(SERVICE_USER_KIND, "email").to(GetEmail.class);
- put(SERVICE_USER_KIND, "email").to(PutEmail.class);
- delete(SERVICE_USER_KIND, "email").to(PutEmail.class);
- put(SERVICE_USER_KIND, "password.http").to(PutHttpPassword.class);
- delete(SERVICE_USER_KIND, "password.http").to(PutHttpPassword.class);
- get(SERVICE_USER_KIND, "active").to(GetActive.class);
- put(SERVICE_USER_KIND, "active").to(PutActive.class);
- delete(SERVICE_USER_KIND, "active").to(DeleteActive.class);
- get(SERVICE_USER_KIND, "owner").to(GetOwner.class);
- put(SERVICE_USER_KIND, "owner").to(PutOwner.class);
- delete(SERVICE_USER_KIND, "owner").to(PutOwner.class);
- }
- });
+ install(
+ new RestApiModule() {
+ @Override
+ protected void configure() {
+ DynamicMap.mapOf(binder(), SERVICE_USER_KIND);
+ DynamicMap.mapOf(binder(), SERVICE_USER_SSH_KEY_KIND);
+ bind(ServiceUserCollection.class);
+ child(CONFIG_KIND, "serviceusers").to(ServiceUserCollection.class);
+ get(SERVICE_USER_KIND).to(GetServiceUser.class);
+ install(new FactoryModuleBuilder().build(CreateServiceUser.Factory.class));
+ get(CONFIG_KIND, "config").to(GetConfig.class);
+ put(CONFIG_KIND, "config").to(PutConfig.class);
+ child(SERVICE_USER_KIND, "sshkeys").to(SshKeys.class);
+ get(SERVICE_USER_SSH_KEY_KIND).to(GetSshKey.class);
+ post(SERVICE_USER_KIND, "sshkeys").to(AddSshKey.class);
+ delete(SERVICE_USER_SSH_KEY_KIND).to(DeleteSshKey.class);
+ get(SERVICE_USER_KIND, "name").to(GetName.class);
+ put(SERVICE_USER_KIND, "name").to(PutName.class);
+ delete(SERVICE_USER_KIND, "name").to(PutName.class);
+ get(SERVICE_USER_KIND, "email").to(GetEmail.class);
+ put(SERVICE_USER_KIND, "email").to(PutEmail.class);
+ delete(SERVICE_USER_KIND, "email").to(PutEmail.class);
+ put(SERVICE_USER_KIND, "password.http").to(PutHttpPassword.class);
+ delete(SERVICE_USER_KIND, "password.http").to(PutHttpPassword.class);
+ get(SERVICE_USER_KIND, "active").to(GetActive.class);
+ put(SERVICE_USER_KIND, "active").to(PutActive.class);
+ delete(SERVICE_USER_KIND, "active").to(DeleteActive.class);
+ get(SERVICE_USER_KIND, "owner").to(GetOwner.class);
+ put(SERVICE_USER_KIND, "owner").to(PutOwner.class);
+ delete(SERVICE_USER_KIND, "owner").to(PutOwner.class);
+ }
+ });
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutActive.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutActive.java
index 07c33d9..517ccbc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutActive.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutActive.java
@@ -22,8 +22,8 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import java.io.IOException;
+import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton
class PutActive implements RestModifyView<ServiceUserResource, Input> {
@@ -36,7 +36,7 @@
@Override
public Response<String> apply(ServiceUserResource rsrc, Input input)
- throws ResourceNotFoundException, OrmException, IOException {
+ throws ResourceNotFoundException, OrmException, IOException, ConfigInvalidException {
return putActive.get().apply(rsrc, input);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutConfig.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutConfig.java
index 47c41ee..09a559e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutConfig.java
@@ -28,17 +28,14 @@
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
import com.googlesource.gerrit.plugins.serviceuser.PutConfig.Input;
-
+import java.io.IOException;
+import java.util.List;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
-import java.io.IOException;
-import java.util.List;
-
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
@Singleton
class PutConfig implements RestModifyView<ConfigResource, Input> {
@@ -60,8 +57,11 @@
private final GroupCache groupCache;
@Inject
- PutConfig(PluginConfigFactory cfgFactory, SitePaths sitePaths,
- @PluginName String pluginName, GroupCache groupCache) {
+ PutConfig(
+ PluginConfigFactory cfgFactory,
+ SitePaths sitePaths,
+ @PluginName String pluginName,
+ GroupCache groupCache) {
this.cfgFactory = cfgFactory;
this.sitePaths = sitePaths;
this.pluginName = pluginName;
@@ -71,16 +71,13 @@
@Override
public Response<String> apply(ConfigResource rsrc, Input input)
throws IOException, ConfigInvalidException, UnprocessableEntityException {
- FileBasedConfig cfg =
- new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
+ FileBasedConfig cfg = new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
cfg.load();
if (input.info != null) {
- cfg.setString("plugin", pluginName, "infoMessage",
- Strings.emptyToNull(input.info));
+ cfg.setString("plugin", pluginName, "infoMessage", Strings.emptyToNull(input.info));
}
if (input.onSuccess != null) {
- cfg.setString("plugin", pluginName, "onSuccessMessage",
- Strings.emptyToNull(input.onSuccess));
+ cfg.setString("plugin", pluginName, "onSuccessMessage", Strings.emptyToNull(input.onSuccess));
}
if (input.allowEmail != null) {
setBoolean(cfg, "allowEmail", input.allowEmail);
@@ -103,15 +100,14 @@
if (input.groups != null) {
for (String g : input.groups) {
if (groupCache.get(new AccountGroup.NameKey(g)) == null) {
- throw new UnprocessableEntityException(
- String.format("Group %s does not exist.", g));
+ throw new UnprocessableEntityException(String.format("Group %s does not exist.", g));
}
}
cfg.setStringList("plugin", pluginName, "group", input.groups);
}
cfg.save();
cfgFactory.getFromGerritConfig(pluginName, true);
- return Response.<String> ok("OK");
+ return Response.<String>ok("OK");
}
private void setBoolean(Config cfg, String name, boolean value) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutEmail.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutEmail.java
index 8a9389e..8ea158c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutEmail.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutEmail.java
@@ -14,12 +14,14 @@
package com.googlesource.gerrit.plugins.serviceuser;
+import static com.google.gerrit.server.permissions.GlobalPermission.ADMINISTRATE_SERVER;
+
import com.google.common.base.Strings;
import com.google.gerrit.common.errors.EmailException;
+import com.google.gerrit.extensions.api.accounts.EmailInput;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.DefaultInput;
-import com.google.gerrit.extensions.api.accounts.EmailInput;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
@@ -30,22 +32,20 @@
import com.google.gerrit.server.account.DeleteEmail;
import com.google.gerrit.server.account.PutPreferred;
import com.google.gerrit.server.config.ConfigResource;
+import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import com.googlesource.gerrit.plugins.serviceuser.PutEmail.Input;
-
-import org.eclipse.jgit.errors.ConfigInvalidException;
-
import java.io.IOException;
+import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton
class PutEmail implements RestModifyView<ServiceUserResource, Input> {
public static class Input {
- @DefaultInput
- public String email;
+ @DefaultInput public String email;
}
private final Provider<GetConfig> getConfig;
@@ -54,40 +54,42 @@
private final Provider<DeleteEmail> deleteEmail;
private final Provider<PutPreferred> putPreferred;
private final Provider<CurrentUser> self;
+ private final PermissionBackend permissionBackend;
@Inject
- PutEmail(Provider<GetConfig> getConfig,
+ PutEmail(
+ Provider<GetConfig> getConfig,
Provider<GetEmail> getEmail,
Provider<CreateEmail.Factory> createEmailFactory,
Provider<DeleteEmail> deleteEmail,
Provider<PutPreferred> putPreferred,
- Provider<CurrentUser> self) {
+ Provider<CurrentUser> self,
+ PermissionBackend permissionBackend) {
this.getConfig = getConfig;
this.getEmail = getEmail;
this.createEmailFactory = createEmailFactory;
this.deleteEmail = deleteEmail;
this.putPreferred = putPreferred;
this.self = self;
+ this.permissionBackend = permissionBackend;
}
@Override
public Response<?> apply(ServiceUserResource rsrc, Input input)
- throws AuthException, ResourceNotFoundException,
- ResourceConflictException, MethodNotAllowedException, OrmException,
- BadRequestException, ConfigInvalidException, EmailException, IOException {
+ throws AuthException, ResourceNotFoundException, ResourceConflictException,
+ MethodNotAllowedException, OrmException, BadRequestException, ConfigInvalidException,
+ EmailException, IOException, PermissionBackendException {
Boolean emailAllowed = getConfig.get().apply(new ConfigResource()).allowEmail;
- if ((emailAllowed == null || !emailAllowed)
- && !self.get().getCapabilities().canAdministrateServer()) {
- throw new ResourceConflictException("setting email not allowed");
+ if ((emailAllowed == null || !emailAllowed)) {
+ permissionBackend.user(self).check(ADMINISTRATE_SERVER);
}
String email = getEmail.get().apply(rsrc);
if (Strings.emptyToNull(input.email) == null) {
if (Strings.emptyToNull(email) == null) {
return Response.none();
- } else {
- return deleteEmail.get().apply(rsrc.getUser(), email);
}
+ return deleteEmail.get().apply(rsrc.getUser(), email);
} else if (email != null && email.equals(input.email)) {
return Response.ok(email);
} else {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutHttpPassword.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutHttpPassword.java
index d5f2883..a920f62 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutHttpPassword.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutHttpPassword.java
@@ -13,6 +13,8 @@
// limitations under the License.
package com.googlesource.gerrit.plugins.serviceuser;
+import static com.google.gerrit.server.permissions.GlobalPermission.ADMINISTRATE_SERVER;
+
import com.google.common.base.Strings;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
@@ -21,21 +23,18 @@
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.config.ConfigResource;
+import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import com.googlesource.gerrit.plugins.serviceuser.PutHttpPassword.Input;
-
-import org.apache.commons.codec.binary.Base64;
-
-import org.eclipse.jgit.errors.ConfigInvalidException;
-
import java.io.IOException;
-
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
+import org.apache.commons.codec.binary.Base64;
+import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton
public class PutHttpPassword implements RestModifyView<ServiceUserResource, Input> {
@@ -58,20 +57,24 @@
private final Provider<GetConfig> getConfig;
private final com.google.gerrit.server.account.PutHttpPassword putHttpPassword;
private final Provider<CurrentUser> self;
+ private final PermissionBackend permissionBackend;
@Inject
- PutHttpPassword(Provider<GetConfig> getConfig,
+ PutHttpPassword(
+ Provider<GetConfig> getConfig,
com.google.gerrit.server.account.PutHttpPassword putHttpPassword,
- Provider<CurrentUser> self) {
+ Provider<CurrentUser> self,
+ PermissionBackend permissionBackend) {
this.getConfig = getConfig;
this.putHttpPassword = putHttpPassword;
this.self = self;
+ this.permissionBackend = permissionBackend;
}
@Override
public Response<String> apply(ServiceUserResource rsrc, Input input)
throws AuthException, ResourceConflictException, ConfigInvalidException,
- ResourceNotFoundException, OrmException, IOException {
+ ResourceNotFoundException, OrmException, IOException, PermissionBackendException {
if (input == null) {
input = new Input();
}
@@ -79,15 +82,11 @@
Boolean httpPasswordAllowed = getConfig.get().apply(new ConfigResource()).allowHttpPassword;
if (input.generate || input.httpPassword == null) {
- if ((httpPasswordAllowed == null || !httpPasswordAllowed)
- && !self.get().getCapabilities().canAdministrateServer()) {
- throw new ResourceConflictException("not allowed to generate HTTP password");
+ if ((httpPasswordAllowed == null || !httpPasswordAllowed)) {
+ permissionBackend.user(self).check(ADMINISTRATE_SERVER);
}
} else {
- if (!self.get().getCapabilities().canAdministrateServer()) {
- throw new AuthException("not allowed to set HTTP password directly, "
- + "requires the Administrate Server permission");
- }
+ permissionBackend.user(self).check(ADMINISTRATE_SERVER);
}
String newPassword = input.generate ? generate() : input.httpPassword;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutName.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutName.java
index 5558efc..4cfca2c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutName.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutName.java
@@ -23,8 +23,8 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import java.io.IOException;
+import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton
class PutName implements RestModifyView<ServiceUserResource, Input> {
@@ -37,8 +37,8 @@
@Override
public Response<String> apply(ServiceUserResource rsrc, Input input)
- throws MethodNotAllowedException, ResourceNotFoundException, OrmException,
- IOException {
+ throws MethodNotAllowedException, ResourceNotFoundException, OrmException, IOException,
+ ConfigInvalidException {
return putName.get().apply(rsrc.getUser(), input);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutOwner.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutOwner.java
index 726a4f5..67be740 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutOwner.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutOwner.java
@@ -14,20 +14,22 @@
package com.googlesource.gerrit.plugins.serviceuser;
+import static com.google.gerrit.server.permissions.GlobalPermission.ADMINISTRATE_SERVER;
import static com.googlesource.gerrit.plugins.serviceuser.CreateServiceUser.KEY_OWNER;
import static com.googlesource.gerrit.plugins.serviceuser.CreateServiceUser.USER;
import com.google.common.base.Strings;
import com.google.gerrit.common.data.GroupDescription;
-import com.google.gerrit.common.data.GroupDescriptions;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.common.GroupInfo;
+import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
+import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.config.ConfigResource;
@@ -35,24 +37,22 @@
import com.google.gerrit.server.git.ProjectLevelConfig;
import com.google.gerrit.server.group.GroupJson;
import com.google.gerrit.server.group.GroupsCollection;
+import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import com.googlesource.gerrit.plugins.serviceuser.PutOwner.Input;
-
+import java.io.IOException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Config;
-import java.io.IOException;
-
@Singleton
class PutOwner implements RestModifyView<ServiceUserResource, Input> {
public static class Input {
- @DefaultInput
- public String group;
+ @DefaultInput public String group;
}
private final Provider<GetConfig> getConfig;
@@ -63,12 +63,18 @@
private final MetaDataUpdate.User metaDataUpdateFactory;
private final GroupJson json;
private final Provider<CurrentUser> self;
+ private final PermissionBackend permissionBackend;
@Inject
- PutOwner(Provider<GetConfig> getConfig, GroupsCollection groups,
- @PluginName String pluginName, ProjectCache projectCache,
- MetaDataUpdate.User metaDataUpdateFactory, GroupJson json,
- Provider<CurrentUser> self) {
+ PutOwner(
+ Provider<GetConfig> getConfig,
+ GroupsCollection groups,
+ @PluginName String pluginName,
+ ProjectCache projectCache,
+ MetaDataUpdate.User metaDataUpdateFactory,
+ GroupJson json,
+ Provider<CurrentUser> self,
+ PermissionBackend permissionBackend) {
this.getConfig = getConfig;
this.groups = groups;
this.pluginName = pluginName;
@@ -77,22 +83,22 @@
this.metaDataUpdateFactory = metaDataUpdateFactory;
this.json = json;
this.self = self;
+ this.permissionBackend = permissionBackend;
}
@Override
public Response<GroupInfo> apply(ServiceUserResource rsrc, Input input)
- throws UnprocessableEntityException, RepositoryNotFoundException,
- MethodNotAllowedException, IOException, OrmException, ResourceConflictException {
+ throws UnprocessableEntityException, RepositoryNotFoundException, MethodNotAllowedException,
+ IOException, OrmException, ResourceConflictException, AuthException,
+ PermissionBackendException {
ProjectLevelConfig storage = projectCache.getAllProjects().getConfig(pluginName + ".db");
Boolean ownerAllowed = getConfig.get().apply(new ConfigResource()).allowOwner;
- if ((ownerAllowed == null || !ownerAllowed)
- && !self.get().getCapabilities().canAdministrateServer()) {
- throw new ResourceConflictException("setting owner not allowed");
+ if ((ownerAllowed == null || !ownerAllowed)) {
+ permissionBackend.user(self).check(ADMINISTRATE_SERVER);
}
if (input == null) {
input = new Input();
-
}
Config db = storage.get();
String oldGroup = db.getString(USER, rsrc.getUser().getUserName(), KEY_OWNER);
@@ -101,17 +107,18 @@
db.unset(USER, rsrc.getUser().getUserName(), KEY_OWNER);
} else {
group = groups.parse(input.group);
- if (GroupDescriptions.toAccountGroup(group) == null) {
+ if (!AccountGroup.isInternalGroup(group.getGroupUUID())) {
throw new MethodNotAllowedException();
}
- db.setString(USER, rsrc.getUser().getUserName(), KEY_OWNER,
- group.getGroupUUID().get());
+ db.setString(USER, rsrc.getUser().getUserName(), KEY_OWNER, group.getGroupUUID().get());
}
MetaDataUpdate md = metaDataUpdateFactory.create(allProjects);
md.setMessage("Set owner for service user '" + rsrc.getUser().getUserName() + "'\n");
storage.commit(md);
return group != null
- ? (oldGroup != null ? Response.ok(json.format(group)) : Response.created(json.format(group)))
- : Response.<GroupInfo> none();
+ ? (oldGroup != null
+ ? Response.ok(json.format(group))
+ : Response.created(json.format(group)))
+ : Response.<GroupInfo>none();
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/RefUpdateListener.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/RefUpdateListener.java
index 6d79586..29ab47b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/RefUpdateListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/RefUpdateListener.java
@@ -25,19 +25,17 @@
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
+import java.io.IOException;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
+import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-
@Singleton
class RefUpdateListener implements GitReferenceUpdatedListener {
- private static final Logger log = LoggerFactory
- .getLogger(RefUpdateListener.class);
+ private static final Logger log = LoggerFactory.getLogger(RefUpdateListener.class);
private final CreateServiceUserNotes.Factory serviceUserNotesFactory;
private final GitRepositoryManager repoManager;
@@ -46,9 +44,12 @@
private final String pluginName;
@Inject
- RefUpdateListener(CreateServiceUserNotes.Factory serviceUserNotesFactory,
- GitRepositoryManager repoManager, WorkQueue workQueue,
- PluginConfigFactory cfgFactory, @PluginName String pluginName) {
+ RefUpdateListener(
+ CreateServiceUserNotes.Factory serviceUserNotesFactory,
+ GitRepositoryManager repoManager,
+ WorkQueue workQueue,
+ PluginConfigFactory cfgFactory,
+ @PluginName String pluginName) {
this.serviceUserNotesFactory = serviceUserNotesFactory;
this.repoManager = repoManager;
this.workQueue = workQueue;
@@ -63,32 +64,33 @@
return;
}
- Runnable task = new ProjectRunnable() {
- @Override
- public void run() {
- createServiceUserNotes(event);
- }
+ Runnable task =
+ new ProjectRunnable() {
+ @Override
+ public void run() {
+ createServiceUserNotes(event);
+ }
- @Override
- public Project.NameKey getProjectNameKey() {
- return new Project.NameKey(event.getProjectName());
- }
+ @Override
+ public Project.NameKey getProjectNameKey() {
+ return new Project.NameKey(event.getProjectName());
+ }
- @Override
- public String getRemoteName() {
- return null;
- }
+ @Override
+ public String getRemoteName() {
+ return null;
+ }
- @Override
- public boolean hasCustomizedPrint() {
- return true;
- }
+ @Override
+ public boolean hasCustomizedPrint() {
+ return true;
+ }
- @Override
- public String toString() {
- return "create-service-user-notes";
- }
- };
+ @Override
+ public String toString() {
+ return "create-service-user-notes";
+ }
+ };
if (cfg.getBoolean("createNotesAsync", false)) {
workQueue.getDefaultQueue().submit(task);
} else {
@@ -98,14 +100,14 @@
private void createServiceUserNotes(Event e) {
Project.NameKey projectName = new Project.NameKey(e.getProjectName());
- try (Repository git = repoManager.openRepository(projectName)){
- CreateServiceUserNotes crn = serviceUserNotesFactory.create(
- projectName, git);
- crn.createNotes(e.getRefName(),
+ try (Repository git = repoManager.openRepository(projectName)) {
+ CreateServiceUserNotes crn = serviceUserNotesFactory.create(projectName, git);
+ crn.createNotes(
+ e.getRefName(),
ObjectId.fromString(e.getOldObjectId()),
ObjectId.fromString(e.getNewObjectId()));
crn.commitNotes();
- } catch (IOException | OrmException | ConcurrentRefUpdateException x) {
+ } catch (IOException | OrmException | ConfigInvalidException | ConcurrentRefUpdateException x) {
log.error(x.getMessage(), x);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserCollection.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserCollection.java
index 12d8d1c..9b6f613 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserCollection.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserCollection.java
@@ -14,6 +14,7 @@
package com.googlesource.gerrit.plugins.serviceuser;
+import static com.google.gerrit.server.permissions.GlobalPermission.ADMINISTRATE_SERVER;
import static com.googlesource.gerrit.plugins.serviceuser.CreateServiceUser.KEY_CREATOR_ID;
import static com.googlesource.gerrit.plugins.serviceuser.CreateServiceUser.KEY_OWNER;
import static com.googlesource.gerrit.plugins.serviceuser.CreateServiceUser.USER;
@@ -35,16 +36,19 @@
import com.google.gerrit.server.config.ConfigResource;
import com.google.gerrit.server.git.ProjectLevelConfig;
import com.google.gerrit.server.group.GroupsCollection;
+import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
+import java.io.IOException;
+import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton
-class ServiceUserCollection implements
- ChildCollection<ConfigResource, ServiceUserResource>,
- AcceptsCreate<ConfigResource> {
+class ServiceUserCollection
+ implements ChildCollection<ConfigResource, ServiceUserResource>, AcceptsCreate<ConfigResource> {
private final DynamicMap<RestView<ServiceUserResource>> views;
private final CreateServiceUser.Factory createServiceUserFactory;
@@ -54,13 +58,19 @@
private final ProjectCache projectCache;
private final Provider<CurrentUser> userProvider;
private final GroupsCollection groups;
+ private final PermissionBackend permissionBackend;
@Inject
- ServiceUserCollection(DynamicMap<RestView<ServiceUserResource>> views,
+ ServiceUserCollection(
+ DynamicMap<RestView<ServiceUserResource>> views,
CreateServiceUser.Factory createServiceUserFactory,
- Provider<ListServiceUsers> list, Provider<AccountsCollection> accounts,
- @PluginName String pluginName, ProjectCache projectCache,
- Provider<CurrentUser> userProvider, GroupsCollection groups) {
+ Provider<ListServiceUsers> list,
+ Provider<AccountsCollection> accounts,
+ @PluginName String pluginName,
+ ProjectCache projectCache,
+ Provider<CurrentUser> userProvider,
+ GroupsCollection groups,
+ PermissionBackend permissionBackend) {
this.views = views;
this.createServiceUserFactory = createServiceUserFactory;
this.list = list;
@@ -69,23 +79,24 @@
this.projectCache = projectCache;
this.userProvider = userProvider;
this.groups = groups;
+ this.permissionBackend = permissionBackend;
}
@Override
public ServiceUserResource parse(ConfigResource parent, IdString id)
- throws ResourceNotFoundException, AuthException, OrmException {
+ throws ResourceNotFoundException, AuthException, IOException, OrmException,
+ PermissionBackendException, ConfigInvalidException {
ProjectLevelConfig storage = projectCache.getAllProjects().getConfig(pluginName + ".db");
IdentifiedUser serviceUser = accounts.get().parseId(id.get());
if (serviceUser == null
- || !storage.get().getSubsections(USER)
- .contains(serviceUser.getUserName())) {
+ || !storage.get().getSubsections(USER).contains(serviceUser.getUserName())) {
throw new ResourceNotFoundException(id);
}
CurrentUser user = userProvider.get();
if (user == null || !user.isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
- if (!user.getCapabilities().canAdministrateServer()) {
+ if (!permissionBackend.user(userProvider).testOrFalse(ADMINISTRATE_SERVER)) {
String owner = storage.get().getString(USER, id.get(), KEY_OWNER);
if (owner != null) {
try {
@@ -96,8 +107,9 @@
} catch (UnprocessableEntityException e) {
throw new ResourceNotFoundException(id);
}
- } else if (!((IdentifiedUser)user).getAccountId().equals(
- new Account.Id(storage.get().getInt(USER, id.get(), KEY_CREATOR_ID, -1)))) {
+ } else if (!((IdentifiedUser) user)
+ .getAccountId()
+ .equals(new Account.Id(storage.get().getInt(USER, id.get(), KEY_CREATOR_ID, -1)))) {
throw new ResourceNotFoundException(id);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserMenu.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserMenu.java
index 859a773..2756143 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserMenu.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserMenu.java
@@ -14,34 +14,44 @@
package com.googlesource.gerrit.plugins.serviceuser;
+import static com.google.gerrit.server.permissions.GlobalPermission.ADMINISTRATE_SERVER;
+
import com.google.common.collect.Lists;
import com.google.gerrit.extensions.annotations.PluginName;
+import com.google.gerrit.extensions.api.access.PluginPermission;
import com.google.gerrit.extensions.client.MenuItem;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.webui.TopMenu;
import com.google.gerrit.server.CurrentUser;
-import com.google.gerrit.server.account.CapabilityControl;
import com.google.gerrit.server.config.ConfigResource;
+import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
-
+import java.io.IOException;
import java.util.List;
+import org.eclipse.jgit.errors.ConfigInvalidException;
class ServiceUserMenu implements TopMenu {
private final String pluginName;
private final Provider<CurrentUser> userProvider;
private final List<MenuEntry> menuEntries;
private final Provider<ListServiceUsers> listServiceUsers;
+ private final PermissionBackend permissionBackend;
@Inject
- ServiceUserMenu(@PluginName String pluginName,
+ ServiceUserMenu(
+ @PluginName String pluginName,
Provider<CurrentUser> userProvider,
- Provider<ListServiceUsers> listServiceUsers) {
+ Provider<ListServiceUsers> listServiceUsers,
+ PermissionBackend permissionBackend)
+ throws IOException, PermissionBackendException, ConfigInvalidException {
this.pluginName = pluginName;
this.userProvider = userProvider;
this.listServiceUsers = listServiceUsers;
menuEntries = Lists.newArrayList();
+ this.permissionBackend = permissionBackend;
List<MenuItem> peopleItems = Lists.newArrayListWithExpectedSize(2);
if (canCreateServiceUser()) {
@@ -57,15 +67,16 @@
private boolean canCreateServiceUser() {
if (userProvider.get().isIdentifiedUser()) {
- CapabilityControl ctl = userProvider.get().getCapabilities();
- return ctl.canPerform(pluginName + "-" + CreateServiceUserCapability.ID)
- || ctl.canAdministrateServer();
- } else {
- return false;
+ return permissionBackend
+ .user(userProvider)
+ .testOrFalse(new PluginPermission(pluginName, CreateServiceUserCapability.ID))
+ || permissionBackend.user(userProvider).testOrFalse(ADMINISTRATE_SERVER);
}
+ return false;
}
- private boolean hasServiceUser() {
+ private boolean hasServiceUser()
+ throws PermissionBackendException, IOException, ConfigInvalidException {
try {
return !listServiceUsers.get().apply(new ConfigResource()).isEmpty();
} catch (AuthException | OrmException e) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserResolver.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserResolver.java
index fd360cc..734f47e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserResolver.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ServiceUserResolver.java
@@ -33,15 +33,14 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
import com.googlesource.gerrit.plugins.serviceuser.GetServiceUser.ServiceUserInfo;
-
-import org.eclipse.jgit.lib.PersonIdent;
-
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.lib.PersonIdent;
@Singleton
class ServiceUserResolver {
@@ -54,11 +53,14 @@
private final AccountCache accountCache;
@Inject
- ServiceUserResolver(AccountResolver resolver,
+ ServiceUserResolver(
+ AccountResolver resolver,
IdentifiedUser.GenericFactory genericUserFactory,
Provider<GetServiceUser> getServiceUser,
- Provider<ListMembers> listMembers, SchemaFactory<ReviewDb> schema,
- ThreadLocalRequestContext tl, AccountCache accountCache) {
+ Provider<ListMembers> listMembers,
+ SchemaFactory<ReviewDb> schema,
+ ThreadLocalRequestContext tl,
+ AccountCache accountCache) {
this.resolver = resolver;
this.genericUserFactory = genericUserFactory;
this.getServiceUser = getServiceUser;
@@ -69,24 +71,23 @@
}
ServiceUserInfo getAsServiceUser(PersonIdent committerIdent)
- throws OrmException {
+ throws ConfigInvalidException, IOException, OrmException {
StringBuilder committer = new StringBuilder();
committer.append(committerIdent.getName());
committer.append(" <");
committer.append(committerIdent.getEmailAddress());
committer.append("> ");
- try (ReviewDb db = schema.open()) {
- Account account = resolver.find(db, committer.toString());
- if (account == null) {
- return null;
- }
- try {
- return getServiceUser.get().apply(
- new ServiceUserResource(genericUserFactory.create(account.getId())));
- } catch (ResourceNotFoundException e) {
- return null;
- }
+ Account account = resolver.find(committer.toString());
+ if (account == null) {
+ return null;
+ }
+ try {
+ return getServiceUser
+ .get()
+ .apply(new ServiceUserResource(genericUserFactory.create(account.getId())));
+ } catch (ResourceNotFoundException e) {
+ return null;
}
}
@@ -96,47 +97,50 @@
}
try (ReviewDb db = schema.open()) {
- RequestContext context = new RequestContext() {
- @Override
- public CurrentUser getUser() {
- return new CurrentUser(null) {
+ RequestContext context =
+ new RequestContext() {
+ @Override
+ public CurrentUser getUser() {
+ return new CurrentUser() {
+
+ @Override
+ public GroupMembership getEffectiveGroups() {
+ return new GroupMembership() {
+ @Override
+ public Set<AccountGroup.UUID> intersection(
+ Iterable<AccountGroup.UUID> groupIds) {
+ return null;
+ }
+
+ @Override
+ public Set<AccountGroup.UUID> getKnownGroups() {
+ return null;
+ }
+
+ @Override
+ public boolean containsAnyOf(Iterable<AccountGroup.UUID> groupIds) {
+ return true;
+ }
+
+ @Override
+ public boolean contains(AccountGroup.UUID groupId) {
+ return true;
+ }
+ };
+ }
+ };
+ }
@Override
- public GroupMembership getEffectiveGroups() {
- return new GroupMembership() {
+ public Provider<ReviewDb> getReviewDbProvider() {
+ return new Provider<ReviewDb>() {
@Override
- public Set<AccountGroup.UUID> intersection(Iterable<AccountGroup.UUID> groupIds) {
- return null;
- }
-
- @Override
- public Set<AccountGroup.UUID> getKnownGroups() {
- return null;
- }
-
- @Override
- public boolean containsAnyOf(Iterable<AccountGroup.UUID> groupIds) {
- return true;
- }
-
- @Override
- public boolean contains(AccountGroup.UUID groupId) {
- return true;
+ public ReviewDb get() {
+ return db;
}
};
}
};
- }
-
- @Override
- public Provider<ReviewDb> getReviewDbProvider() {
- return new Provider<ReviewDb>() {
- @Override
- public ReviewDb get() {
- return db;
- }};
- }
- };
RequestContext old = tl.setContext(context);
try {
ListMembers lm = listMembers.get();
@@ -152,8 +156,7 @@
}
}
- List<AccountInfo> listActiveOwners(ServiceUserInfo serviceUser)
- throws OrmException {
+ List<AccountInfo> listActiveOwners(ServiceUserInfo serviceUser) throws OrmException {
List<AccountInfo> activeOwners = new ArrayList<>();
for (AccountInfo owner : listOwners(serviceUser)) {
AccountState accountState = accountCache.get(new Account.Id(owner._accountId));
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/SshKeys.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/SshKeys.java
index 74ea24f..ac64ebb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/SshKeys.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/SshKeys.java
@@ -23,20 +23,18 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
+import java.io.IOException;
import org.eclipse.jgit.errors.ConfigInvalidException;
-import java.io.IOException;
-
@Singleton
-class SshKeys implements
- ChildCollection<ServiceUserResource, ServiceUserResource.SshKey> {
+class SshKeys implements ChildCollection<ServiceUserResource, ServiceUserResource.SshKey> {
private final DynamicMap<RestView<ServiceUserResource.SshKey>> views;
private final Provider<GetSshKeys> list;
private final Provider<com.google.gerrit.server.account.SshKeys> sshKeys;
@Inject
- SshKeys(DynamicMap<RestView<ServiceUserResource.SshKey>> views,
+ SshKeys(
+ DynamicMap<RestView<ServiceUserResource.SshKey>> views,
Provider<GetSshKeys> list,
Provider<com.google.gerrit.server.account.SshKeys> sshKeys) {
this.views = views;
@@ -51,8 +49,7 @@
@Override
public ServiceUserResource.SshKey parse(ServiceUserResource parent, IdString id)
- throws ResourceNotFoundException, OrmException, IOException,
- ConfigInvalidException {
+ throws ResourceNotFoundException, OrmException, IOException, ConfigInvalidException {
return new ServiceUserResource.SshKey(sshKeys.get().parse(parent.getUser(), id));
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ValidateServiceUserCommits.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ValidateServiceUserCommits.java
index c0684e7..f7b1179 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ValidateServiceUserCommits.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/ValidateServiceUserCommits.java
@@ -24,13 +24,12 @@
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
import com.googlesource.gerrit.plugins.serviceuser.GetServiceUser.ServiceUserInfo;
-
-import org.eclipse.jgit.lib.PersonIdent;
-
+import java.io.IOException;
import java.util.Collections;
import java.util.List;
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.lib.PersonIdent;
@Singleton
class ValidateServiceUserCommits implements CommitValidationListener {
@@ -38,40 +37,40 @@
private final AccountCache accountCache;
@Inject
- ValidateServiceUserCommits(ServiceUserResolver serviceUserResolver,
- AccountCache accountCache) {
+ ValidateServiceUserCommits(ServiceUserResolver serviceUserResolver, AccountCache accountCache) {
this.serviceUserResolver = serviceUserResolver;
this.accountCache = accountCache;
}
@Override
- public List<CommitValidationMessage> onCommitReceived(
- CommitReceivedEvent receiveEvent) throws CommitValidationException {
+ public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
+ throws CommitValidationException {
try {
PersonIdent committer = receiveEvent.commit.getCommitterIdent();
- ServiceUserInfo serviceUser =
- serviceUserResolver.getAsServiceUser(committer);
+ ServiceUserInfo serviceUser = serviceUserResolver.getAsServiceUser(committer);
if (serviceUser != null) {
if (serviceUser.owner != null
&& serviceUserResolver.listActiveOwners(serviceUser).isEmpty()) {
- throw new CommitValidationException(String.format(
- "Commit %s of service user %s (%s) is rejected because "
- + "all service user owner accounts are inactive.",
- receiveEvent.commit.getId().getName(), committer.getName(),
- committer.getEmailAddress()));
- } else {
- AccountState creator = accountCache.get(
- new Account.Id(serviceUser.createdBy._accountId));
- if (creator == null || !creator.getAccount().isActive()) {
- throw new CommitValidationException(String.format(
- "Commit %s of service user %s (%s) is rejected because "
- + "the account of the service creator is inactive.",
- receiveEvent.commit.getId().getName(), committer.getName(),
- committer.getEmailAddress()));
- }
+ throw new CommitValidationException(
+ String.format(
+ "Commit %s of service user %s (%s) is rejected because "
+ + "all service user owner accounts are inactive.",
+ receiveEvent.commit.getId().getName(),
+ committer.getName(),
+ committer.getEmailAddress()));
+ }
+ AccountState creator = accountCache.get(new Account.Id(serviceUser.createdBy._accountId));
+ if (creator == null || !creator.getAccount().isActive()) {
+ throw new CommitValidationException(
+ String.format(
+ "Commit %s of service user %s (%s) is rejected because "
+ + "the account of the service creator is inactive.",
+ receiveEvent.commit.getId().getName(),
+ committer.getName(),
+ committer.getEmailAddress()));
}
}
- } catch (OrmException e) {
+ } catch (IOException | OrmException | ConfigInvalidException e) {
throw new CommitValidationException(
"Internal error while checking for service user commits.", e);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/AccountCapabilities.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/AccountCapabilities.java
index c705d53..4a377d6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/AccountCapabilities.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/AccountCapabilities.java
@@ -18,17 +18,13 @@
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
-/** Capabilities the caller has from {@code /accounts/self/capabilities}. */
+/** Capabilities the caller has from {@code /accounts/self/capabilities}. */
public class AccountCapabilities extends JavaScriptObject {
public static void all(AsyncCallback<AccountCapabilities> cb, String... filter) {
- new RestApi("/accounts/self/capabilities")
- .addParameter("q", filter)
- .get(cb);
+ new RestApi("/accounts/self/capabilities").addParameter("q", filter).get(cb);
}
- protected AccountCapabilities() {
- }
+ protected AccountCapabilities() {}
- public final native boolean canPerform(String name)
- /*-{ return this[name] ? true : false; }-*/;
+ public final native boolean canPerform(String name)/*-{ return this[name] ? true : false; }-*/ ;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/AccountInfo.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/AccountInfo.java
index 962b2e9..ffc1953 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/AccountInfo.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/AccountInfo.java
@@ -18,10 +18,12 @@
public class AccountInfo extends JavaScriptObject {
public final native int _account_id() /*-{ return this._account_id || 0; }-*/;
+
public final native String name() /*-{ return this.name; }-*/;
+
public final native String username() /*-{ return this.username; }-*/;
+
public final native String email() /*-{ return this.email; }-*/;
- protected AccountInfo() {
- }
+ protected AccountInfo() {}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ConfigInfo.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ConfigInfo.java
index 7ba2428..6291319 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ConfigInfo.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ConfigInfo.java
@@ -17,26 +17,41 @@
import com.google.gerrit.client.rpc.NativeMap;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
-
import java.util.List;
public class ConfigInfo extends JavaScriptObject {
final native String getInfoMessage() /*-{ return this.info }-*/;
+
final native String getOnSuccessMessage() /*-{ return this.on_success }-*/;
+
final native boolean getAllowEmail() /*-{ return this.allow_email ? true : false; }-*/;
- final native boolean getAllowHttpPassword() /*-{ return this.allow_http_password ? true : false; }-*/;
+
+ final native boolean
+ getAllowHttpPassword() /*-{ return this.allow_http_password ? true : false; }-*/;
+
final native boolean getAllowOwner() /*-{ return this.allow_owner ? true : false; }-*/;
+
final native boolean getCreateNotes() /*-{ return this.create_notes ? true : false; }-*/;
- final native boolean getCreateNotesAsync() /*-{ return this.create_notes_async ? true : false; }-*/;
+
+ final native boolean
+ getCreateNotesAsync() /*-{ return this.create_notes_async ? true : false; }-*/;
+
final native JsArrayString getBlockedNames() /*-{ return this.blocked_names; }-*/;
+
final native NativeMap<GroupInfo> getGroups() /*-{ return this.groups; }-*/;
final native void setInfoMessage(String s) /*-{ this.info = s; }-*/;
+
final native void setOnSuccessMessage(String s) /*-{ this.on_success = s; }-*/;
+
final native void setAllowEmail(boolean s) /*-{ this.allow_email = s; }-*/;
+
final native void setAllowHttpPassword(boolean s) /*-{ this.allow_http_password = s; }-*/;
+
final native void setAllowOwner(boolean s) /*-{ this.allow_owner = s; }-*/;
+
final native void setCreateNotes(boolean s) /*-{ this.create_notes = s; }-*/;
+
final native void setCreateNotesAsync(boolean s) /*-{ this.create_notes_async = s; }-*/;
final void setBlockedNames(List<String> blockedNames) {
@@ -44,9 +59,10 @@
for (String n : blockedNames) {
addBlockedName(n);
}
-
}
+
final native void initBlockedNames() /*-{ this.blocked_names = []; }-*/;
+
final native void addBlockedName(String n) /*-{ this.blocked_names.push(n); }-*/;
final void setGroups(List<String> groups) {
@@ -54,9 +70,10 @@
for (String g : groups) {
addGroup(g);
}
-
}
+
final native void initGroups() /*-{ this.groups = []; }-*/;
+
final native void addGroup(String g) /*-{ this.groups.push(g); }-*/;
static ConfigInfo create() {
@@ -64,6 +81,5 @@
return g;
}
- protected ConfigInfo() {
- }
+ protected ConfigInfo() {}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/CreateServiceUserScreen.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/CreateServiceUserScreen.java
index 65ce461..c57eb5f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/CreateServiceUserScreen.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/CreateServiceUserScreen.java
@@ -55,28 +55,32 @@
Panel usernamePanel = new VerticalPanel();
usernamePanel.add(new Label("Username:"));
- usernameTxt = new TextBox() {
- @Override
- public void onBrowserEvent(Event event) {
- super.onBrowserEvent(event);
- if (event.getTypeInt() == Event.ONPASTE) {
- Scheduler.get().scheduleDeferred(new ScheduledCommand() {
- @Override
- public void execute() {
- if (getValue().trim().length() != 0) {
- setEnabled(true);
- }
+ usernameTxt =
+ new TextBox() {
+ @Override
+ public void onBrowserEvent(Event event) {
+ super.onBrowserEvent(event);
+ if (event.getTypeInt() == Event.ONPASTE) {
+ Scheduler.get()
+ .scheduleDeferred(
+ new ScheduledCommand() {
+ @Override
+ public void execute() {
+ if (getValue().trim().length() != 0) {
+ setEnabled(true);
+ }
+ }
+ });
}
- });
- }
- }
- };
- usernameTxt.addKeyPressHandler(new KeyPressHandler() {
- @Override
- public void onKeyPress(final KeyPressEvent event) {
- event.stopPropagation();
- }
- });
+ }
+ };
+ usernameTxt.addKeyPressHandler(
+ new KeyPressHandler() {
+ @Override
+ public void onKeyPress(final KeyPressEvent event) {
+ event.stopPropagation();
+ }
+ });
usernameTxt.sinkEvents(Event.ONPASTE);
usernameTxt.setVisibleLength(40);
usernamePanel.add(usernameTxt);
@@ -86,12 +90,13 @@
sshKeyPanel.add(new Label("Public SSH Key:"));
sshKeyPanel.add(new SshKeyHelpPanel());
sshKeyTxt = new TextArea();
- sshKeyTxt.addKeyPressHandler(new KeyPressHandler() {
- @Override
- public void onKeyPress(final KeyPressEvent event) {
- event.stopPropagation();
- }
- });
+ sshKeyTxt.addKeyPressHandler(
+ new KeyPressHandler() {
+ @Override
+ public void onKeyPress(final KeyPressEvent event) {
+ event.stopPropagation();
+ }
+ });
sshKeyTxt.setVisibleLines(12);
sshKeyTxt.setCharacterWidth(80);
sshKeyTxt.getElement().setPropertyBoolean("spellcheck", false);
@@ -103,12 +108,13 @@
final Button createButton = new Button("Create");
createButton.addStyleName("serviceuser-createButton");
- createButton.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(final ClickEvent event) {
- doCreate();
- }
- });
+ createButton.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(final ClickEvent event) {
+ doCreate();
+ }
+ });
buttons.add(createButton);
createButton.setEnabled(false);
new OnEditEnabler(createButton, usernameTxt);
@@ -116,54 +122,61 @@
usernameTxt.setFocus(true);
createButton.setEnabled(false);
- new RestApi("config").id("server").view(Plugin.get().getPluginName(), "config")
- .get(new AsyncCallback<ConfigInfo>() {
- @Override
- public void onSuccess(ConfigInfo info) {
- onSuccessMessage = info.getOnSuccessMessage();
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "config")
+ .get(
+ new AsyncCallback<ConfigInfo>() {
+ @Override
+ public void onSuccess(ConfigInfo info) {
+ onSuccessMessage = info.getOnSuccessMessage();
- String infoMessage = info.getInfoMessage();
- if (infoMessage != null && !"".equals(infoMessage)) {
- insert(new HTML(infoMessage), 0);
- }
+ String infoMessage = info.getInfoMessage();
+ if (infoMessage != null && !"".equals(infoMessage)) {
+ insert(new HTML(infoMessage), 0);
+ }
- if (info.getAllowEmail()) {
- Panel emailPanel = new VerticalPanel();
- emailPanel.add(new Label("Email:"));
- emailTxt = new TextBox() {
- @Override
- public void onBrowserEvent(Event event) {
- super.onBrowserEvent(event);
- if (event.getTypeInt() == Event.ONPASTE) {
- Scheduler.get().scheduleDeferred(new ScheduledCommand() {
- @Override
- public void execute() {
- if (getValue().trim().length() != 0) {
- setEnabled(true);
+ if (info.getAllowEmail()) {
+ Panel emailPanel = new VerticalPanel();
+ emailPanel.add(new Label("Email:"));
+ emailTxt =
+ new TextBox() {
+ @Override
+ public void onBrowserEvent(Event event) {
+ super.onBrowserEvent(event);
+ if (event.getTypeInt() == Event.ONPASTE) {
+ Scheduler.get()
+ .scheduleDeferred(
+ new ScheduledCommand() {
+ @Override
+ public void execute() {
+ if (getValue().trim().length() != 0) {
+ setEnabled(true);
+ }
+ }
+ });
+ }
}
- }
- });
- }
+ };
+ emailTxt.addKeyPressHandler(
+ new KeyPressHandler() {
+ @Override
+ public void onKeyPress(final KeyPressEvent event) {
+ event.stopPropagation();
+ }
+ });
+ emailTxt.sinkEvents(Event.ONPASTE);
+ emailTxt.setVisibleLength(40);
+ emailPanel.add(emailTxt);
+ insert(emailPanel, 2);
}
- };
- emailTxt.addKeyPressHandler(new KeyPressHandler() {
- @Override
- public void onKeyPress(final KeyPressEvent event) {
- event.stopPropagation();
- }
- });
- emailTxt.sinkEvents(Event.ONPASTE);
- emailTxt.setVisibleLength(40);
- emailPanel.add(emailTxt);
- insert(emailPanel, 2);
- }
- }
+ }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
}
private void doCreate() {
@@ -178,44 +191,49 @@
if (emailTxt != null) {
in.email(emailTxt.getValue().trim());
}
- new RestApi("config").id("server").view("serviceuser", "serviceusers")
- .id(username).post(in, new AsyncCallback<JavaScriptObject>() {
+ new RestApi("config")
+ .id("server")
+ .view("serviceuser", "serviceusers")
+ .id(username)
+ .post(
+ in,
+ new AsyncCallback<JavaScriptObject>() {
- @Override
- public void onSuccess(JavaScriptObject result) {
- clearForm();
- Plugin.get().go("/x/" + Plugin.get().getName() + "/user/" + username);
+ @Override
+ public void onSuccess(JavaScriptObject result) {
+ clearForm();
+ Plugin.get().go("/x/" + Plugin.get().getName() + "/user/" + username);
- final DialogBox successDialog = new DialogBox();
- successDialog.setText("Service User Created");
- successDialog.setAnimationEnabled(true);
+ final DialogBox successDialog = new DialogBox();
+ successDialog.setText("Service User Created");
+ successDialog.setAnimationEnabled(true);
- Panel p = new VerticalPanel();
- p.setStyleName("serviceuser-panel");
- p.add(new Label("The service user '" + username + "' was created."));
- Button okButton = new Button("OK");
- okButton.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- successDialog.hide();
- }
- });
+ Panel p = new VerticalPanel();
+ p.setStyleName("serviceuser-panel");
+ p.add(new Label("The service user '" + username + "' was created."));
+ Button okButton = new Button("OK");
+ okButton.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ successDialog.hide();
+ }
+ });
- if (onSuccessMessage != null && !"".equals(onSuccessMessage)) {
- p.add(new HTML(onSuccessMessage));
- }
+ if (onSuccessMessage != null && !"".equals(onSuccessMessage)) {
+ p.add(new HTML(onSuccessMessage));
+ }
- p.add(okButton);
- successDialog.add(p);
+ p.add(okButton);
+ successDialog.add(p);
- successDialog.center();
- successDialog.show();
- }
+ successDialog.center();
+ successDialog.show();
+ }
- @Override
- public void onFailure(Throwable caught) {
- }
- });
+ @Override
+ public void onFailure(Throwable caught) {}
+ });
}
private void clearForm() {
@@ -228,6 +246,7 @@
private static class ServiceUserInput extends JavaScriptObject {
final native void ssh_key(String s) /*-{ this.ssh_key = s; }-*/;
+
final native void email(String e) /*-{ this.email = e; }-*/;
static ServiceUserInput create() {
@@ -235,7 +254,6 @@
return g;
}
- protected ServiceUserInput() {
- }
+ protected ServiceUserInput() {}
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/EditableValue.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/EditableValue.java
index eda6b4f..0ab741f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/EditableValue.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/EditableValue.java
@@ -65,44 +65,48 @@
OnEditEnabler e = new OnEditEnabler(save);
e.listenTo(input);
- edit.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- labelWidget.setVisible(false);
- edit.setVisible(false);
- input.setVisible(true);
- input.setFocus(true);
- save.setVisible(true);
- if (warning != null) {
- warning.setVisible(true);
- }
- cancel.setVisible(true);
- }
- });
- save.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- save.setEnabled(false);
- save(serviceUser, input.getValue().trim());
- }
- });
- input.addKeyPressHandler(new KeyPressHandler() {
- @Override
- public void onKeyPress(KeyPressEvent event) {
- if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
- save.setEnabled(false);
- save(serviceUser, input.getValue().trim());
- } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
- cancel();
- }
- }
- });
- cancel.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- cancel();
- }
- });
+ edit.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ labelWidget.setVisible(false);
+ edit.setVisible(false);
+ input.setVisible(true);
+ input.setFocus(true);
+ save.setVisible(true);
+ if (warning != null) {
+ warning.setVisible(true);
+ }
+ cancel.setVisible(true);
+ }
+ });
+ save.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ save.setEnabled(false);
+ save(serviceUser, input.getValue().trim());
+ }
+ });
+ input.addKeyPressHandler(
+ new KeyPressHandler() {
+ @Override
+ public void onKeyPress(KeyPressEvent event) {
+ if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
+ save.setEnabled(false);
+ save(serviceUser, input.getValue().trim());
+ } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
+ cancel();
+ }
+ }
+ });
+ cancel.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ cancel();
+ }
+ });
add(labelWidget);
add(edit);
@@ -116,9 +120,9 @@
edit.setVisible(true);
input.setVisible(false);
if (labelWidget instanceof Label) {
- input.setValue(((Label)labelWidget).getText());
+ input.setValue(((Label) labelWidget).getText());
} else {
- input.setValue(((Anchor)labelWidget).getText());
+ input.setValue(((Anchor) labelWidget).getText());
}
save.setVisible(false);
save.setEnabled(false);
@@ -139,9 +143,9 @@
protected void updateValue(String newValue) {
if (labelWidget instanceof Label) {
- ((Label)labelWidget).setText(newValue);
+ ((Label) labelWidget).setText(newValue);
} else {
- ((Anchor)labelWidget).setText(newValue);
+ ((Anchor) labelWidget).setText(newValue);
}
labelWidget.setVisible(true);
edit.setVisible(true);
@@ -157,7 +161,7 @@
protected void updateHref(String newHref) {
if (labelWidget instanceof Anchor) {
- ((Anchor)labelWidget).setHref(newHref);
+ ((Anchor) labelWidget).setHref(newHref);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/GroupInfo.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/GroupInfo.java
index 67bf13c..b398092 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/GroupInfo.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/GroupInfo.java
@@ -18,8 +18,8 @@
public class GroupInfo extends JavaScriptObject {
public final native String name() /*-{ return this.name; }-*/;
+
public final native String url() /*-{ return this.url; }-*/;
- protected GroupInfo() {
- }
+ protected GroupInfo() {}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/HttpPasswordInput.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/HttpPasswordInput.java
index 1a95251..5549597 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/HttpPasswordInput.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/HttpPasswordInput.java
@@ -23,6 +23,5 @@
return createObject().cast();
}
- protected HttpPasswordInput() {
- }
+ protected HttpPasswordInput() {}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/OnEditEnabler.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/OnEditEnabler.java
index 233ca30..815962c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/OnEditEnabler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/OnEditEnabler.java
@@ -34,22 +34,23 @@
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBoxBase;
import com.google.gwt.user.client.ui.ValueBoxBase;
-
import java.util.HashMap;
import java.util.Map;
-
-/** Enables a FocusWidget (e.g. a Button) if an edit is detected from any
- * registered input widget.
+/**
+ * Enables a FocusWidget (e.g. a Button) if an edit is detected from any registered input widget.
*/
-public class OnEditEnabler implements KeyPressHandler, KeyDownHandler,
- MouseUpHandler, ChangeHandler, ValueChangeHandler<Object> {
+public class OnEditEnabler
+ implements KeyPressHandler,
+ KeyDownHandler,
+ MouseUpHandler,
+ ChangeHandler,
+ ValueChangeHandler<Object> {
private final FocusWidget widget;
private Map<TextBoxBase, String> strings = new HashMap<>();
private String originalValue;
-
// The first parameter to the constructors must be the FocusWidget to enable,
// subsequent parameters are widgets to listenTo.
@@ -73,7 +74,6 @@
widget = w;
}
-
// Register input widgets to be listened to
public void listenTo(final TextBoxBase tb) {
@@ -88,12 +88,13 @@
// up to date with non-user updates of the text (calls to
// setText()...) and also up to date with user changes which
// occured after enabling "widget".
- tb.addFocusHandler(new FocusHandler() {
- @Override
- public void onFocus(FocusEvent event) {
- strings.put(tb, tb.getText().trim());
- }
- });
+ tb.addFocusHandler(
+ new FocusHandler() {
+ @Override
+ public void onFocus(FocusEvent event) {
+ strings.put(tb, tb.getText().trim());
+ }
+ });
// CTRL-V Pastes in Chrome seem only detectable via BrowserEvents or
// KeyDownEvents, the latter is better.
@@ -109,7 +110,6 @@
cb.addValueChangeHandler((ValueChangeHandler) this);
}
-
// Handlers
@Override
@@ -139,19 +139,21 @@
}
private void on(final GwtEvent<?> e) {
- if (widget.isEnabled() ||
- ! (e.getSource() instanceof FocusWidget) ||
- ! ((FocusWidget) e.getSource()).isEnabled() ) {
+ if (widget.isEnabled()
+ || !(e.getSource() instanceof FocusWidget)
+ || !((FocusWidget) e.getSource()).isEnabled()) {
if (e.getSource() instanceof ValueBoxBase) {
final TextBoxBase box = ((TextBoxBase) e.getSource());
- Scheduler.get().scheduleDeferred(new ScheduledCommand() {
- @Override
- public void execute() {
- if (box.getValue().trim().equals(originalValue)) {
- widget.setEnabled(false);
- }
- }
- });
+ Scheduler.get()
+ .scheduleDeferred(
+ new ScheduledCommand() {
+ @Override
+ public void execute() {
+ if (box.getValue().trim().equals(originalValue)) {
+ widget.setEnabled(false);
+ }
+ }
+ });
}
return;
}
@@ -168,17 +170,19 @@
private void onTextBoxBase(final TextBoxBase tb) {
// The text appears to not get updated until the handlers complete.
- Scheduler.get().scheduleDeferred(new ScheduledCommand() {
- @Override
- public void execute() {
- String orig = strings.get(tb);
- if (orig == null) {
- orig = "";
- }
- if (! orig.equals(tb.getText().trim())) {
- widget.setEnabled(true);
- }
- }
- });
+ Scheduler.get()
+ .scheduleDeferred(
+ new ScheduledCommand() {
+ @Override
+ public void execute() {
+ String orig = strings.get(tb);
+ if (orig == null) {
+ orig = "";
+ }
+ if (!orig.equals(tb.getText().trim())) {
+ widget.setEnabled(true);
+ }
+ }
+ });
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserInfo.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserInfo.java
index b412e95..96c543d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserInfo.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserInfo.java
@@ -20,24 +20,28 @@
public final String getDisplayName() {
if (created_by().username() != null) {
return created_by().username();
- } else {
- if (created_by()._account_id() != -1) {
- return Integer.toString(created_by()._account_id());
- } else {
- return "N/A";
- }
}
+ if (created_by()._account_id() != -1) {
+ return Integer.toString(created_by()._account_id());
+ }
+ return "N/A";
}
public final native int _account_id() /*-{ return this._account_id || 0; }-*/;
+
public final native String name() /*-{ return this.name; }-*/;
+
public final native String username() /*-{ return this.username; }-*/;
+
public final native String email() /*-{ return this.email; }-*/;
+
public final native AccountInfo created_by() /*-{ return this.created_by; }-*/;
+
public final native String created_at() /*-{ return this.created_at; }-*/;
+
public final native boolean active() /*-{ return this.inactive ? false : true; }-*/;
+
public final native GroupInfo owner() /*-{ return this.owner; }-*/;
- protected ServiceUserInfo() {
- }
+ protected ServiceUserInfo() {}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserListScreen.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserListScreen.java
index aae6a29..5c30bea 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserListScreen.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserListScreen.java
@@ -37,19 +37,23 @@
ServiceUserListScreen() {
setStyleName("serviceuser-panel");
- new RestApi("config").id("server").view(Plugin.get().getPluginName(), "serviceusers")
- .get(NativeMap.copyKeysIntoChildren("username",
- new AsyncCallback<NativeMap<ServiceUserInfo>>() {
- @Override
- public void onSuccess(NativeMap<ServiceUserInfo> info) {
- display(info);
- }
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .get(
+ NativeMap.copyKeysIntoChildren(
+ "username",
+ new AsyncCallback<NativeMap<ServiceUserInfo>>() {
+ @Override
+ public void onSuccess(NativeMap<ServiceUserInfo> info) {
+ display(info);
+ }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- }));
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ }));
}
private void display(NativeMap<ServiceUserInfo> info) {
@@ -80,15 +84,16 @@
fmt.addStyleName(row, 0, "leftMostCell");
}
- t.setWidget(row, 0, new InlineHyperlink(
- username, "/x/" + Plugin.get().getName() + "/user/" + username));
+ t.setWidget(
+ row,
+ 0,
+ new InlineHyperlink(username, "/x/" + Plugin.get().getName() + "/user/" + username));
t.setText(row, 1, a.name());
t.setText(row, 2, a.email());
if (a.owner() != null) {
if (a.owner().url() != null) {
- t.setWidget(row, 3,
- new Anchor(a.owner().name(), a.owner().url()));
+ t.setWidget(row, 3, new Anchor(a.owner().name(), a.owner().url()));
} else {
t.setText(row, 3, a.owner().name());
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserScreen.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserScreen.java
index 1886c72..78cb65e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserScreen.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserScreen.java
@@ -46,61 +46,46 @@
ServiceUserScreen(final String serviceUser) {
setStyleName("serviceuser-panel");
- new RestApi("config").id("server").view(Plugin.get().getPluginName(), "serviceusers")
- .id(serviceUser).get(new AsyncCallback<ServiceUserInfo>() {
- @Override
- public void onSuccess(final ServiceUserInfo serviceUserInfo) {
- new RestApi("config").id("server")
- .view(Plugin.get().getPluginName(), "config")
- .get(new AsyncCallback<ConfigInfo>() {
- @Override
- public void onSuccess(final ConfigInfo configInfo) {
- AccountCapabilities.all(new AsyncCallback<AccountCapabilities>() {
- @Override
- public void onSuccess(AccountCapabilities ac) {
- boolean isAdmin = ac.canPerform("administrateServer");
- display(serviceUserInfo,
- configInfo.getAllowEmail() || isAdmin,
- configInfo.getAllowOwner() || isAdmin,
- configInfo.getAllowHttpPassword() || isAdmin);
- }
-
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- }, "administrateServer");
- }
-
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
- }
-
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
- }
-
- private void display(ServiceUserInfo info,
- boolean allowEmail, boolean allowOwner, boolean allowHttpPassword) {
- MyTable t = new MyTable();
- t.setStyleName("serviceuser-serviceUserInfoTable");
- t.addRow("Account State", createActiveToggle(info));
- t.addRow("Username", info.username());
- t.addRow("Full Name", new EditableValue(info.username(), info.name()) {
- @Override
- protected void save(String serviceUser, final String newValue) {
- new RestApi("config").id("server")
- .view(Plugin.get().getPluginName(), "serviceusers").id(serviceUser)
- .view("name").put(newValue, new AsyncCallback<NativeString>() {
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(serviceUser)
+ .get(
+ new AsyncCallback<ServiceUserInfo>() {
@Override
- public void onSuccess(NativeString result) {
- updateValue(newValue);
+ public void onSuccess(final ServiceUserInfo serviceUserInfo) {
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "config")
+ .get(
+ new AsyncCallback<ConfigInfo>() {
+ @Override
+ public void onSuccess(final ConfigInfo configInfo) {
+ AccountCapabilities.all(
+ new AsyncCallback<AccountCapabilities>() {
+ @Override
+ public void onSuccess(AccountCapabilities ac) {
+ boolean isAdmin = ac.canPerform("administrateServer");
+ display(
+ serviceUserInfo,
+ configInfo.getAllowEmail() || isAdmin,
+ configInfo.getAllowOwner() || isAdmin,
+ configInfo.getAllowHttpPassword() || isAdmin);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ },
+ "administrateServer");
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
}
@Override
@@ -108,34 +93,69 @@
// never invoked
}
});
- }
- });
- if (allowEmail) {
- t.addRow("Email Address", new EditableValue(info.username(), info.email()) {
- @Override
- protected void save(String serviceUser, final String newValue) {
- new RestApi("config").id("server")
- .view(Plugin.get().getPluginName(), "serviceusers").id(serviceUser)
- .view("email").put(newValue, new AsyncCallback<NativeString>() {
- @Override
- public void onSuccess(NativeString result) {
- updateValue(newValue);
- }
+ }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
- }
- });
+ private void display(
+ ServiceUserInfo info, boolean allowEmail, boolean allowOwner, boolean allowHttpPassword) {
+ MyTable t = new MyTable();
+ t.setStyleName("serviceuser-serviceUserInfoTable");
+ t.addRow("Account State", createActiveToggle(info));
+ t.addRow("Username", info.username());
+ t.addRow(
+ "Full Name",
+ new EditableValue(info.username(), info.name()) {
+ @Override
+ protected void save(String serviceUser, final String newValue) {
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(serviceUser)
+ .view("name")
+ .put(
+ newValue,
+ new AsyncCallback<NativeString>() {
+ @Override
+ public void onSuccess(NativeString result) {
+ updateValue(newValue);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
+ }
+ });
+ if (allowEmail) {
+ t.addRow(
+ "Email Address",
+ new EditableValue(info.username(), info.email()) {
+ @Override
+ protected void save(String serviceUser, final String newValue) {
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(serviceUser)
+ .view("email")
+ .put(
+ newValue,
+ new AsyncCallback<NativeString>() {
+ @Override
+ public void onSuccess(NativeString result) {
+ updateValue(newValue);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
+ }
+ });
} else {
t.addRow("Email Address", info.email());
}
- t.addRow(
- "HTTP Password",
- createHttpPasswordWidget(info.username(),
- allowHttpPassword));
+ t.addRow("HTTP Password", createHttpPasswordWidget(info.username(), allowHttpPassword));
t.addRow("Owner Group", createOwnerWidget(info, allowOwner));
t.addRow("Created By", info.getDisplayName());
t.addRow("Created At", info.created_at());
@@ -155,46 +175,50 @@
activeToggle.setValue(info.active());
activeToggle.setVisible(true);
- activeToggle.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
- @Override
- public void onValueChange(ValueChangeEvent<Boolean> event) {
- if (event.getValue()) {
- new RestApi("config").id("server")
- .view(Plugin.get().getPluginName(), "serviceusers")
- .id(info.username()).view("active")
- .put(new AsyncCallback<NoContent>() {
- @Override
- public void onSuccess(NoContent result) {
- }
+ activeToggle.addValueChangeHandler(
+ new ValueChangeHandler<Boolean>() {
+ @Override
+ public void onValueChange(ValueChangeEvent<Boolean> event) {
+ if (event.getValue()) {
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(info.username())
+ .view("active")
+ .put(
+ new AsyncCallback<NoContent>() {
+ @Override
+ public void onSuccess(NoContent result) {}
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
- } else {
- new RestApi("config").id("server")
- .view(Plugin.get().getPluginName(), "serviceusers")
- .id(info.username()).view("active")
- .delete(new AsyncCallback<NoContent>() {
- @Override
- public void onSuccess(NoContent result) {
- }
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
+ } else {
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(info.username())
+ .view("active")
+ .delete(
+ new AsyncCallback<NoContent>() {
+ @Override
+ public void onSuccess(NoContent result) {}
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
- }
- }
- });
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
+ }
+ }
+ });
return activeToggle;
}
- private Widget createHttpPasswordWidget(final String serviceUser,
- boolean allowHttpPassword) {
+ private Widget createHttpPasswordWidget(final String serviceUser, boolean allowHttpPassword) {
if (allowHttpPassword) {
HorizontalPanel p = new HorizontalPanel();
final CopyableLabel label = new CopyableLabel("");
@@ -206,110 +230,127 @@
final Image delete = new Image(ServiceUserPlugin.RESOURCES.redNot());
delete.addStyleName("serviceuser-deleteButton");
delete.setTitle("Clear HTTP password");
- delete.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- new RestApi("config").id("server").view(Plugin.get().getPluginName(), "serviceusers")
- .id(serviceUser).view("password.http").delete(new AsyncCallback<NoContent>() {
- @Override
- public void onSuccess(NoContent noContent) {
- label.setText("");
- label.setVisible(false);
- delete.setVisible(false);
- }
+ delete.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(serviceUser)
+ .view("password.http")
+ .delete(
+ new AsyncCallback<NoContent>() {
+ @Override
+ public void onSuccess(NoContent noContent) {
+ label.setText("");
+ label.setVisible(false);
+ delete.setVisible(false);
+ }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
- }
- });
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
+ }
+ });
delete.setVisible(true);
p.add(delete);
Image generate = new Image(ServiceUserPlugin.RESOURCES.gear());
generate.addStyleName("serviceuser-generateButton");
generate.setTitle("Generate new HTTP password");
- generate.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- HttpPasswordInput in = HttpPasswordInput.create();
- in.generate(true);
- new RestApi("config").id("server").view(Plugin.get().getPluginName(), "serviceusers")
- .id(serviceUser).view("password.http").put(in, new AsyncCallback<NativeString>() {
- @Override
- public void onSuccess(NativeString newPassword) {
- label.setText(newPassword.asString());
- label.setVisible(true);
- delete.setVisible(true);
- }
+ generate.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ HttpPasswordInput in = HttpPasswordInput.create();
+ in.generate(true);
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(serviceUser)
+ .view("password.http")
+ .put(
+ in,
+ new AsyncCallback<NativeString>() {
+ @Override
+ public void onSuccess(NativeString newPassword) {
+ label.setText(newPassword.asString());
+ label.setVisible(true);
+ delete.setVisible(true);
+ }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
- }
- });
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
+ }
+ });
p.add(generate);
return p;
- } else {
- return new CopyableLabel("");
}
+ return new CopyableLabel("");
}
private Widget createOwnerWidget(ServiceUserInfo info, boolean allowOwner) {
if (allowOwner) {
- EditableValue ownerWidget = new EditableValue(info.username(),
- info.owner() != null ? info.owner().name() : "",
- info.owner() != null ? info.owner().url() : null) {
- @Override
- protected void save(String serviceUser, final String newValue) {
- new RestApi("config").id("server")
- .view(Plugin.get().getPluginName(), "serviceusers").id(serviceUser)
- .view("owner").put(newValue, new AsyncCallback<GroupInfo>() {
- @Override
- public void onSuccess(GroupInfo result) {
- updateValue(result != null ? result.name() : "");
- updateHref(result != null ? result.url() : "");
- Plugin.get().refresh();
- }
+ EditableValue ownerWidget =
+ new EditableValue(
+ info.username(),
+ info.owner() != null ? info.owner().name() : "",
+ info.owner() != null ? info.owner().url() : null) {
+ @Override
+ protected void save(String serviceUser, final String newValue) {
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(serviceUser)
+ .view("owner")
+ .put(
+ newValue,
+ new AsyncCallback<GroupInfo>() {
+ @Override
+ public void onSuccess(GroupInfo result) {
+ updateValue(result != null ? result.name() : "");
+ updateHref(result != null ? result.url() : "");
+ Plugin.get().refresh();
+ }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
- }
- };
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
+ }
+ };
StringBuilder ownerWarning = new StringBuilder();
ownerWarning.append("If ");
- ownerWarning.append(info.owner() != null
- ? "the owner group is changed"
- : "an owner group is set");
+ ownerWarning.append(
+ info.owner() != null ? "the owner group is changed" : "an owner group is set");
ownerWarning.append(" only members of the ");
ownerWarning.append(info.owner() != null ? "new " : "");
- ownerWarning.append("owner group can see and administrate"
- + " the service user.");
+ ownerWarning.append("owner group can see and administrate" + " the service user.");
if (info.owner() != null) {
- ownerWarning.append(" If the owner group is removed only the"
- + " creator of the service user can see and administrate"
- + " the service user.");
+ ownerWarning.append(
+ " If the owner group is removed only the"
+ + " creator of the service user can see and administrate"
+ + " the service user.");
} else {
- ownerWarning.append(" The creator of the service user can no"
- + " longer see and administrate the service user if she/he"
- + " is not member of the owner group.");
+ ownerWarning.append(
+ " The creator of the service user can no"
+ + " longer see and administrate the service user if she/he"
+ + " is not member of the owner group.");
}
ownerWidget.setWarning(ownerWarning.toString());
return ownerWidget;
- } else {
- if (info.owner() != null && info.owner().url() != null) {
- return new Anchor(info.owner().name(), info.owner().url());
- } else {
- return new Label(info.owner() != null ? info.owner().name() : "");
- }
}
+ if (info.owner() != null && info.owner().url() != null) {
+ return new Anchor(info.owner().name(), info.owner().url());
+ }
+ return new Label(info.owner() != null ? info.owner().name() : "");
}
private static class MyTable extends FlexTable {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserSettingsScreen.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserSettingsScreen.java
index ccd5fb3..1755cda 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserSettingsScreen.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/ServiceUserSettingsScreen.java
@@ -57,18 +57,21 @@
ServiceUserSettingsScreen() {
setStyleName("serviceuser-panel");
- new RestApi("config").id("server").view(Plugin.get().getPluginName(), "config")
- .get(new AsyncCallback<ConfigInfo>() {
- @Override
- public void onSuccess(ConfigInfo info) {
- display(info);
- }
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "config")
+ .get(
+ new AsyncCallback<ConfigInfo>() {
+ @Override
+ public void onSuccess(ConfigInfo info) {
+ display(info);
+ }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
}
private void display(ConfigInfo info) {
@@ -76,19 +79,21 @@
Panel infoMsgTitelPanel = new HorizontalPanel();
infoMsgTitelPanel.add(new Label("Info Message"));
Image infoMsgInfo = new Image(ServiceUserPlugin.RESOURCES.info());
- infoMsgInfo.setTitle("HTML formatted message that should be"
- + " displayed on the service user creation screen.");
+ infoMsgInfo.setTitle(
+ "HTML formatted message that should be"
+ + " displayed on the service user creation screen.");
infoMsgTitelPanel.add(infoMsgInfo);
infoMsgTitelPanel.add(new Label(":"));
infoMsgPanel.add(infoMsgTitelPanel);
infoMsgTxt = new TextArea();
infoMsgTxt.setValue(info.getInfoMessage());
- infoMsgTxt.addKeyPressHandler(new KeyPressHandler() {
- @Override
- public void onKeyPress(final KeyPressEvent event) {
- event.stopPropagation();
- }
- });
+ infoMsgTxt.addKeyPressHandler(
+ new KeyPressHandler() {
+ @Override
+ public void onKeyPress(final KeyPressEvent event) {
+ event.stopPropagation();
+ }
+ });
infoMsgTxt.setVisibleLines(12);
infoMsgTxt.setCharacterWidth(80);
infoMsgTxt.getElement().setPropertyBoolean("spellcheck", false);
@@ -99,19 +104,21 @@
Panel onSuccessMsgTitelPanel = new HorizontalPanel();
onSuccessMsgTitelPanel.add(new Label("On Success Message"));
Image onSuccessMsgInfo = new Image(ServiceUserPlugin.RESOURCES.info());
- onSuccessMsgInfo.setTitle("HTML formatted message that should be"
- + " displayed after a service user was successfully created.");
+ onSuccessMsgInfo.setTitle(
+ "HTML formatted message that should be"
+ + " displayed after a service user was successfully created.");
onSuccessMsgTitelPanel.add(onSuccessMsgInfo);
onSuccessMsgTitelPanel.add(new Label(":"));
onSuccessMsgPanel.add(onSuccessMsgTitelPanel);
onSuccessMsgTxt = new TextArea();
onSuccessMsgTxt.setValue(info.getOnSuccessMessage());
- onSuccessMsgTxt.addKeyPressHandler(new KeyPressHandler() {
- @Override
- public void onKeyPress(final KeyPressEvent event) {
- event.stopPropagation();
- }
- });
+ onSuccessMsgTxt.addKeyPressHandler(
+ new KeyPressHandler() {
+ @Override
+ public void onKeyPress(final KeyPressEvent event) {
+ event.stopPropagation();
+ }
+ });
onSuccessMsgTxt.setVisibleLines(12);
onSuccessMsgTxt.setCharacterWidth(80);
onSuccessMsgTxt.getElement().setPropertyBoolean("spellcheck", false);
@@ -123,9 +130,10 @@
allowEmailCheckBox.setValue(info.getAllowEmail());
allowEmailPanel.add(allowEmailCheckBox);
Image allowEmailInfo = new Image(ServiceUserPlugin.RESOURCES.info());
- allowEmailInfo.setTitle("Whether it is allowed to provide an email address "
- + "for a service user. E.g. having an email address allows a service user "
- + "to push commits and tags.");
+ allowEmailInfo.setTitle(
+ "Whether it is allowed to provide an email address "
+ + "for a service user. E.g. having an email address allows a service user "
+ + "to push commits and tags.");
allowEmailPanel.add(allowEmailInfo);
add(allowEmailPanel);
@@ -134,9 +142,10 @@
allowHttpPasswordCheckBox.setValue(info.getAllowHttpPassword());
allowHttpPasswordPanel.add(allowHttpPasswordCheckBox);
Image allowHttpPasswordInfo = new Image(ServiceUserPlugin.RESOURCES.info());
- allowHttpPasswordInfo.setTitle("Whether it is allowed to generate an HTTP password "
- + "for a service user. E.g. having an HTTP password allows a service user "
- + "to use the Gerrit REST API.");
+ allowHttpPasswordInfo.setTitle(
+ "Whether it is allowed to generate an HTTP password "
+ + "for a service user. E.g. having an HTTP password allows a service user "
+ + "to use the Gerrit REST API.");
allowHttpPasswordPanel.add(allowHttpPasswordInfo);
add(allowHttpPasswordPanel);
@@ -145,8 +154,7 @@
allowOwnerCheckBox.setValue(info.getAllowOwner());
allowOwnerPanel.add(allowOwnerCheckBox);
Image allowOwnerInfo = new Image(ServiceUserPlugin.RESOURCES.info());
- allowOwnerInfo.setTitle("Whether it is allowed to set an owner group "
- + "for a service user.");
+ allowOwnerInfo.setTitle("Whether it is allowed to set an owner group " + "for a service user.");
allowOwnerPanel.add(allowOwnerInfo);
add(allowOwnerPanel);
@@ -155,12 +163,13 @@
createNotesCheckBox.setValue(info.getCreateNotes());
createNotesPanel.add(createNotesCheckBox);
Image createNotesInfo = new Image(ServiceUserPlugin.RESOURCES.info());
- createNotesInfo.setTitle("Whether commits of a service user should be "
- + "annotated by a Git note that contains information about the current "
- + "owners of the service user. This allows to find a real person that "
- + "is responsible for this commit. To get such a Git note for each commit "
- + "of a service user the 'Forge Committer' access right must be blocked "
- + "for service users.");
+ createNotesInfo.setTitle(
+ "Whether commits of a service user should be "
+ + "annotated by a Git note that contains information about the current "
+ + "owners of the service user. This allows to find a real person that "
+ + "is responsible for this commit. To get such a Git note for each commit "
+ + "of a service user the 'Forge Committer' access right must be blocked "
+ + "for service users.");
createNotesPanel.add(createNotesInfo);
add(createNotesPanel);
@@ -170,40 +179,42 @@
createNotesAsyncCheckBox.setEnabled(info.getCreateNotes());
createNotesAsyncPanel.add(createNotesAsyncCheckBox);
Image createNotesAsyncInfo = new Image(ServiceUserPlugin.RESOURCES.info());
- createNotesAsyncInfo.setTitle("Whether the Git notes on commits that are "
- + "pushed by a service user should be created asynchronously.");
+ createNotesAsyncInfo.setTitle(
+ "Whether the Git notes on commits that are "
+ + "pushed by a service user should be created asynchronously.");
createNotesAsyncPanel.add(createNotesAsyncInfo);
add(createNotesAsyncPanel);
- createNotesCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
- @Override
- public void onValueChange(ValueChangeEvent<Boolean> event) {
- createNotesAsyncCheckBox.setEnabled(event.getValue());
- }
- });
+ createNotesCheckBox.addValueChangeHandler(
+ new ValueChangeHandler<Boolean>() {
+ @Override
+ public void onValueChange(ValueChangeEvent<Boolean> event) {
+ createNotesAsyncCheckBox.setEnabled(event.getValue());
+ }
+ });
saveButton = new Button("Save");
saveButton.addStyleName("serviceuser-saveButton");
- saveButton.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(final ClickEvent event) {
- doSave();
- }
- });
+ saveButton.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(final ClickEvent event) {
+ doSave();
+ }
+ });
blockedUsernamesPanel =
- new StringListPanel("Blocked Usernames", "Username",
- info.getBlockedNames(), saveButton);
- blockedUsernamesPanel.setInfo("List of usernames which are "
- + "forbidden to be used as name for a service user. "
- + "The blocked usernames are case insensitive.");
+ new StringListPanel("Blocked Usernames", "Username", info.getBlockedNames(), saveButton);
+ blockedUsernamesPanel.setInfo(
+ "List of usernames which are "
+ + "forbidden to be used as name for a service user. "
+ + "The blocked usernames are case insensitive.");
add(blockedUsernamesPanel);
groupsPanel =
- new StringListPanel("Groups", "Group Name",
- info.getGroups().keySet(), saveButton);
- groupsPanel.setInfo("Names of groups to which newly created "
- + "service users should be added automatically.");
+ new StringListPanel("Groups", "Group Name", info.getGroups().keySet(), saveButton);
+ groupsPanel.setInfo(
+ "Names of groups to which newly created " + "service users should be added automatically.");
add(groupsPanel);
HorizontalPanel buttons = new HorizontalPanel();
@@ -236,18 +247,22 @@
}
in.setBlockedNames(blockedUsernamesPanel.getValues());
in.setGroups(groupsPanel.getValues());
- new RestApi("config").id("server").view(Plugin.get().getPluginName(), "config")
- .put(in, new AsyncCallback<JavaScriptObject>() {
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "config")
+ .put(
+ in,
+ new AsyncCallback<JavaScriptObject>() {
- @Override
- public void onSuccess(JavaScriptObject result) {
- saveButton.setEnabled(false);
- }
+ @Override
+ public void onSuccess(JavaScriptObject result) {
+ saveButton.setEnabled(false);
+ }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshKeyHelpPanel.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshKeyHelpPanel.java
index 134b110..9845b23 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshKeyHelpPanel.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshKeyHelpPanel.java
@@ -26,20 +26,22 @@
b.append("<ol>")
.append("<li>From the Terminal or Git Bash, run <em>ssh-keygen</em></li>")
.append("<li>")
- .append("Enter a path for the key, e.g. <em>id_rsa</em>. If you are generating the key<br />")
- .append("on your local system take care to not overwrite your own SSH key.")
+ .append(
+ "Enter a path for the key, e.g. <em>id_rsa</em>. If you are generating the key<br />")
+ .append("on your local system take care to not overwrite your own SSH key.")
.append("</li>")
.append("<li>")
- .append("Enter a passphrase only if the service where you intend to use this<br />")
- .append("service user is able to deal with passphrases, otherwise leave it blank.<br />")
- .append("Remember this passphrase, as you will need it to unlock the key.")
+ .append("Enter a passphrase only if the service where you intend to use this<br />")
+ .append("service user is able to deal with passphrases, otherwise leave it blank.<br />")
+ .append("Remember this passphrase, as you will need it to unlock the key.")
.append("</li>")
.append("<li>")
- .append("Open <em>id_rsa.pub</em> and copy & paste the contents into the box below.<br />")
- .append("Note that <em>id_rsa.pub</em> is your public key and can be shared,<br />")
- .append("while <em>id_rsa</em> is your private key and should be kept secret.")
+ .append(
+ "Open <em>id_rsa.pub</em> and copy & paste the contents into the box below.<br />")
+ .append("Note that <em>id_rsa.pub</em> is your public key and can be shared,<br />")
+ .append("while <em>id_rsa</em> is your private key and should be kept secret.")
.append("</li>")
- .append("</ol>");
+ .append("</ol>");
dp.add(new HTML(b.toString()));
add(dp);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshKeyInfo.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshKeyInfo.java
index 238e548..52a7044 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshKeyInfo.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshKeyInfo.java
@@ -18,12 +18,16 @@
public class SshKeyInfo extends JavaScriptObject {
public final native int seq() /*-{ return this.seq || 0; }-*/;
+
public final native String sshPublicKey() /*-{ return this.ssh_public_key; }-*/;
+
public final native String encodedKey() /*-{ return this.encoded_key; }-*/;
+
public final native String algorithm() /*-{ return this.algorithm; }-*/;
+
public final native String comment() /*-{ return this.comment; }-*/;
+
public final native boolean isValid() /*-{ return this['valid'] ? true : false; }-*/;
- protected SshKeyInfo() {
- }
+ protected SshKeyInfo() {}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshPanel.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshPanel.java
index 7764554..10acc65 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshPanel.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/SshPanel.java
@@ -36,7 +36,6 @@
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwtexpui.clippy.client.CopyableLabel;
import com.google.gwtexpui.globalkey.client.NpTextArea;
-
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -66,12 +65,13 @@
FlowPanel body = new FlowPanel();
showAddKeyBlock = new Button("Add Key ...");
- showAddKeyBlock.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(final ClickEvent event) {
- showAddKeyBlock(true);
- }
- });
+ showAddKeyBlock.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(final ClickEvent event) {
+ showAddKeyBlock(true);
+ }
+ });
keys = new SshKeyTable();
body.add(keys);
@@ -79,12 +79,13 @@
final FlowPanel fp = new FlowPanel();
deleteKey = new Button("Delete");
deleteKey.setEnabled(false);
- deleteKey.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(final ClickEvent event) {
- keys.deleteChecked();
- }
- });
+ deleteKey.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(final ClickEvent event) {
+ keys.deleteChecked();
+ }
+ });
fp.add(deleteKey);
fp.add(showAddKeyBlock);
body.add(fp);
@@ -106,35 +107,37 @@
addKeyBlock.add(buttons);
clearNew = new Button("Clear");
- clearNew.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(final ClickEvent event) {
- addTxt.setText("");
- addTxt.setFocus(true);
- }
- });
+ clearNew.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(final ClickEvent event) {
+ addTxt.setText("");
+ addTxt.setFocus(true);
+ }
+ });
buttons.add(clearNew);
addNew = new Button("Add");
- addNew.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(final ClickEvent event) {
- doAddNew();
- }
- });
+ addNew.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(final ClickEvent event) {
+ doAddNew();
+ }
+ });
buttons.add(addNew);
closeAddKeyBlock = new Button("Close");
- closeAddKeyBlock.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(final ClickEvent event) {
- showAddKeyBlock(false);
- }
- });
+ closeAddKeyBlock.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(final ClickEvent event) {
+ showAddKeyBlock(false);
+ }
+ });
buttons.add(closeAddKeyBlock);
buttons.setCellWidth(closeAddKeyBlock, "100%");
- buttons.setCellHorizontalAlignment(closeAddKeyBlock,
- HasHorizontalAlignment.ALIGN_RIGHT);
+ buttons.setCellHorizontalAlignment(closeAddKeyBlock, HasHorizontalAlignment.ALIGN_RIGHT);
body.add(addKeyBlock);
@@ -153,25 +156,30 @@
void doAddNew() {
final String txt = addTxt.getText();
if (txt != null && txt.length() > 0) {
- new RestApi("config").id("server")
- .view(Plugin.get().getPluginName(), "serviceusers").id(serviceUser)
- .view("sshkeys").post(txt, new AsyncCallback<SshKeyInfo>() {
- @Override
- public void onSuccess(SshKeyInfo k) {
- addTxt.setText("");
- keys.addOneKey(k);
- if (!keys.isVisible()) {
- showAddKeyBlock(false);
- setKeyTableVisible(true);
- keys.updateDeleteButton();
- }
- }
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(serviceUser)
+ .view("sshkeys")
+ .post(
+ txt,
+ new AsyncCallback<SshKeyInfo>() {
+ @Override
+ public void onSuccess(SshKeyInfo k) {
+ addTxt.setText("");
+ keys.addOneKey(k);
+ if (!keys.isVisible()) {
+ showAddKeyBlock(false);
+ setKeyTableVisible(true);
+ keys.updateDeleteButton();
+ }
+ }
- @Override
- public void onFailure(final Throwable caught) {
- // never invoked
- }
- });
+ @Override
+ public void onFailure(final Throwable caught) {
+ // never invoked
+ }
+ });
}
}
@@ -182,29 +190,32 @@
}
private void refreshSshKeys() {
- new RestApi("config").id("server")
- .view(Plugin.get().getPluginName(), "serviceusers").id(serviceUser)
- .view("sshkeys").get(new AsyncCallback<JsArray<SshKeyInfo>>() {
- @Override
- public void onSuccess(JsArray<SshKeyInfo> result) {
- keys.display(Natives.asList(result));
- if (result.length() == 0 && keys.isVisible()) {
- showAddKeyBlock(true);
- }
- if (++loadCount == 2) {
- display();
- }
- }
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(serviceUser)
+ .view("sshkeys")
+ .get(
+ new AsyncCallback<JsArray<SshKeyInfo>>() {
+ @Override
+ public void onSuccess(JsArray<SshKeyInfo> result) {
+ keys.display(Natives.asList(result));
+ if (result.length() == 0 && keys.isVisible()) {
+ showAddKeyBlock(true);
+ }
+ if (++loadCount == 2) {
+ display();
+ }
+ }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
}
- void display() {
- }
+ void display() {}
private void showAddKeyBlock(boolean show) {
showAddKeyBlock.setVisible(!show);
@@ -237,12 +248,13 @@
fmt.addStyleName(0, 4, "topMostCell");
fmt.addStyleName(0, 5, "topMostCell");
- updateDeleteHandler = new ValueChangeHandler<Boolean>() {
- @Override
- public void onValueChange(ValueChangeEvent<Boolean> event) {
- updateDeleteButton();
- }
- };
+ updateDeleteHandler =
+ new ValueChangeHandler<Boolean>() {
+ @Override
+ public void onValueChange(ValueChangeEvent<Boolean> event) {
+ updateDeleteButton();
+ }
+ };
}
void deleteChecked() {
@@ -257,31 +269,36 @@
updateDeleteButton();
} else {
for (int seq : sequenceNumbers) {
- new RestApi("config").id("server")
- .view(Plugin.get().getPluginName(), "serviceusers").id(serviceUser)
- .view("sshkeys").id(seq).delete(new AsyncCallback<NoContent>() {
- @Override
- public void onSuccess(NoContent result) {
- for (int row = 1; row < getRowCount();) {
- SshKeyInfo k = getRowItem(row);
- if (k != null && sequenceNumbers.contains(k.seq())) {
- removeRow(row);
- } else {
- row++;
+ new RestApi("config")
+ .id("server")
+ .view(Plugin.get().getPluginName(), "serviceusers")
+ .id(serviceUser)
+ .view("sshkeys")
+ .id(seq)
+ .delete(
+ new AsyncCallback<NoContent>() {
+ @Override
+ public void onSuccess(NoContent result) {
+ for (int row = 1; row < getRowCount(); ) {
+ SshKeyInfo k = getRowItem(row);
+ if (k != null && sequenceNumbers.contains(k.seq())) {
+ removeRow(row);
+ } else {
+ row++;
+ }
+ }
+ if (getRowCount() == 1) {
+ display(Collections.<SshKeyInfo>emptyList());
+ } else {
+ updateDeleteButton();
+ }
}
- }
- if (getRowCount() == 1) {
- display(Collections.<SshKeyInfo> emptyList());
- } else {
- updateDeleteButton();
- }
- }
- @Override
- public void onFailure(Throwable caught) {
- // never invoked
- }
- });
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
}
}
}
@@ -291,8 +308,7 @@
setKeyTableVisible(false);
showAddKeyBlock(true);
} else {
- while (1 < getRowCount())
- removeRow(getRowCount() - 1);
+ while (1 < getRowCount()) removeRow(getRowCount() - 1);
for (SshKeyInfo k : result) {
addOneKey(k);
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/StringListPanel.java b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/StringListPanel.java
index a809a6d..c2fff99 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/StringListPanel.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/serviceuser/client/StringListPanel.java
@@ -32,7 +32,6 @@
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwtexpui.globalkey.client.NpTextBox;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -44,40 +43,40 @@
private final HorizontalPanel titlePanel;
private Image info;
- StringListPanel(String title, String fieldName, JsArrayString values,
- final FocusWidget w) {
+ StringListPanel(String title, String fieldName, JsArrayString values, final FocusWidget w) {
this(title, fieldName, Natives.asList(values), w);
}
- StringListPanel(String title, String fieldName, Collection<String> values,
- final FocusWidget w) {
+ StringListPanel(String title, String fieldName, Collection<String> values, final FocusWidget w) {
titlePanel = new HorizontalPanel();
Label titleLabel = new Label(title);
titleLabel.setStyleName("serviceuser-smallHeading");
titlePanel.add(titleLabel);
add(titlePanel);
input = new NpTextBox();
- input.addKeyPressHandler(new KeyPressHandler() {
- @Override
- public void onKeyPress(KeyPressEvent event) {
- if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
- w.setEnabled(true);
- add();
- }
- }
- });
+ input.addKeyPressHandler(
+ new KeyPressHandler() {
+ @Override
+ public void onKeyPress(KeyPressEvent event) {
+ if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
+ w.setEnabled(true);
+ add();
+ }
+ }
+ });
HorizontalPanel p = new HorizontalPanel();
p.add(input);
Button addButton = new Button("Add");
addButton.setEnabled(false);
new OnEditEnabler(addButton, input);
- addButton.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- w.setEnabled(true);
- add();
- }
- });
+ addButton.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ w.setEnabled(true);
+ add();
+ }
+ });
p.add(addButton);
add(p);
@@ -87,13 +86,14 @@
deleteButton = new Button("Delete");
deleteButton.setEnabled(false);
add(deleteButton);
- deleteButton.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- w.setEnabled(true);
- t.deleteChecked();
- }
- });
+ deleteButton.addClickHandler(
+ new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ w.setEnabled(true);
+ t.deleteChecked();
+ }
+ });
t.display(values);
}
@@ -154,12 +154,13 @@
fmt.addStyleName(row, 1, "dataCell");
CheckBox checkBox = new CheckBox();
- checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
- @Override
- public void onValueChange(ValueChangeEvent<Boolean> event) {
- enableDelete();
- }
- });
+ checkBox.addValueChangeHandler(
+ new ValueChangeHandler<Boolean>() {
+ @Override
+ public void onValueChange(ValueChangeEvent<Boolean> event) {
+ enableDelete();
+ }
+ });
setWidget(row, 0, checkBox);
setText(row, 1, value);
}
@@ -168,7 +169,7 @@
int insertPos = getRowCount();
for (int row = 1; row < getRowCount(); row++) {
int compareResult = v.compareTo(getText(row, 1));
- if (compareResult < 0) {
+ if (compareResult < 0) {
insertPos = row;
break;
} else if (compareResult == 0) {