Search in sources :

Example 46 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method visibleto.

@Operator
public Predicate<ChangeData> visibleto(String who) throws QueryParseException, IOException, ConfigInvalidException {
    if (isSelf(who)) {
        return isVisible();
    }
    Set<Account.Id> accounts = null;
    try {
        accounts = parseAccount(who);
    } catch (QueryParseException e) {
        if (e instanceof QueryRequiresAuthException) {
            throw e;
        }
    }
    if (accounts != null) {
        if (accounts.size() == 1) {
            return visibleto(args.userFactory.create(Iterables.getOnlyElement(accounts)));
        } else if (accounts.size() > 1) {
            throw error(String.format("\"%s\" resolves to multiple accounts", who));
        }
    }
    // If its not an account, maybe its a group?
    Collection<GroupReference> suggestions = args.groupBackend.suggest(who, null);
    if (!suggestions.isEmpty()) {
        HashSet<AccountGroup.UUID> ids = new HashSet<>();
        for (GroupReference ref : suggestions) {
            ids.add(ref.getUUID());
        }
        return visibleto(new GroupBackedUser(ids));
    }
    throw error("No user or group matches \"" + who + "\".");
}
Also used : QueryRequiresAuthException(com.google.gerrit.index.query.QueryRequiresAuthException) GroupReference(com.google.gerrit.entities.GroupReference) QueryParseException(com.google.gerrit.index.query.QueryParseException) HashSet(java.util.HashSet)

Example 47 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method uploaderin.

@Operator
public Predicate<ChangeData> uploaderin(String group) throws QueryParseException, IOException {
    checkFieldAvailable(ChangeField.UPLOADER, "uploaderin");
    GroupReference g = GroupBackends.findBestSuggestion(args.groupBackend, group);
    if (g == null) {
        throw error("Group " + group + " not found");
    }
    AccountGroup.UUID groupId = g.getUUID();
    GroupDescription.Basic groupDescription = args.groupBackend.get(groupId);
    if (!(groupDescription instanceof GroupDescription.Internal)) {
        return new UploaderinPredicate(args.userFactory, groupId);
    }
    Set<Account.Id> accounts = getMembers(groupId);
    List<Predicate<ChangeData>> p = Lists.newArrayListWithCapacity(accounts.size());
    for (Account.Id id : accounts) {
        p.add(ChangePredicates.uploader(id));
    }
    return Predicate.or(p);
}
Also used : Account(com.google.gerrit.entities.Account) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) LimitPredicate(com.google.gerrit.index.query.LimitPredicate) Predicate(com.google.gerrit.index.query.Predicate) GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference)

Example 48 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class GroupsIT method getSystemGroupByConfiguredName.

@Test
@GerritConfig(name = "groups.global:Anonymous-Users.name", value = "All Users")
public void getSystemGroupByConfiguredName() throws Exception {
    GroupReference anonymousUsersGroup = systemGroupBackend.getGroup(ANONYMOUS_USERS);
    assertThat(anonymousUsersGroup.getName()).isEqualTo("All Users");
    GroupInfo group = gApi.groups().id(anonymousUsersGroup.getUUID().get()).get();
    assertThat(group.name).isEqualTo(anonymousUsersGroup.getName());
    group = gApi.groups().id(anonymousUsersGroup.getName()).get();
    assertThat(group.id).isEqualTo(Url.encode(anonymousUsersGroup.getUUID().get()));
}
Also used : GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) GroupReference(com.google.gerrit.entities.GroupReference) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 49 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class GroupsIT method getSystemGroupByDefaultName.

@Test
public void getSystemGroupByDefaultName() throws Exception {
    GroupReference anonymousUsersGroup = systemGroupBackend.getGroup(ANONYMOUS_USERS);
    GroupInfo group = gApi.groups().id("Anonymous Users").get();
    assertThat(group.name).isEqualTo(anonymousUsersGroup.getName());
    assertThat(group.id).isEqualTo(Url.encode(anonymousUsersGroup.getUUID().get()));
}
Also used : GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) GroupReference(com.google.gerrit.entities.GroupReference) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 50 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class AccessIT method grantDenyAndAllowForSameGroup.

@Test
public void grantDenyAndAllowForSameGroup() throws Exception {
    GroupReference registeredUsers = systemGroupBackend.getGroup(REGISTERED_USERS);
    String access = "access";
    List<String> denyThenAllow = asList("deny " + registeredUsers.toConfigValue(), registeredUsers.toConfigValue());
    // Clone repository to forcefully add permission
    TestRepository<InMemoryRepository> allProjectsRepo = cloneProject(allProjects, admin);
    // Fetch permission ref
    GitUtil.fetch(allProjectsRepo, "refs/meta/config:cfg");
    allProjectsRepo.reset("cfg");
    // Load current permissions
    String config = gApi.projects().name(allProjects.get()).branch(RefNames.REFS_CONFIG).file(ProjectConfig.PROJECT_CONFIG).asString();
    // Append and push denyThenAllow permissions
    Config cfg = new Config();
    cfg.fromText(config);
    cfg.setStringList(access, AccessSection.HEADS, Permission.READ, denyThenAllow);
    config = cfg.toText();
    PushOneCommit push = pushFactory.create(admin.newIdent(), allProjectsRepo, "Subject", ProjectConfig.PROJECT_CONFIG, config);
    push.to(RefNames.REFS_CONFIG).assertOkStatus();
    ProjectAccessInfo pai = gApi.projects().name(allProjects.get()).access();
    Map<String, AccessSectionInfo> local = pai.local;
    AccessSectionInfo heads = local.get(AccessSection.HEADS);
    Map<String, PermissionInfo> permissions = heads.permissions;
    PermissionInfo read = permissions.get(Permission.READ);
    Map<String, PermissionRuleInfo> rules = read.rules;
    assertEquals(rules.get(registeredUsers.getUUID().get()), new PermissionRuleInfo(PermissionRuleInfo.Action.DENY, false));
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Config(org.eclipse.jgit.lib.Config) ProjectAccessInfo(com.google.gerrit.extensions.api.access.ProjectAccessInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo) PermissionRuleInfo(com.google.gerrit.extensions.api.access.PermissionRuleInfo) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) GroupReference(com.google.gerrit.entities.GroupReference) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

GroupReference (com.google.gerrit.entities.GroupReference)59 Test (org.junit.Test)24 AccountGroup (com.google.gerrit.entities.AccountGroup)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)8 GroupDescription (com.google.gerrit.entities.GroupDescription)8 InternalGroup (com.google.gerrit.entities.InternalGroup)7 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)7 IOException (java.io.IOException)7 Repository (org.eclipse.jgit.lib.Repository)7 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)6 Config (org.eclipse.jgit.lib.Config)6 CachedProjectConfig (com.google.gerrit.entities.CachedProjectConfig)5 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)5 NotifyConfig (com.google.gerrit.entities.NotifyConfig)4 ArrayList (java.util.ArrayList)4 Account (com.google.gerrit.entities.Account)3 BooleanProjectConfig (com.google.gerrit.entities.BooleanProjectConfig)3 Permission (com.google.gerrit.entities.Permission)3 PermissionRule (com.google.gerrit.entities.PermissionRule)3 ProjectAccessInfo (com.google.gerrit.extensions.api.access.ProjectAccessInfo)3