use of com.google.gerrit.extensions.common.AgreementInfo 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.extensions.common.AgreementInfo in project gerrit by GerritCodeReview.
the class AgreementJson method format.
public AgreementInfo format(ContributorAgreement ca) {
AgreementInfo info = new AgreementInfo();
info.name = ca.getName();
info.description = ca.getDescription();
info.url = ca.getAgreementUrl();
GroupReference autoVerifyGroup = ca.getAutoVerify();
if (autoVerifyGroup != null && self.get().isIdentifiedUser()) {
IdentifiedUser user = identifiedUserFactory.create(self.get().getAccountId());
try {
GroupControl gc = genericGroupControlFactory.controlFor(user, autoVerifyGroup.getUUID());
GroupResource group = new GroupResource(gc);
info.autoVerifyGroup = groupJson.format(group);
} catch (NoSuchGroupException | OrmException e) {
log.warn("autoverify group \"" + autoVerifyGroup.getName() + "\" does not exist, referenced in CLA \"" + ca.getName() + "\"");
}
}
return info;
}
use of com.google.gerrit.extensions.common.AgreementInfo in project gerrit by GerritCodeReview.
the class AgreementsIT method signAgreement.
@Test
public void signAgreement() throws Exception {
assume().that(isContributorAgreementsEnabled()).isTrue();
// List of agreements is initially empty
List<AgreementInfo> result = gApi.accounts().self().listAgreements();
assertThat(result).isEmpty();
// Sign the agreement
gApi.accounts().self().signAgreement(caAutoVerify.getName());
// Explicitly reset the user to force a new request context
setApiUser(user);
// Verify that the agreement was signed
result = gApi.accounts().self().listAgreements();
assertThat(result).hasSize(1);
AgreementInfo info = result.get(0);
assertAgreement(info, caAutoVerify);
// Signing the same agreement again has no effect
gApi.accounts().self().signAgreement(caAutoVerify.getName());
result = gApi.accounts().self().listAgreements();
assertThat(result).hasSize(1);
}
Aggregations