use of com.google.gerrit.entities.AccountGroup.UUID in project gerrit by GerritCodeReview.
the class GroupReferenceTest method create.
@Test
public void create() {
AccountGroup.UUID uuid = AccountGroup.uuid("uuid");
String name = "foo";
GroupReference groupReference = GroupReference.create(uuid, name);
assertThat(groupReference.getUUID()).isEqualTo(uuid);
assertThat(groupReference.getName()).isEqualTo(name);
}
use of com.google.gerrit.entities.AccountGroup.UUID in project gerrit by GerritCodeReview.
the class GroupReferenceTest method testEquals.
@Test
public void testEquals() {
AccountGroup.UUID uuid1 = AccountGroup.uuid("uuid-foo");
AccountGroup.UUID uuid2 = AccountGroup.uuid("uuid-bar");
String name1 = "foo";
String name2 = "bar";
GroupReference groupReference1 = GroupReference.create(uuid1, name1);
GroupReference groupReference2 = GroupReference.create(uuid1, name2);
GroupReference groupReference3 = GroupReference.create(uuid2, name1);
assertThat(groupReference1.equals(groupReference2)).isTrue();
assertThat(groupReference1.equals(groupReference3)).isFalse();
assertThat(groupReference2.equals(groupReference3)).isFalse();
}
use of com.google.gerrit.entities.AccountGroup.UUID in project gerrit by GerritCodeReview.
the class ContributorAgreementsChecker method check.
/**
* Checks if the user has signed a contributor agreement for the project.
*
* @throws AuthException if the user has not signed a contributor agreement for the project
* @throws IOException if project states could not be loaded
*/
public void check(Project.NameKey project, CurrentUser user) throws IOException, AuthException {
metrics.claCheckCount.increment();
ProjectState projectState = projectCache.get(project).orElseThrow(() -> new IOException("Can't load " + project));
if (!projectState.is(BooleanProjectConfig.USE_CONTRIBUTOR_AGREEMENTS)) {
return;
}
if (!user.isIdentifiedUser()) {
throw new AuthException("Must be logged in to verify Contributor Agreement");
}
IdentifiedUser iUser = user.asIdentifiedUser();
Collection<ContributorAgreement> contributorAgreements = projectCache.getAllProjects().getConfig().getContributorAgreements().values();
List<UUID> okGroupIds = new ArrayList<>();
for (ContributorAgreement ca : contributorAgreements) {
List<AccountGroup.UUID> groupIds;
groupIds = okGroupIds;
// matchProjects defaults to match all projects when missing.
List<String> matchProjectsRegexes = ca.getMatchProjectsRegexes();
if (!matchProjectsRegexes.isEmpty() && !projectMatchesAnyPattern(project.get(), matchProjectsRegexes)) {
// Doesn't match, isn't checked.
continue;
}
// excludeProjects defaults to exclude no projects when missing.
List<String> excludeProjectsRegexes = ca.getExcludeProjectsRegexes();
if (!excludeProjectsRegexes.isEmpty() && projectMatchesAnyPattern(project.get(), excludeProjectsRegexes)) {
// Matches, isn't checked.
continue;
}
for (PermissionRule rule : ca.getAccepted()) {
if ((rule.getAction() == Action.ALLOW) && (rule.getGroup() != null) && (rule.getGroup().getUUID() != null)) {
groupIds.add(AccountGroup.uuid(rule.getGroup().getUUID().get()));
}
}
}
if (!okGroupIds.isEmpty() && !iUser.getEffectiveGroups().containsAnyOf(okGroupIds)) {
final StringBuilder msg = new StringBuilder();
msg.append("No Contributor Agreement on file for user ").append(iUser.getNameEmail()).append(" (id=").append(iUser.getAccountId()).append(")");
msg.append(urlFormatter.get().getSettingsUrl("Agreements").orElse(""));
throw new AuthException(msg.toString());
}
}
use of com.google.gerrit.entities.AccountGroup.UUID in project gerrit by GerritCodeReview.
the class GroupReferenceTest method forGroupDescription.
@Test
public void forGroupDescription() {
String name = "foo";
AccountGroup.UUID uuid = AccountGroup.uuid("uuid-foo");
GroupReference groupReference = GroupReference.forGroup(new GroupDescription.Basic() {
@Override
public String getUrl() {
return null;
}
@Override
public String getName() {
return name;
}
@Override
public UUID getGroupUUID() {
return uuid;
}
@Override
public String getEmailAddress() {
return null;
}
});
assertThat(groupReference.getName()).isEqualTo(name);
assertThat(groupReference.getUUID()).isEqualTo(uuid);
}
Aggregations