Merge "Prevent groups from being renamed to empty string"
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.httpd.rpc.account;
|
||||
|
||||
import com.google.gerrit.common.data.GroupDetail;
|
||||
import com.google.gerrit.common.errors.InvalidNameException;
|
||||
import com.google.gerrit.common.errors.NameAlreadyUsedException;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.httpd.rpc.Handler;
|
||||
@@ -44,7 +45,7 @@ class RenameGroup extends Handler<GroupDetail> {
|
||||
|
||||
@Override
|
||||
public GroupDetail call() throws OrmException, NameAlreadyUsedException,
|
||||
NoSuchGroupException {
|
||||
NoSuchGroupException, InvalidNameException {
|
||||
return performRenameGroupFactory.create().renameGroup(groupId, newName);
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.gerrit.common.data.GroupDetail;
|
||||
import com.google.gerrit.common.errors.InvalidNameException;
|
||||
import com.google.gerrit.common.errors.NameAlreadyUsedException;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
@@ -60,7 +61,7 @@ public class PerformRenameGroup {
|
||||
|
||||
public GroupDetail renameGroup(final String groupName,
|
||||
final String newGroupName) throws OrmException, NameAlreadyUsedException,
|
||||
NoSuchGroupException {
|
||||
NoSuchGroupException, InvalidNameException {
|
||||
final AccountGroup.NameKey groupNameKey =
|
||||
new AccountGroup.NameKey(groupName);
|
||||
final AccountGroup group = groupCache.get(groupNameKey);
|
||||
@@ -72,12 +73,15 @@ public class PerformRenameGroup {
|
||||
|
||||
public GroupDetail renameGroup(final AccountGroup.Id groupId,
|
||||
final String newName) throws OrmException, NameAlreadyUsedException,
|
||||
NoSuchGroupException {
|
||||
NoSuchGroupException, InvalidNameException {
|
||||
final GroupControl ctl = groupControlFactory.validateFor(groupId);
|
||||
final AccountGroup group = db.accountGroups().get(groupId);
|
||||
if (group == null || !ctl.isOwner()) {
|
||||
throw new NoSuchGroupException(groupId);
|
||||
}
|
||||
if (newName.trim().isEmpty()) {
|
||||
throw new InvalidNameException();
|
||||
}
|
||||
|
||||
final AccountGroup.NameKey old = group.getNameKey();
|
||||
final AccountGroup.NameKey key = new AccountGroup.NameKey(newName);
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.sshd.commands;
|
||||
|
||||
import com.google.gerrit.common.errors.InvalidNameException;
|
||||
import com.google.gerrit.common.errors.NameAlreadyUsedException;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.server.account.PerformRenameGroup;
|
||||
@@ -39,6 +40,8 @@ public class RenameGroupCommand extends SshCommand {
|
||||
performRenameGroupFactory.create().renameGroup(groupName, newGroupName);
|
||||
} catch (OrmException e) {
|
||||
throw die(e);
|
||||
} catch (InvalidNameException e) {
|
||||
throw die(e);
|
||||
} catch (NameAlreadyUsedException e) {
|
||||
throw die(e);
|
||||
} catch (NoSuchGroupException e) {
|
||||
|
Reference in New Issue
Block a user