Search in sources :

Example 6 with ContributorAgreement

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

the class ProjectConfig method saveContributorAgreements.

private void saveContributorAgreements(Config rc, Set<AccountGroup.UUID> keepGroups) {
    unsetSection(rc, CONTRIBUTOR_AGREEMENT);
    for (ContributorAgreement ca : sort(contributorAgreements.values())) {
        set(rc, CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_DESCRIPTION, ca.getDescription());
        set(rc, CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_AGREEMENT_URL, ca.getAgreementUrl());
        if (ca.getAutoVerify() != null) {
            if (ca.getAutoVerify().getUUID() != null) {
                keepGroups.add(ca.getAutoVerify().getUUID());
            }
            String autoVerify = PermissionRule.create(ca.getAutoVerify()).asString(false);
            set(rc, CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_AUTO_VERIFY, autoVerify);
        } else {
            rc.unset(CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_AUTO_VERIFY);
        }
        rc.setStringList(CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_ACCEPTED, ruleToStringList(ca.getAccepted(), keepGroups));
        rc.setStringList(CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_EXCLUDE_PROJECTS, patternToStringList(ca.getExcludeProjectsRegexes()));
        rc.setStringList(CONTRIBUTOR_AGREEMENT, ca.getName(), KEY_MATCH_PROJECTS, patternToStringList(ca.getMatchProjectsRegexes()));
    }
}
Also used : ContributorAgreement(com.google.gerrit.entities.ContributorAgreement)

Example 7 with ContributorAgreement

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

the class GetServerInfo method getAuthInfo.

private AuthInfo getAuthInfo() throws PermissionBackendException {
    AuthInfo info = new AuthInfo();
    info.authType = authConfig.getAuthType();
    info.useContributorAgreements = toBoolean(authConfig.isUseContributorAgreements());
    info.editableAccountFields = new ArrayList<>(realm.getEditableFields());
    info.switchAccountUrl = authConfig.getSwitchAccountUrl();
    info.gitBasicAuthPolicy = authConfig.getGitBasicAuthPolicy();
    if (info.useContributorAgreements != null) {
        Collection<ContributorAgreement> agreements = projectCache.getAllProjects().getConfig().getContributorAgreements().values();
        if (!agreements.isEmpty()) {
            info.contributorAgreements = Lists.newArrayListWithCapacity(agreements.size());
            for (ContributorAgreement agreement : agreements) {
                info.contributorAgreements.add(agreementJson.format(agreement));
            }
        }
    }
    switch(info.authType) {
        case LDAP:
        case LDAP_BIND:
            info.registerUrl = authConfig.getRegisterUrl();
            info.registerText = authConfig.getRegisterText();
            info.editFullNameUrl = authConfig.getEditFullNameUrl();
            break;
        case CUSTOM_EXTENSION:
            info.registerUrl = authConfig.getRegisterUrl();
            info.registerText = authConfig.getRegisterText();
            info.editFullNameUrl = authConfig.getEditFullNameUrl();
            info.httpPasswordUrl = authConfig.getHttpPasswordUrl();
            break;
        case HTTP:
        case HTTP_LDAP:
            info.loginUrl = authConfig.getLoginUrl();
            info.loginText = authConfig.getLoginText();
            break;
        case CLIENT_SSL_CERT_LDAP:
        case DEVELOPMENT_BECOME_ANY_ACCOUNT:
        case OAUTH:
        case OPENID:
        case OPENID_SSO:
            break;
    }
    return info;
}
Also used : AuthInfo(com.google.gerrit.extensions.common.AuthInfo) ContributorAgreement(com.google.gerrit.entities.ContributorAgreement)

Example 8 with ContributorAgreement

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

the class AgreementsIT method configureContributorAgreement.

protected ContributorAgreement configureContributorAgreement(boolean autoVerify) throws Exception {
    ContributorAgreement.Builder ca;
    String name = autoVerify ? "cla-test-group" : "cla-test-no-auto-verify-group";
    AccountGroup.UUID g = groupOperations.newGroup().name(name).create();
    GroupApi groupApi = gApi.groups().id(g.get());
    groupApi.description("CLA test group");
    InternalGroup caGroup = group(AccountGroup.uuid(groupApi.detail().id));
    GroupReference groupRef = GroupReference.create(caGroup.getGroupUUID(), caGroup.getName());
    PermissionRule rule = PermissionRule.builder(groupRef).setAction(PermissionRule.Action.ALLOW).build();
    if (autoVerify) {
        ca = ContributorAgreement.builder("cla-test");
        ca.setAutoVerify(groupRef);
        ca.setAccepted(ImmutableList.of(rule));
    } else {
        ca = ContributorAgreement.builder("cla-test-no-auto-verify");
    }
    ca.setDescription("description");
    ca.setAgreementUrl("agreement-url");
    ca.setAccepted(ImmutableList.of(rule));
    ca.setExcludeProjectsRegexes(ImmutableList.of("ExcludedProject"));
    try (ProjectConfigUpdate u = updateProject(allProjects)) {
        ContributorAgreement contributorAgreement = ca.build();
        u.getConfig().replace(contributorAgreement);
        u.save();
        return contributorAgreement;
    }
}
Also used : GroupApi(com.google.gerrit.extensions.api.groups.GroupApi) AccountGroup(com.google.gerrit.entities.AccountGroup) PermissionRule(com.google.gerrit.entities.PermissionRule) ContributorAgreement(com.google.gerrit.entities.ContributorAgreement) GroupReference(com.google.gerrit.entities.GroupReference) InternalGroup(com.google.gerrit.entities.InternalGroup)

Example 9 with ContributorAgreement

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

the class PutAgreement method apply.

@Override
public Response<String> apply(AccountResource resource, AgreementInput input) throws IOException, RestApiException, ConfigInvalidException {
    if (!agreementsEnabled) {
        throw new MethodNotAllowedException("contributor agreements disabled");
    }
    if (!self.get().hasSameAccountId(resource.getUser())) {
        throw new AuthException("not allowed to enter contributor agreement");
    }
    String agreementName = Strings.nullToEmpty(input.name);
    ContributorAgreement ca = projectCache.getAllProjects().getConfig().getContributorAgreements().get(agreementName);
    if (ca == null) {
        throw new UnprocessableEntityException("contributor agreement not found");
    }
    if (ca.getAutoVerify() == null) {
        throw new BadRequestException("cannot enter a non-autoVerify agreement");
    }
    AccountGroup.UUID uuid = ca.getAutoVerify().getUUID();
    if (uuid == null) {
        throw new ResourceConflictException("autoverify group uuid not found");
    }
    AccountState accountState = self.get().state();
    try {
        addMembers.addMembers(uuid, ImmutableSet.of(accountState.account().id()));
    } catch (NoSuchGroupException e) {
        throw new ResourceConflictException("autoverify group not found", e);
    }
    agreementSignup.fire(accountState, agreementName);
    return Response.ok(agreementName);
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.entities.AccountGroup) ContributorAgreement(com.google.gerrit.entities.ContributorAgreement) AuthException(com.google.gerrit.extensions.restapi.AuthException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AccountState(com.google.gerrit.server.account.AccountState) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Example 10 with ContributorAgreement

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

the class GetAgreements method apply.

@Override
public Response<List<AgreementInfo>> apply(AccountResource resource) throws RestApiException, PermissionBackendException {
    if (!agreementsEnabled) {
        throw new MethodNotAllowedException("contributor agreements disabled");
    }
    if (!self.get().isIdentifiedUser()) {
        throw new AuthException("not allowed to get contributor agreements");
    }
    IdentifiedUser user = self.get().asIdentifiedUser();
    if (user != resource.getUser()) {
        try {
            permissionBackend.user(user).check(GlobalPermission.ADMINISTRATE_SERVER);
        } catch (AuthException e) {
            throw new AuthException("not allowed to get contributor agreements", e);
        }
    }
    List<AgreementInfo> results = new ArrayList<>();
    Collection<ContributorAgreement> cas = projectCache.getAllProjects().getConfig().getContributorAgreements().values();
    for (ContributorAgreement ca : cas) {
        List<AccountGroup.UUID> groupIds = new ArrayList<>();
        for (PermissionRule rule : ca.getAccepted()) {
            if ((rule.getAction() == Action.ALLOW) && (rule.getGroup() != null)) {
                if (rule.getGroup().getUUID() != null) {
                    groupIds.add(rule.getGroup().getUUID());
                } else {
                    logger.atWarning().log("group \"%s\" does not exist, referenced in CLA \"%s\"", rule.getGroup().getName(), ca.getName());
                }
            }
        }
        if (user.getEffectiveGroups().containsAnyOf(groupIds)) {
            results.add(agreementJson.format(ca));
        }
    }
    return Response.ok(results);
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) PermissionRule(com.google.gerrit.entities.PermissionRule) AgreementInfo(com.google.gerrit.extensions.common.AgreementInfo) ContributorAgreement(com.google.gerrit.entities.ContributorAgreement) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser)

Aggregations

ContributorAgreement (com.google.gerrit.entities.ContributorAgreement)10 PermissionRule (com.google.gerrit.entities.PermissionRule)4 AuthException (com.google.gerrit.extensions.restapi.AuthException)3 Test (org.junit.Test)3 AccountGroup (com.google.gerrit.entities.AccountGroup)2 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)2 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)2 ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 AccessSection (com.google.gerrit.entities.AccessSection)1 UUID (com.google.gerrit.entities.AccountGroup.UUID)1 GroupReference (com.google.gerrit.entities.GroupReference)1 InternalGroup (com.google.gerrit.entities.InternalGroup)1 Permission (com.google.gerrit.entities.Permission)1 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)1 GroupApi (com.google.gerrit.extensions.api.groups.GroupApi)1 AgreementInfo (com.google.gerrit.extensions.common.AgreementInfo)1 AuthInfo (com.google.gerrit.extensions.common.AuthInfo)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1