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 + "\".");
}
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);
}
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()));
}
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()));
}
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));
}
Aggregations