Search in sources :

Example 1 with ContributorAgreement

use of com.google.gerrit.common.data.ContributorAgreement in project gerrit by GerritCodeReview.

the class GetServerInfo method getAuthInfo.

private AuthInfo getAuthInfo(AuthConfig cfg, Realm realm) {
    AuthInfo info = new AuthInfo();
    info.authType = cfg.getAuthType();
    info.useContributorAgreements = toBoolean(cfg.isUseContributorAgreements());
    info.editableAccountFields = new ArrayList<>(realm.getEditableFields());
    info.switchAccountUrl = cfg.getSwitchAccountUrl();
    info.gitBasicAuthPolicy = cfg.getGitBasicAuthPolicy();
    if (info.useContributorAgreements != null) {
        Collection<ContributorAgreement> agreements = projectCache.getAllProjects().getConfig().getContributorAgreements();
        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 = cfg.getRegisterUrl();
            info.registerText = cfg.getRegisterText();
            info.editFullNameUrl = cfg.getEditFullNameUrl();
            break;
        case CUSTOM_EXTENSION:
            info.registerUrl = cfg.getRegisterUrl();
            info.registerText = cfg.getRegisterText();
            info.editFullNameUrl = cfg.getEditFullNameUrl();
            info.httpPasswordUrl = cfg.getHttpPasswordUrl();
            break;
        case HTTP:
        case HTTP_LDAP:
            info.loginUrl = cfg.getLoginUrl();
            info.loginText = cfg.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.common.data.ContributorAgreement)

Example 2 with ContributorAgreement

use of com.google.gerrit.common.data.ContributorAgreement in project gerrit by GerritCodeReview.

the class GetAgreements method apply.

@Override
public List<AgreementInfo> apply(AccountResource resource) throws RestApiException {
    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()) {
        throw new AuthException("not allowed to get contributor agreements");
    }
    List<AgreementInfo> results = new ArrayList<>();
    Collection<ContributorAgreement> cas = projectCache.getAllProjects().getConfig().getContributorAgreements();
    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 {
                    log.warn("group \"" + rule.getGroup().getName() + "\" does not " + "exist, referenced in CLA \"" + ca.getName() + "\"");
                }
            }
        }
        if (user.getEffectiveGroups().containsAnyOf(groupIds)) {
            results.add(agreementJson.format(ca));
        }
    }
    return results;
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) PermissionRule(com.google.gerrit.common.data.PermissionRule) AgreementInfo(com.google.gerrit.extensions.common.AgreementInfo) ContributorAgreement(com.google.gerrit.common.data.ContributorAgreement) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser)

Example 3 with ContributorAgreement

use of com.google.gerrit.common.data.ContributorAgreement in project gerrit by GerritCodeReview.

the class ProjectConfig method saveContributorAgreements.

private void saveContributorAgreements(Config rc, Set<AccountGroup.UUID> keepGroups) {
    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 = new PermissionRule(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));
    }
}
Also used : PermissionRule(com.google.gerrit.common.data.PermissionRule) ContributorAgreement(com.google.gerrit.common.data.ContributorAgreement)

Example 4 with ContributorAgreement

use of com.google.gerrit.common.data.ContributorAgreement in project gerrit by GerritCodeReview.

the class ProjectConfig method getContributorAgreement.

public ContributorAgreement getContributorAgreement(String name, boolean create) {
    ContributorAgreement ca = contributorAgreements.get(name);
    if (ca == null && create) {
        ca = new ContributorAgreement(name);
        contributorAgreements.put(name, ca);
    }
    return ca;
}
Also used : ContributorAgreement(com.google.gerrit.common.data.ContributorAgreement)

Example 5 with ContributorAgreement

use of com.google.gerrit.common.data.ContributorAgreement in project gerrit by GerritCodeReview.

the class ProjectConfigTest method readConfig.

@Test
public void readConfig() throws Exception {
    RevCommit rev = util.commit(//
    util.tree(//
    util.file("groups", util.blob(group(developers))), util.file("project.config", util.blob(//
    "" + //
    "[access \"refs/heads/*\"]\n" + //
    "  exclusiveGroupPermissions = read submit create\n" + //
    "  submit = group Developers\n" + //
    "  push = group Developers\n" + //
    "  read = group Developers\n" + //
    "[accounts]\n" + //
    "  sameGroupVisibility = deny group Developers\n" + //
    "  sameGroupVisibility = block group Staff\n" + //
    "[contributor-agreement \"Individual\"]\n" + //
    "  description = A simple description\n" + //
    "  accepted = group Developers\n" + //
    "  accepted = group Staff\n" + //
    "  autoVerify = group Developers\n" + //
    "  agreementUrl = http://www.example.com/agree\n"))));
    ProjectConfig cfg = read(rev);
    assertThat(cfg.getAccountsSection().getSameGroupVisibility()).hasSize(2);
    ContributorAgreement ca = cfg.getContributorAgreement("Individual");
    assertThat(ca.getName()).isEqualTo("Individual");
    assertThat(ca.getDescription()).isEqualTo("A simple description");
    assertThat(ca.getAgreementUrl()).isEqualTo("http://www.example.com/agree");
    assertThat(ca.getAccepted()).hasSize(2);
    assertThat(ca.getAccepted().get(0).getGroup()).isEqualTo(developers);
    assertThat(ca.getAccepted().get(1).getGroup().getName()).isEqualTo("Staff");
    assertThat(ca.getAutoVerify().getName()).isEqualTo("Developers");
    AccessSection section = cfg.getAccessSection("refs/heads/*");
    assertThat(section).isNotNull();
    assertThat(cfg.getAccessSection("refs/*")).isNull();
    Permission create = section.getPermission(Permission.CREATE);
    Permission submit = section.getPermission(Permission.SUBMIT);
    Permission read = section.getPermission(Permission.READ);
    Permission push = section.getPermission(Permission.PUSH);
    assertThat(create.getExclusiveGroup()).isTrue();
    assertThat(submit.getExclusiveGroup()).isTrue();
    assertThat(read.getExclusiveGroup()).isTrue();
    assertThat(push.getExclusiveGroup()).isFalse();
}
Also used : ContributorAgreement(com.google.gerrit.common.data.ContributorAgreement) Permission(com.google.gerrit.common.data.Permission) AccessSection(com.google.gerrit.common.data.AccessSection) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

ContributorAgreement (com.google.gerrit.common.data.ContributorAgreement)10 PermissionRule (com.google.gerrit.common.data.PermissionRule)6 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)3 AccessSection (com.google.gerrit.common.data.AccessSection)2 Permission (com.google.gerrit.common.data.Permission)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)2 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)2 ArrayList (java.util.ArrayList)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 Test (org.junit.Test)2 Capable (com.google.gerrit.common.data.Capable)1 GroupReference (com.google.gerrit.common.data.GroupReference)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 IdString (com.google.gerrit.extensions.restapi.IdString)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)1