Merge "Add ssh command to list groups."

This commit is contained in:
Martin Fick
2011-11-07 14:38:56 -08:00
committed by gerrit code review
9 changed files with 163 additions and 14 deletions

View File

@@ -0,0 +1,73 @@
// Copyright (C) 2011 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
package com.google.gerrit.server.account;
import com.google.gerrit.common.data.GroupDetail;
import com.google.gerrit.common.data.GroupList;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gwtorm.client.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
public class VisibleGroups {
public interface Factory {
VisibleGroups create();
}
private final Provider<IdentifiedUser> identifiedUser;
private final GroupCache groupCache;
private final GroupControl.Factory groupControlFactory;
private final GroupDetailFactory.Factory groupDetailFactory;
@Inject
VisibleGroups(final Provider<IdentifiedUser> currentUser,
final GroupCache groupCache,
final GroupControl.Factory groupControlFactory,
final GroupDetailFactory.Factory groupDetailFactory) {
this.identifiedUser = currentUser;
this.groupCache = groupCache;
this.groupControlFactory = groupControlFactory;
this.groupDetailFactory = groupDetailFactory;
}
public GroupList get() throws OrmException, NoSuchGroupException {
final IdentifiedUser user = identifiedUser.get();
final List<AccountGroup> list = new ArrayList<AccountGroup>();
if (user.getCapabilities().canAdministrateServer()) {
CollectionUtils.addAll(list, groupCache.all().iterator());
} else {
for(final AccountGroup group : groupCache.all()) {
final GroupControl c = groupControlFactory.controlFor(group);
if (c.isVisible()) {
list.add(c.getAccountGroup());
}
}
}
List<GroupDetail> l = new ArrayList<GroupDetail>();
for(AccountGroup group : list) {
l.add(groupDetailFactory.create(group.getId()).call());
}
return new GroupList(l, user.getCapabilities().canCreateGroup());
}
}

View File

@@ -26,6 +26,7 @@ import com.google.gerrit.server.account.GroupDetailFactory;
import com.google.gerrit.server.account.GroupMembersFactory;
import com.google.gerrit.server.account.PerformCreateGroup;
import com.google.gerrit.server.account.PerformRenameGroup;
import com.google.gerrit.server.account.VisibleGroups;
import com.google.gerrit.server.git.CreateCodeReviewNotes;
import com.google.gerrit.server.git.MergeOp;
import com.google.gerrit.server.git.MetaDataUpdate;
@@ -91,6 +92,7 @@ public class GerritRequestModule extends FactoryModule {
factory(RegisterNewEmailSender.Factory.class);
factory(PerformCreateGroup.Factory.class);
factory(PerformRenameGroup.Factory.class);
factory(VisibleGroups.Factory.class);
factory(GroupDetailFactory.Factory.class);
factory(GroupMembersFactory.Factory.class);
}