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;
}
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;
}
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));
}
}
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;
}
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();
}
Aggregations