fix(query): realtime data on defined requests (#3726)

* feat: directly specify factors on addCustomLoginPolicy and return on LoginPolicy responses

* fix proto

* update login policy

* feat: directly specify idp on addCustomLoginPolicy and return on LoginPolicy responses

* fix: tests

* fix(projection): trigger bulk

* refactor: clean projection pkg

* instance should bulk

* fix(query): should trigger bulk on id calls

* tests

* build prerelease

* fix: add shouldTriggerBulk

* fix: test

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
Co-authored-by: Max Peintner <max@caos.ch>
This commit is contained in:
Silvan
2022-06-14 07:51:00 +02:00
committed by GitHub
parent 5c805c48db
commit dd2f31683c
146 changed files with 1097 additions and 1239 deletions

View File

@@ -3,7 +3,6 @@ package query
import (
"context"
"database/sql"
errs "errors"
"time"
sq "github.com/Masterminds/squirrel"
@@ -77,28 +76,11 @@ type ProjectRoleSearchQueries struct {
Queries []SearchQuery
}
func (q *Queries) ProjectRoleByID(ctx context.Context, projectID, key string) (*ProjectRole, error) {
stmt, scan := prepareProjectRoleQuery()
query, args, err := stmt.
Where(sq.Eq{
ProjectRoleColumnProjectID.identifier(): projectID,
ProjectRoleColumnKey.identifier(): key,
ProjectRoleColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID(),
}).ToSql()
if err != nil {
return nil, errors.ThrowInternal(err, "QUERY-2N0fs", "Errors.Query.SQLStatment")
func (q *Queries) SearchProjectRoles(ctx context.Context, shouldTriggerBulk bool, queries *ProjectRoleSearchQueries) (projects *ProjectRoles, err error) {
if shouldTriggerBulk {
projection.ProjectRoleProjection.TriggerBulk(ctx)
}
row := q.client.QueryRowContext(ctx, query, args...)
return scan(row)
}
func (q *Queries) ExistsProjectRole(ctx context.Context, projectID, key string) (err error) {
_, err = q.ProjectRoleByID(ctx, projectID, key)
return err
}
func (q *Queries) SearchProjectRoles(ctx context.Context, queries *ProjectRoleSearchQueries) (projects *ProjectRoles, err error) {
query, scan := prepareProjectRolesQuery()
stmt, args, err := queries.toQuery(query).
Where(sq.Eq{
@@ -213,39 +195,6 @@ func (q *ProjectRoleSearchQueries) toQuery(query sq.SelectBuilder) sq.SelectBuil
return query
}
func prepareProjectRoleQuery() (sq.SelectBuilder, func(*sql.Row) (*ProjectRole, error)) {
return sq.Select(
ProjectRoleColumnProjectID.identifier(),
ProjectRoleColumnCreationDate.identifier(),
ProjectRoleColumnChangeDate.identifier(),
ProjectRoleColumnResourceOwner.identifier(),
ProjectRoleColumnSequence.identifier(),
ProjectRoleColumnKey.identifier(),
ProjectRoleColumnDisplayName.identifier(),
ProjectRoleColumnGroupName.identifier()).
From(projectRolesTable.identifier()).PlaceholderFormat(sq.Dollar),
func(row *sql.Row) (*ProjectRole, error) {
p := new(ProjectRole)
err := row.Scan(
&p.ProjectID,
&p.CreationDate,
&p.ChangeDate,
&p.ResourceOwner,
&p.Sequence,
&p.Key,
&p.DisplayName,
&p.Group,
)
if err != nil {
if errs.Is(err, sql.ErrNoRows) {
return nil, errors.ThrowNotFound(err, "QUERY-Mf0wf", "Errors.ProjectRole.NotFound")
}
return nil, errors.ThrowInternal(err, "QUERY-M00sf", "Errors.Internal")
}
return p, nil
}
}
func prepareProjectRolesQuery() (sq.SelectBuilder, func(*sql.Rows) (*ProjectRoles, error)) {
return sq.Select(
ProjectRoleColumnProjectID.identifier(),