Search in sources :

Example 1 with GroupOptionsInfo

use of com.google.gerrit.extensions.common.GroupOptionsInfo in project gerrit by GerritCodeReview.

the class GroupsIT method groupOptions.

@Test
public void groupOptions() throws Exception {
    String name = name("group");
    gApi.groups().create(name);
    // get options
    assertThat(gApi.groups().id(name).options().visibleToAll).isNull();
    // set options
    GroupOptionsInfo options = new GroupOptionsInfo();
    options.visibleToAll = true;
    gApi.groups().id(name).options(options);
    assertThat(gApi.groups().id(name).options().visibleToAll).isTrue();
}
Also used : GroupOptionsInfo(com.google.gerrit.extensions.common.GroupOptionsInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with GroupOptionsInfo

use of com.google.gerrit.extensions.common.GroupOptionsInfo in project gerrit by GerritCodeReview.

the class GroupJson method createOptions.

public static GroupOptionsInfo createOptions(GroupDescription.Basic group) {
    GroupOptionsInfo options = new GroupOptionsInfo();
    AccountGroup ag = GroupDescriptions.toAccountGroup(group);
    if (ag != null && ag.isVisibleToAll()) {
        options.visibleToAll = true;
    }
    return options;
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupOptionsInfo(com.google.gerrit.extensions.common.GroupOptionsInfo)

Example 3 with GroupOptionsInfo

use of com.google.gerrit.extensions.common.GroupOptionsInfo in project gerrit by GerritCodeReview.

the class PutOptions method apply.

@Override
public GroupOptionsInfo apply(GroupResource resource, GroupOptionsInfo input) throws MethodNotAllowedException, AuthException, BadRequestException, ResourceNotFoundException, OrmException, IOException {
    if (resource.toAccountGroup() == null) {
        throw new MethodNotAllowedException();
    } else if (!resource.getControl().isOwner()) {
        throw new AuthException("Not group owner");
    }
    if (input == null) {
        throw new BadRequestException("options are required");
    }
    if (input.visibleToAll == null) {
        input.visibleToAll = false;
    }
    AccountGroup group = db.get().accountGroups().get(resource.toAccountGroup().getId());
    if (group == null) {
        throw new ResourceNotFoundException();
    }
    group.setVisibleToAll(input.visibleToAll);
    db.get().accountGroups().update(Collections.singleton(group));
    groupCache.evict(group);
    GroupOptionsInfo options = new GroupOptionsInfo();
    if (group.isVisibleToAll()) {
        options.visibleToAll = true;
    }
    return options;
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AuthException(com.google.gerrit.extensions.restapi.AuthException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) GroupOptionsInfo(com.google.gerrit.extensions.common.GroupOptionsInfo)

Aggregations

GroupOptionsInfo (com.google.gerrit.extensions.common.GroupOptionsInfo)3 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 Test (org.junit.Test)1