zitadel/pkg/management/api/grpc/project_grant.go
Silvan 3025ac577b
feat: org queries (#136)
* search orgs

* org by domain

* member spooler

* member

* get roles

* tests

* types duration

* use default func for renew

* correct database

* reorder migrations

* delete unused consts

* move get roles to internal

* use prepared org by domain

* implement org in other objects

* add eventstores
2020-05-26 16:46:16 +02:00

65 lines
2.1 KiB
Go

package grpc
import (
"context"
"github.com/caos/zitadel/internal/api"
grpc_util "github.com/caos/zitadel/internal/api/grpc"
"github.com/golang/protobuf/ptypes/empty"
)
func (s *Server) SearchProjectGrants(ctx context.Context, in *ProjectGrantSearchRequest) (*ProjectGrantSearchResponse, error) {
request := projectGrantSearchRequestsToModel(in)
orgID := grpc_util.GetHeader(ctx, api.ZitadelOrgID)
request.AppendMyResourceOwnerQuery(orgID)
request.AppendNotMyOrgQuery(orgID)
response, err := s.project.SearchGrantedProjects(ctx, request)
if err != nil {
return nil, err
}
return projectGrantSearchResponseFromModel(response), nil
}
func (s *Server) ProjectGrantByID(ctx context.Context, in *ProjectGrantID) (*ProjectGrant, error) {
grant, err := s.project.ProjectGrantByID(ctx, in.ProjectId, in.Id)
if err != nil {
return nil, err
}
return projectGrantFromModel(grant), nil
}
func (s *Server) CreateProjectGrant(ctx context.Context, in *ProjectGrantCreate) (*ProjectGrant, error) {
grant, err := s.project.AddProjectGrant(ctx, projectGrantCreateToModel(in))
if err != nil {
return nil, err
}
return projectGrantFromModel(grant), nil
}
func (s *Server) UpdateProjectGrant(ctx context.Context, in *ProjectGrantUpdate) (*ProjectGrant, error) {
grant, err := s.project.ChangeProjectGrant(ctx, projectGrantUpdateToModel(in))
if err != nil {
return nil, err
}
return projectGrantFromModel(grant), nil
}
func (s *Server) DeactivateProjectGrant(ctx context.Context, in *ProjectGrantID) (*ProjectGrant, error) {
grant, err := s.project.DeactivateProjectGrant(ctx, in.ProjectId, in.Id)
if err != nil {
return nil, err
}
return projectGrantFromModel(grant), nil
}
func (s *Server) ReactivateProjectGrant(ctx context.Context, in *ProjectGrantID) (*ProjectGrant, error) {
grant, err := s.project.ReactivateProjectGrant(ctx, in.ProjectId, in.Id)
if err != nil {
return nil, err
}
return projectGrantFromModel(grant), nil
}
func (s *Server) RemoveProjectGrant(ctx context.Context, in *ProjectGrantID) (*empty.Empty, error) {
err := s.project.RemoveProjectGrant(ctx, in.ProjectId, in.Id)
return &empty.Empty{}, err
}