fix(queries): project grant and role prepare funcs (#2659)

* chore(queries): test suite for prepare stmt funcs

* test(queries): prepare project funcs

* refactor: add comments

* test: simlify expected sql, added possibility to add args to expected queries

* test(queries): prepare funcs in org

* chore(backend): correct modules

* test(queries): org domain prepare funcs

* test: correct name

* refactor: file name

* refactor: add table to login policy columns

* chore(prepare_test): only add row to result if columns

* test(queries): login policy prepare funcs

* chore: add comments for configs

* test(queries): prepare idp funcs

* fix(queries): add table to password complexity policy cols

* test(queries): password complexity policy prepare funcs

* fix(queries): add table to password age policy cols

* test(queries): password age policy prepare func

* fix(queries): set cols on lockout policy

* test(queries): lockout policy prepare funs

* fix(queries): set table on privacy policy cols

* test(queries): privacy policy prepare funcs

* fix(queries): set table on org iam policy cols

* fix(queries): correct table in org iam policy cols

* test(queries): org iam policy prepare funcs

* test(queries): prepare project grant funcs

* refactor(queries): prepareProjectRoleQuery as func

* test(queries): prepare project role funcs

* test(queries): project grant check for nulls in joins

* fix(queries): allow null values in project grant
This commit is contained in:
Silvan
2021-11-16 09:44:56 +01:00
committed by GitHub
parent ed547ee1d4
commit 9ddbc80e81
4 changed files with 1200 additions and 32 deletions

View File

@@ -255,20 +255,25 @@ func prepareProjectGrantQuery() (sq.SelectBuilder, func(*sql.Row) (*ProjectGrant
LeftJoin(join(resourceOwnerIDColumn, ProjectGrantColumnResourceOwner)).
LeftJoin(join(grantedOrgIDColumn, ProjectGrantColumnGrantedOrgID)),
func(row *sql.Row) (*ProjectGrant, error) {
p := new(ProjectGrant)
grant := new(ProjectGrant)
var (
projectName sql.NullString
orgName sql.NullString
resourceOwnerName sql.NullString
)
err := row.Scan(
&p.ProjectID,
&p.GrantID,
&p.CreationDate,
&p.ChangeDate,
&p.ResourceOwner,
&p.State,
&p.Sequence,
&p.ProjectName,
&p.GrantedOrgID,
&p.OrgName,
&p.GrantedRoleKeys,
&p.ResourceOwnerName,
&grant.ProjectID,
&grant.GrantID,
&grant.CreationDate,
&grant.ChangeDate,
&grant.ResourceOwner,
&grant.State,
&grant.Sequence,
&projectName,
&grant.GrantedOrgID,
&orgName,
&grant.GrantedRoleKeys,
&resourceOwnerName,
)
if err != nil {
if errs.Is(err, sql.ErrNoRows) {
@@ -276,7 +281,12 @@ func prepareProjectGrantQuery() (sq.SelectBuilder, func(*sql.Row) (*ProjectGrant
}
return nil, errors.ThrowInternal(err, "QUERY-w9fsH", "Errors.Internal")
}
return p, nil
grant.ProjectName = projectName.String
grant.ResourceOwnerName = resourceOwnerName.String
grant.OrgName = orgName.String
return grant, nil
}
}
@@ -305,28 +315,38 @@ func prepareProjectGrantsQuery() (sq.SelectBuilder, func(*sql.Rows) (*ProjectGra
LeftJoin(join(grantedOrgIDColumn, ProjectGrantColumnGrantedOrgID)),
func(rows *sql.Rows) (*ProjectGrants, error) {
projects := make([]*ProjectGrant, 0)
var count uint64
var (
count uint64
projectName sql.NullString
orgName sql.NullString
resourceOwnerName sql.NullString
)
for rows.Next() {
project := new(ProjectGrant)
grant := new(ProjectGrant)
err := rows.Scan(
&project.ProjectID,
&project.GrantID,
&project.CreationDate,
&project.ChangeDate,
&project.ResourceOwner,
&project.State,
&project.Sequence,
&project.ProjectName,
&project.GrantedOrgID,
&project.OrgName,
&project.GrantedRoleKeys,
&project.ResourceOwnerName,
&grant.ProjectID,
&grant.GrantID,
&grant.CreationDate,
&grant.ChangeDate,
&grant.ResourceOwner,
&grant.State,
&grant.Sequence,
&projectName,
&grant.GrantedOrgID,
&orgName,
&grant.GrantedRoleKeys,
&resourceOwnerName,
&count,
)
if err != nil {
return nil, err
}
projects = append(projects, project)
grant.ProjectName = projectName.String
grant.ResourceOwnerName = resourceOwnerName.String
grant.OrgName = orgName.String
projects = append(projects, grant)
}
if err := rows.Close(); err != nil {