fix: project role delete (#431)

This commit is contained in:
Fabi 2020-07-09 16:47:48 +02:00 committed by GitHub
parent f664ad7f88
commit cde6231164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -2,19 +2,17 @@ package management
import (
"context"
"github.com/caos/zitadel/internal/api/authz"
"github.com/golang/protobuf/ptypes/empty"
grpc_util "github.com/caos/zitadel/internal/api/grpc"
"github.com/caos/zitadel/internal/api/http"
"github.com/caos/zitadel/pkg/grpc/management"
)
func (s *Server) SearchProjectGrants(ctx context.Context, in *management.ProjectGrantSearchRequest) (*management.ProjectGrantSearchResponse, error) {
request := projectGrantSearchRequestsToModel(in)
orgID := grpc_util.GetHeader(ctx, http.ZitadelOrgID)
request.AppendMyResourceOwnerQuery(orgID)
request.AppendNotMyOrgQuery(orgID)
ctxData := authz.GetCtxData(ctx)
request.AppendMyResourceOwnerQuery(ctxData.OrgID)
response, err := s.project.SearchProjectGrants(ctx, request)
if err != nil {
return nil, err

View File

@ -340,13 +340,16 @@ func (es *ProjectEventstore) PrepareRemoveProjectRole(ctx context.Context, role
}
func (es *ProjectEventstore) RemoveRoleFromGrants(existing *model.Project, roleKey string) []*model.ProjectGrant {
grants := make([]*model.ProjectGrant, 0)
for _, grant := range existing.Grants {
grants := make([]*model.ProjectGrant, len(existing.Grants))
for i, grant := range existing.Grants {
roles := make([]string, 0)
for _, role := range grant.RoleKeys {
if role != roleKey {
grants = append(grants, grant)
roles = append(roles, role)
}
}
grant.RoleKeys = roles
grants[i] = grant
}
return grants
}