diff options
author | David Pursehouse <dpursehouse@collab.net> | 2018-12-15 18:03:11 +0900 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2018-12-15 18:03:43 +0900 |
commit | c9c85eed606520c7716884256500af1c03d7bcb0 (patch) | |
tree | 97a5d1bf5d7b6a2425d71ea79bbff96fe2edf588 | |
parent | f380652e35ddac1b90083b17ea46890c5ca76928 (diff) | |
parent | 2c2bd89cb66f36e9661e0e1a576fdb511a897dec (diff) |
Merge branch 'stable-2.15' into stable-2.16
* stable-2.15:
AccountApi: Add method to set account name
Change-Id: I0f8f044b02f360be0e8aaba858d473c5d0530780
3 files changed, 51 insertions, 0 deletions
diff --git a/java/com/google/gerrit/extensions/api/accounts/AccountApi.java b/java/com/google/gerrit/extensions/api/accounts/AccountApi.java index b7fce5f344..056565ee70 100644 --- a/java/com/google/gerrit/extensions/api/accounts/AccountApi.java +++ b/java/com/google/gerrit/extensions/api/accounts/AccountApi.java @@ -112,6 +112,8 @@ public interface AccountApi { List<DeletedDraftCommentInfo> deleteDraftComments(DeleteDraftCommentsInput input) throws RestApiException; + void setName(String name) throws RestApiException; + /** * A default implementation which allows source compatibility when adding new methods to the * interface. @@ -310,5 +312,10 @@ public interface AccountApi { throws RestApiException { throw new NotImplementedException(); } + + @Override + public void setName(String name) throws RestApiException { + throw new NotImplementedException(); + } } } diff --git a/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java b/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java index 15e21fe629..6f89058e56 100644 --- a/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java +++ b/java/com/google/gerrit/server/api/accounts/AccountApiImpl.java @@ -41,6 +41,7 @@ import com.google.gerrit.extensions.common.EmailInfo; import com.google.gerrit.extensions.common.GpgKeyInfo; import com.google.gerrit.extensions.common.GroupInfo; import com.google.gerrit.extensions.common.Input; +import com.google.gerrit.extensions.common.NameInput; import com.google.gerrit.extensions.common.SshKeyInfo; import com.google.gerrit.extensions.restapi.IdString; import com.google.gerrit.extensions.restapi.Response; @@ -74,6 +75,7 @@ import com.google.gerrit.server.restapi.account.Index; import com.google.gerrit.server.restapi.account.PostWatchedProjects; import com.google.gerrit.server.restapi.account.PutActive; import com.google.gerrit.server.restapi.account.PutAgreement; +import com.google.gerrit.server.restapi.account.PutName; import com.google.gerrit.server.restapi.account.PutStatus; import com.google.gerrit.server.restapi.account.SetDiffPreferences; import com.google.gerrit.server.restapi.account.SetEditPreferences; @@ -132,6 +134,7 @@ public class AccountApiImpl implements AccountApi { private final PutStatus putStatus; private final GetGroups getGroups; private final EmailApiImpl.Factory emailApi; + private final PutName putName; @Inject AccountApiImpl( @@ -173,6 +176,7 @@ public class AccountApiImpl implements AccountApi { PutStatus putStatus, GetGroups getGroups, EmailApiImpl.Factory emailApi, + PutName putName, @Assisted AccountResource account) { this.account = account; this.accountLoaderFactory = ailf; @@ -213,6 +217,7 @@ public class AccountApiImpl implements AccountApi { this.putStatus = putStatus; this.getGroups = getGroups; this.emailApi = emailApi; + this.putName = putName; } @Override @@ -577,4 +582,15 @@ public class AccountApiImpl implements AccountApi { throw asRestApiException("Cannot delete draft comments", e); } } + + @Override + public void setName(String name) throws RestApiException { + NameInput input = new NameInput(); + input.name = name; + try { + putName.apply(account, input); + } catch (Exception e) { + throw asRestApiException("Cannot set account name", e); + } + } } diff --git a/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java b/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java index 5e46a03126..6f4549fdb2 100644 --- a/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java +++ b/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java @@ -52,6 +52,7 @@ import com.google.common.util.concurrent.Runnables; import com.google.gerrit.acceptance.AbstractDaemonTest; import com.google.gerrit.acceptance.GerritConfig; import com.google.gerrit.acceptance.PushOneCommit; +import com.google.gerrit.acceptance.Sandboxed; import com.google.gerrit.acceptance.TestAccount; import com.google.gerrit.acceptance.UseSsh; import com.google.gerrit.acceptance.testsuite.account.AccountOperations; @@ -1184,6 +1185,33 @@ public class AccountIT extends AbstractDaemonTest { } @Test + public void setName() throws Exception { + gApi.accounts().self().setName("Admin McAdminface"); + assertThat(gApi.accounts().self().get().name).isEqualTo("Admin McAdminface"); + } + + @Test + public void adminCanSetNameOfOtherUser() throws Exception { + gApi.accounts().id(user.username).setName("User McUserface"); + assertThat(gApi.accounts().id(user.username).get().name).isEqualTo("User McUserface"); + } + + @Test + public void userCannotSetNameOfOtherUser() throws Exception { + setApiUser(user); + exception.expect(AuthException.class); + gApi.accounts().id(admin.username).setName("Admin McAdminface"); + } + + @Test + @Sandboxed + public void userCanSetNameOfOtherUserWithModifyAccountPermission() throws Exception { + allowGlobalCapabilities(REGISTERED_USERS, GlobalCapability.MODIFY_ACCOUNT); + gApi.accounts().id(admin.username).setName("Admin McAdminface"); + assertThat(gApi.accounts().id(admin.username).get().name).isEqualTo("Admin McAdminface"); + } + + @Test public void fetchUserBranch() throws Exception { setApiUser(user); |