Search in sources :

Example 1 with UUID

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);
}
Also used : AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference) UUID(com.google.gerrit.entities.AccountGroup.UUID) Test(org.junit.Test)

Example 2 with UUID

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();
}
Also used : AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference) UUID(com.google.gerrit.entities.AccountGroup.UUID) Test(org.junit.Test)

Example 3 with UUID

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());
    }
}
Also used : PermissionRule(com.google.gerrit.entities.PermissionRule) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException) IOException(java.io.IOException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ContributorAgreement(com.google.gerrit.entities.ContributorAgreement) UUID(com.google.gerrit.entities.AccountGroup.UUID)

Example 4 with UUID

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);
}
Also used : GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference) UUID(com.google.gerrit.entities.AccountGroup.UUID) UUID(com.google.gerrit.entities.AccountGroup.UUID) Test(org.junit.Test)

Aggregations

UUID (com.google.gerrit.entities.AccountGroup.UUID)4 AccountGroup (com.google.gerrit.entities.AccountGroup)3 GroupReference (com.google.gerrit.entities.GroupReference)3 Test (org.junit.Test)3 ContributorAgreement (com.google.gerrit.entities.ContributorAgreement)1 GroupDescription (com.google.gerrit.entities.GroupDescription)1 PermissionRule (com.google.gerrit.entities.PermissionRule)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1