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