Search in sources :

Example 6 with Organizations

use of com.walmartlabs.concord.server.jooq.tables.Organizations in project concord by walmartlabs.

the class OrganizationDao method get.

public OrganizationEntry get(DSLContext tx, UUID id) {
    Organizations o = ORGANIZATIONS.as("o");
    Users u = USERS.as("u");
    return tx.select(o.ORG_ID, o.ORG_NAME, o.OWNER_ID, u.USERNAME, u.DOMAIN, u.DISPLAY_NAME, u.USER_TYPE, o.VISIBILITY, o.META, o.ORG_CFG).from(o).leftJoin(u).on(u.USER_ID.eq(o.OWNER_ID)).where(o.ORG_ID.eq(id)).fetchOne(this::toEntry);
}
Also used : Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations) Users(com.walmartlabs.concord.server.jooq.tables.Users)

Example 7 with Organizations

use of com.walmartlabs.concord.server.jooq.tables.Organizations in project concord by walmartlabs.

the class ProjectDao method list.

public List<ProjectEntry> list(UUID orgId, UUID currentUserId, Field<?> sortField, boolean asc, int offset, int limit, String filter) {
    Users u = USERS.as("u");
    Projects p = PROJECTS.as("p");
    Organizations o = ORGANIZATIONS.as("o");
    sortField = p.field(sortField);
    SelectOnConditionStep<Record13<UUID, String, String, UUID, String, String, UUID, String, String, String, String, RawPayloadMode, OutVariablesMode>> q = dsl().select(p.PROJECT_ID, p.PROJECT_NAME, p.DESCRIPTION, p.ORG_ID, o.ORG_NAME, p.VISIBILITY, p.OWNER_ID, u.USERNAME, u.DOMAIN, u.DISPLAY_NAME, u.USER_TYPE, p.RAW_PAYLOAD_MODE, p.OUT_VARIABLES_MODE).from(p).leftJoin(u).on(u.USER_ID.eq(p.OWNER_ID)).leftJoin(o).on(o.ORG_ID.eq(p.ORG_ID));
    if (currentUserId != null) {
        // public projects are visible for anyone
        Condition isPublic = p.VISIBILITY.eq(ProjectVisibility.PUBLIC.toString());
        // check if the user belongs to a team in the org
        SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID).from(TEAMS).where(TEAMS.ORG_ID.eq(orgId));
        Condition isInATeam = exists(selectOne().from(V_USER_TEAMS).where(V_USER_TEAMS.USER_ID.eq(currentUserId).and(V_USER_TEAMS.TEAM_ID.in(teamIds))));
        // check if the user owns projects in the org
        Condition ownsProjects = p.OWNER_ID.eq(currentUserId);
        // check if the user owns the org
        Condition ownsOrg = o.OWNER_ID.eq(currentUserId);
        // if any of those conditions true then the project must be visible
        q.where(or(isPublic, isInATeam, ownsProjects, ownsOrg));
    }
    if (orgId != null) {
        q.where(p.ORG_ID.eq(orgId));
    }
    if (sortField != null) {
        q.orderBy(asc ? sortField.asc() : sortField.desc());
    }
    if (filter != null) {
        q.where(p.PROJECT_NAME.containsIgnoreCase(filter));
    }
    if (offset > 0) {
        q.offset(offset);
    }
    if (limit > 0) {
        q.limit(limit);
    }
    return q.fetch(ProjectDao::toEntry);
}
Also used : Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations) Projects(com.walmartlabs.concord.server.jooq.tables.Projects) Users(com.walmartlabs.concord.server.jooq.tables.Users)

Example 8 with Organizations

use of com.walmartlabs.concord.server.jooq.tables.Organizations in project concord by walmartlabs.

the class SecretDao method list.

public List<SecretEntry> list(UUID orgId, UUID currentUserId, Field<?> sortField, boolean asc, int offset, int limit, String filter) {
    Organizations o = ORGANIZATIONS.as("o");
    Secrets s = SECRETS.as("s");
    Projects p = PROJECTS.as("p");
    Users u = USERS.as("u");
    sortField = s.field(sortField);
    SelectOnConditionStep<Record15<UUID, String, UUID, String, UUID, String, String, String, String, String, UUID, String, String, String, String>> q = selectEntry(dsl(), o, s, p, u);
    if (currentUserId != null) {
        // public secrets are visible for anyone
        Condition isPublic = s.VISIBILITY.eq(SecretVisibility.PUBLIC.toString());
        // check if the user belongs to a team in the org
        SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID).from(TEAMS).where(TEAMS.ORG_ID.eq(orgId));
        Condition isInATeam = exists(selectOne().from(V_USER_TEAMS).where(V_USER_TEAMS.USER_ID.eq(currentUserId).and(V_USER_TEAMS.TEAM_ID.in(teamIds))));
        // check if the user owns secrets in the org
        Condition ownsSecrets = s.OWNER_ID.eq(currentUserId);
        // check if the user owns the org
        Condition ownsOrg = o.OWNER_ID.eq(currentUserId);
        // if any of those conditions true then the secret must be visible
        q.where(or(isPublic, isInATeam, ownsSecrets, ownsOrg));
    }
    if (orgId != null) {
        q.where(s.ORG_ID.eq(orgId));
    }
    if (filter != null) {
        q.where(s.SECRET_NAME.containsIgnoreCase(filter));
    }
    if (sortField != null) {
        q.orderBy(asc ? sortField.asc() : sortField.desc());
    }
    if (offset >= 0) {
        q.offset(offset);
    }
    if (limit > 0) {
        q.limit(limit);
    }
    return q.fetch(SecretDao::toEntry);
}
Also used : Secrets(com.walmartlabs.concord.server.jooq.tables.Secrets) Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations) Projects(com.walmartlabs.concord.server.jooq.tables.Projects) Users(com.walmartlabs.concord.server.jooq.tables.Users)

Aggregations

Organizations (com.walmartlabs.concord.server.jooq.tables.Organizations)8 Users (com.walmartlabs.concord.server.jooq.tables.Users)6 Projects (com.walmartlabs.concord.server.jooq.tables.Projects)4 Repositories (com.walmartlabs.concord.server.jooq.tables.Repositories)2 JsonStores (com.walmartlabs.concord.server.jooq.tables.JsonStores)1 Secrets (com.walmartlabs.concord.server.jooq.tables.Secrets)1 Triggers (com.walmartlabs.concord.server.jooq.tables.Triggers)1 OffsetDateTime (java.time.OffsetDateTime)1 ZoneId (java.time.ZoneId)1