Merge "Modify account command: Add option to set preferred email"
This commit is contained in:
@@ -7,6 +7,7 @@ gerrit set-account - Change an account's settings.
|
|||||||
--
|
--
|
||||||
set-account [--full-name <FULLNAME>] [--active|--inactive] \
|
set-account [--full-name <FULLNAME>] [--active|--inactive] \
|
||||||
[--add-email <EMAIL>] [--delete-email <EMAIL> | ALL] \
|
[--add-email <EMAIL>] [--delete-email <EMAIL> | ALL] \
|
||||||
|
[--preferred-email <EMAIL>] \
|
||||||
[--add-ssh-key - | <KEY>] \
|
[--add-ssh-key - | <KEY>] \
|
||||||
[--delete-ssh-key - | <KEY> | ALL] \
|
[--delete-ssh-key - | <KEY> | ALL] \
|
||||||
[--http-password <PASSWORD>] \
|
[--http-password <PASSWORD>] \
|
||||||
@@ -67,6 +68,13 @@ This most likely requires double quoting the value, for example
|
|||||||
Maybe supplied more than once to remove multiple emails
|
Maybe supplied more than once to remove multiple emails
|
||||||
from an account in a single command execution.
|
from an account in a single command execution.
|
||||||
|
|
||||||
|
--preferred-email::
|
||||||
|
Sets the preferred email address for the user's account.
|
||||||
|
The email address must already have been registered
|
||||||
|
with the user's account before it can be set.
|
||||||
|
May be supplied with the delete-email option as long as
|
||||||
|
the emails are not the same.
|
||||||
|
|
||||||
--add-ssh-key::
|
--add-ssh-key::
|
||||||
Content of the public SSH key to add to the account's
|
Content of the public SSH key to add to the account's
|
||||||
keyring. If `-` the key is read from stdin, rather than
|
keyring. If `-` the key is read from stdin, rather than
|
||||||
|
@@ -36,6 +36,7 @@ import com.google.gerrit.server.account.GetSshKeys;
|
|||||||
import com.google.gerrit.server.account.GetSshKeys.SshKeyInfo;
|
import com.google.gerrit.server.account.GetSshKeys.SshKeyInfo;
|
||||||
import com.google.gerrit.server.account.PutActive;
|
import com.google.gerrit.server.account.PutActive;
|
||||||
import com.google.gerrit.server.account.PutHttpPassword;
|
import com.google.gerrit.server.account.PutHttpPassword;
|
||||||
|
import com.google.gerrit.server.account.PutPreferred;
|
||||||
import com.google.gerrit.server.account.PutName;
|
import com.google.gerrit.server.account.PutName;
|
||||||
import com.google.gerrit.sshd.CommandMetaData;
|
import com.google.gerrit.sshd.CommandMetaData;
|
||||||
import com.google.gerrit.sshd.SshCommand;
|
import com.google.gerrit.sshd.SshCommand;
|
||||||
@@ -78,6 +79,9 @@ final class SetAccountCommand extends SshCommand {
|
|||||||
@Option(name = "--delete-email", metaVar = "EMAIL", usage = "email addresses to delete from the account")
|
@Option(name = "--delete-email", metaVar = "EMAIL", usage = "email addresses to delete from the account")
|
||||||
private List<String> deleteEmails = new ArrayList<>();
|
private List<String> deleteEmails = new ArrayList<>();
|
||||||
|
|
||||||
|
@Option(name = "--preferred-email", metaVar = "EMAIL", usage = "a registered email address from the account")
|
||||||
|
private String preferredEmail;
|
||||||
|
|
||||||
@Option(name = "--add-ssh-key", metaVar = "-|KEY", usage = "public keys to add to the account")
|
@Option(name = "--add-ssh-key", metaVar = "-|KEY", usage = "public keys to add to the account")
|
||||||
private List<String> addSshKeys = new ArrayList<>();
|
private List<String> addSshKeys = new ArrayList<>();
|
||||||
|
|
||||||
@@ -102,6 +106,9 @@ final class SetAccountCommand extends SshCommand {
|
|||||||
@Inject
|
@Inject
|
||||||
private DeleteEmail deleteEmail;
|
private DeleteEmail deleteEmail;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PutPreferred putPreferred;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PutName putName;
|
private PutName putName;
|
||||||
|
|
||||||
@@ -151,6 +158,11 @@ final class SetAccountCommand extends SshCommand {
|
|||||||
if (deleteEmails.contains("ALL")) {
|
if (deleteEmails.contains("ALL")) {
|
||||||
deleteEmails = Collections.singletonList("ALL");
|
deleteEmails = Collections.singletonList("ALL");
|
||||||
}
|
}
|
||||||
|
if (deleteEmails.contains(preferredEmail)) {
|
||||||
|
throw new UnloggedFailure(1,
|
||||||
|
"--preferred-email and --delete-email options are mutually " +
|
||||||
|
"exclusive for the same email address.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAccount() throws OrmException, IOException, UnloggedFailure {
|
private void setAccount() throws OrmException, IOException, UnloggedFailure {
|
||||||
@@ -165,6 +177,10 @@ final class SetAccountCommand extends SshCommand {
|
|||||||
deleteEmail(email);
|
deleteEmail(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preferredEmail != null) {
|
||||||
|
putPreferred(preferredEmail);
|
||||||
|
}
|
||||||
|
|
||||||
if (fullName != null) {
|
if (fullName != null) {
|
||||||
PutName.Input in = new PutName.Input();
|
PutName.Input in = new PutName.Input();
|
||||||
in.name = fullName;
|
in.name = fullName;
|
||||||
@@ -277,6 +293,17 @@ final class SetAccountCommand extends SshCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putPreferred(String email) throws RestApiException,
|
||||||
|
OrmException {
|
||||||
|
for (EmailInfo e : getEmails.apply(rsrc)) {
|
||||||
|
if (e.email.equals(email)) {
|
||||||
|
putPreferred.apply(new AccountResource.Email(user, email), null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stderr.println("preferred email not found: " + email);
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> readSshKey(final List<String> sshKeys)
|
private List<String> readSshKey(final List<String> sshKeys)
|
||||||
throws UnsupportedEncodingException, IOException {
|
throws UnsupportedEncodingException, IOException {
|
||||||
if (!sshKeys.isEmpty()) {
|
if (!sshKeys.isEmpty()) {
|
||||||
|
Reference in New Issue
Block a user