fix: project grant join (#2525)

* fix: project grant join granted org name

* fix: search granted projects
This commit is contained in:
Fabi 2021-10-18 17:45:38 +02:00 committed by GitHub
parent 040b53305c
commit 25c009ad0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -63,7 +63,7 @@ func (s *Server) ListGrantedProjects(ctx context.Context, req *mgmt_pb.ListGrant
if err != nil {
return nil, err
}
err = queries.AppendMyResourceOwnerQuery(authz.GetCtxData(ctx).OrgID)
err = queries.AppendGrantedOrgQuery(authz.GetCtxData(ctx).OrgID)
if err != nil {
return nil, err
}

View File

@ -190,6 +190,10 @@ func NewProjectGrantResourceOwnerSearchQuery(value string) (SearchQuery, error)
return NewTextQuery(ProjectGrantColumnResourceOwner, value, TextEquals)
}
func NewProjectGrantGrantedOrgIDSearchQuery(value string) (SearchQuery, error) {
return NewTextQuery(ProjectGrantColumnGrantedOrgID, value, TextEquals)
}
func (r *ProjectGrantSearchQueries) AppendMyResourceOwnerQuery(orgID string) error {
query, err := NewProjectGrantResourceOwnerSearchQuery(orgID)
if err != nil {
@ -199,6 +203,15 @@ func (r *ProjectGrantSearchQueries) AppendMyResourceOwnerQuery(orgID string) err
return nil
}
func (r *ProjectGrantSearchQueries) AppendGrantedOrgQuery(orgID string) error {
query, err := NewProjectGrantGrantedOrgIDSearchQuery(orgID)
if err != nil {
return err
}
r.Queries = append(r.Queries, query)
return nil
}
func (r ProjectGrantSearchQueries) AppendPermissionQueries(permissions []string) error {
if !authz.HasGlobalPermission(permissions) {
ids := authz.GetAllPermissionCtxIDs(permissions)
@ -240,7 +253,7 @@ func prepareProjectGrantQuery() (sq.SelectBuilder, func(*sql.Row) (*ProjectGrant
From(projectGrantsTable.identifier()).PlaceholderFormat(sq.Dollar).
LeftJoin(join(ProjectColumnID, ProjectGrantColumnProjectID)).
LeftJoin(join(resourceOwnerIDColumn, ProjectGrantColumnResourceOwner)).
LeftJoin(join(grantedOrgIDColumn, ProjectGrantColumnResourceOwner)),
LeftJoin(join(grantedOrgIDColumn, ProjectGrantColumnGrantedOrgID)),
func(row *sql.Row) (*ProjectGrant, error) {
p := new(ProjectGrant)
err := row.Scan(
@ -289,8 +302,8 @@ func prepareProjectGrantsQuery() (sq.SelectBuilder, func(*sql.Rows) (*ProjectGra
From(projectGrantsTable.identifier()).PlaceholderFormat(sq.Dollar).
LeftJoin(join(ProjectColumnID, ProjectGrantColumnProjectID)).
LeftJoin(join(resourceOwnerIDColumn, ProjectGrantColumnResourceOwner)).
LeftJoin(join(grantedOrgIDColumn, ProjectGrantColumnResourceOwner)),
func(rows *sql.Rows) (*ProjectGrants, error) {
LeftJoin(join(grantedOrgIDColumn, ProjectGrantColumnGrantedOrgID)),
func(rows *sql.Rows) (*ProjectGrants, error) {
projects := make([]*ProjectGrant, 0)
var count uint64
for rows.Next() {