diff options
Diffstat (limited to 'gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/RenameGroup.java')
-rw-r--r-- | gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/RenameGroup.java | 64 |
1 files changed, 7 insertions, 57 deletions
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/RenameGroup.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/RenameGroup.java index d62f0c0df6..09dc582bf2 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/RenameGroup.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/account/RenameGroup.java @@ -18,40 +18,26 @@ import com.google.gerrit.common.data.GroupDetail; import com.google.gerrit.common.errors.NameAlreadyUsedException; import com.google.gerrit.common.errors.NoSuchGroupException; import com.google.gerrit.httpd.rpc.Handler; -import com.google.gerrit.reviewdb.AccountGroup; -import com.google.gerrit.reviewdb.AccountGroupName; -import com.google.gerrit.reviewdb.ReviewDb; -import com.google.gerrit.server.account.GroupCache; -import com.google.gerrit.server.account.GroupControl; -import com.google.gwtorm.client.OrmDuplicateKeyException; -import com.google.gwtorm.client.OrmException; +import com.google.gerrit.reviewdb.client.AccountGroup; +import com.google.gerrit.server.account.PerformRenameGroup; +import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; -import java.util.Collections; - class RenameGroup extends Handler<GroupDetail> { interface Factory { RenameGroup create(AccountGroup.Id id, String newName); } - private final ReviewDb db; - private final GroupCache groupCache; - private final GroupControl.Factory groupControlFactory; - private final GroupDetailFactory.Factory groupDetailFactory; + private final PerformRenameGroup.Factory performRenameGroupFactory; private final AccountGroup.Id groupId; private final String newName; @Inject - RenameGroup(final ReviewDb db, final GroupCache groupCache, - final GroupControl.Factory groupControlFactory, - final GroupDetailFactory.Factory groupDetailFactory, + RenameGroup(final PerformRenameGroup.Factory performRenameGroupFactory, @Assisted final AccountGroup.Id groupId, @Assisted final String newName) { - this.db = db; - this.groupCache = groupCache; - this.groupControlFactory = groupControlFactory; - this.groupDetailFactory = groupDetailFactory; + this.performRenameGroupFactory = performRenameGroupFactory; this.groupId = groupId; this.newName = newName; } @@ -59,42 +45,6 @@ class RenameGroup extends Handler<GroupDetail> { @Override public GroupDetail call() throws OrmException, NameAlreadyUsedException, NoSuchGroupException { - final GroupControl ctl = groupControlFactory.validateFor(groupId); - final AccountGroup group = db.accountGroups().get(groupId); - if (group == null || !ctl.isOwner()) { - throw new NoSuchGroupException(groupId); - } - - final AccountGroup.NameKey old = group.getNameKey(); - final AccountGroup.NameKey key = new AccountGroup.NameKey(newName); - - try { - final AccountGroupName id = new AccountGroupName(key, groupId); - db.accountGroupNames().insert(Collections.singleton(id)); - } catch (OrmDuplicateKeyException dupeErr) { - // If we are using this identity, don't report the exception. - // - AccountGroupName other = db.accountGroupNames().get(key); - if (other != null && other.getId().equals(groupId)) { - return groupDetailFactory.create(groupId).call(); - } - - // Otherwise, someone else has this identity. - // - throw new NameAlreadyUsedException(); - } - - group.setNameKey(key); - db.accountGroups().update(Collections.singleton(group)); - - AccountGroupName priorName = db.accountGroupNames().get(old); - if (priorName != null) { - db.accountGroupNames().delete(Collections.singleton(priorName)); - } - - groupCache.evict(group); - groupCache.evictAfterRename(old); - - return groupDetailFactory.create(groupId).call(); + return performRenameGroupFactory.create().renameGroup(groupId, newName); } } |