Search in sources :

Example 1 with Users

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

the class OrganizationDao method list.

public List<OrganizationEntry> list(UUID currentUserId, boolean onlyCurrent, int offset, int limit, String filter) {
    Organizations o = ORGANIZATIONS.as("o");
    Users u = USERS.as("u");
    SelectOnConditionStep<Record10<UUID, String, UUID, String, String, String, String, String, JSONB, JSONB>> q = dsl().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));
    if (currentUserId != null) {
        // public orgs are visible for anyone
        // but show them only if onlyCurrent == false
        // i.e. when the user specifically asked to show all available orgs
        Condition isPublic = value(onlyCurrent).isFalse().and(o.VISIBILITY.eq(OrganizationVisibility.PUBLIC.toString()));
        // check if the user belongs to a team in an org
        SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID).from(TEAMS).where(TEAMS.ORG_ID.eq(o.ORG_ID));
        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 orgs
        Condition ownsOrgs = o.OWNER_ID.eq(currentUserId);
        // if any of those conditions true then the org must be visible
        q.where(or(isPublic, isInATeam, ownsOrgs));
    }
    if (filter != null) {
        q.where(o.ORG_NAME.containsIgnoreCase(filter));
    }
    if (offset >= 0) {
        q.offset(offset);
    }
    if (limit > 0) {
        q.limit(limit);
    }
    return q.orderBy(o.ORG_NAME).fetch(this::toEntry);
}
Also used : Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations) Users(com.walmartlabs.concord.server.jooq.tables.Users)

Example 2 with Users

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

the class OrganizationDao method getByName.

public OrganizationEntry getByName(DSLContext tx, String name) {
    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_NAME.eq(name)).fetchOne(this::toEntry);
}
Also used : Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations) Users(com.walmartlabs.concord.server.jooq.tables.Users)

Example 3 with Users

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

the class AuditDao method list.

public List<AuditLogEntry> list(AuditLogFilter filter) {
    return txResult(tx -> {
        AuditLog l = AUDIT_LOG.as("l");
        Users u = USERS.as("u");
        SelectOnConditionStep<Record9<OffsetDateTime, String, String, JSONB, UUID, String, String, String, String>> q = tx.select(l.ENTRY_DATE, l.ENTRY_ACTION, l.ENTRY_OBJECT, l.ENTRY_DETAILS, u.USER_ID, u.USERNAME, u.DOMAIN, u.USER_TYPE, u.DISPLAY_NAME).from(l).leftJoin(u).on(u.USER_ID.eq(l.USER_ID));
        AuditObject object = filter.object();
        if (object != null) {
            q.where(l.ENTRY_OBJECT.eq(object.name()));
        }
        AuditAction action = filter.action();
        if (action != null) {
            q.where(l.ENTRY_ACTION.eq(action.name()));
        }
        UUID userId = filter.userId();
        if (userId != null) {
            q.where(l.USER_ID.eq(userId));
        }
        Map<String, Object> details = filter.details();
        if (details != null) {
            q.where(PgUtils.jsonbContains(l.ENTRY_DETAILS, objectMapper.toJSONB(details)));
        }
        OffsetDateTime after = filter.after();
        if (after != null) {
            q.where(l.ENTRY_DATE.greaterThan(after));
        }
        OffsetDateTime before = filter.before();
        if (before != null) {
            q.where(l.ENTRY_DATE.lessThan(before));
        }
        Integer limit = filter.limit();
        if (limit != null) {
            q.limit(limit);
        }
        Integer offset = filter.offset();
        if (offset != null) {
            q.offset(offset);
        }
        q.orderBy(l.ENTRY_DATE.desc(), l.ENTRY_SEQ.desc());
        return q.fetch(this::toEntry);
    });
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Record9(org.jooq.Record9) Users(com.walmartlabs.concord.server.jooq.tables.Users) UUID(java.util.UUID) AuditLog(com.walmartlabs.concord.server.jooq.tables.AuditLog)

Example 4 with Users

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

the class JsonStoreDao method list.

public List<JsonStoreEntry> list(UUID orgId, UUID currentUserId, int offset, int limit, String filter) {
    Organizations o = ORGANIZATIONS.as("o");
    JsonStores j = JSON_STORES.as("j");
    Users u = USERS.as("u");
    SelectJoinStep<Record10<UUID, String, UUID, String, String, UUID, String, String, String, String>> q = buildSelect(dsl(), o, j, u);
    if (currentUserId != null) {
        // public stores are visible for anyone
        Condition isPublic = j.VISIBILITY.eq(JsonStoreVisibility.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(Tables.V_USER_TEAMS).where(Tables.V_USER_TEAMS.USER_ID.eq(currentUserId).and(Tables.V_USER_TEAMS.TEAM_ID.in(teamIds))));
        // check if the user owns stores in the org
        Condition ownsStores = j.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 store must be visible
        q.where(or(isPublic, isInATeam, ownsStores, ownsOrg));
    }
    if (filter != null) {
        q.where(j.JSON_STORE_NAME.containsIgnoreCase(filter));
    }
    if (offset >= 0) {
        q.offset(offset);
    }
    if (limit > 0) {
        q.limit(limit);
    }
    return q.where(j.ORG_ID.eq(orgId)).orderBy(j.JSON_STORE_NAME).fetch(JsonStoreDao::toEntity);
}
Also used : Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations) JsonStores(com.walmartlabs.concord.server.jooq.tables.JsonStores) Users(com.walmartlabs.concord.server.jooq.tables.Users)

Example 5 with Users

use of com.walmartlabs.concord.server.jooq.tables.Users 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)

Aggregations

Users (com.walmartlabs.concord.server.jooq.tables.Users)8 Organizations (com.walmartlabs.concord.server.jooq.tables.Organizations)6 Projects (com.walmartlabs.concord.server.jooq.tables.Projects)3 OutVariablesMode (com.walmartlabs.concord.server.jooq.enums.OutVariablesMode)1 RawPayloadMode (com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)1 AuditLog (com.walmartlabs.concord.server.jooq.tables.AuditLog)1 JsonStores (com.walmartlabs.concord.server.jooq.tables.JsonStores)1 Secrets (com.walmartlabs.concord.server.jooq.tables.Secrets)1 OffsetDateTime (java.time.OffsetDateTime)1 UUID (java.util.UUID)1 Record9 (org.jooq.Record9)1