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