2020-07-08 11:56:37 +00:00
|
|
|
package management
|
2020-03-24 09:14:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-26 14:46:16 +00:00
|
|
|
|
2020-03-24 09:14:39 +00:00
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
|
|
|
grpc_util "github.com/caos/zitadel/internal/api/grpc"
|
|
|
|
"github.com/caos/zitadel/internal/api/http"
|
|
|
|
"github.com/caos/zitadel/pkg/grpc/management"
|
2020-03-24 09:14:39 +00:00
|
|
|
)
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) SearchProjectGrants(ctx context.Context, in *management.ProjectGrantSearchRequest) (*management.ProjectGrantSearchResponse, error) {
|
2020-05-11 10:16:29 +00:00
|
|
|
request := projectGrantSearchRequestsToModel(in)
|
2020-07-08 11:56:37 +00:00
|
|
|
orgID := grpc_util.GetHeader(ctx, http.ZitadelOrgID)
|
2020-05-12 04:30:53 +00:00
|
|
|
request.AppendMyResourceOwnerQuery(orgID)
|
|
|
|
request.AppendNotMyOrgQuery(orgID)
|
2020-06-15 12:50:39 +00:00
|
|
|
response, err := s.project.SearchProjectGrants(ctx, request)
|
2020-05-11 10:16:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectGrantSearchResponseFromModel(response), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ProjectGrantByID(ctx context.Context, in *management.ProjectGrantID) (*management.ProjectGrantView, error) {
|
2020-06-23 05:06:07 +00:00
|
|
|
grant, err := s.project.ProjectGrantByID(ctx, in.Id)
|
2020-04-23 05:54:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-23 05:06:07 +00:00
|
|
|
return projectGrantFromGrantedProjectModel(grant), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) CreateProjectGrant(ctx context.Context, in *management.ProjectGrantCreate) (*management.ProjectGrant, error) {
|
2020-04-23 05:54:40 +00:00
|
|
|
grant, err := s.project.AddProjectGrant(ctx, projectGrantCreateToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectGrantFromModel(grant), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) UpdateProjectGrant(ctx context.Context, in *management.ProjectGrantUpdate) (*management.ProjectGrant, error) {
|
2020-04-23 05:54:40 +00:00
|
|
|
grant, err := s.project.ChangeProjectGrant(ctx, projectGrantUpdateToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectGrantFromModel(grant), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) DeactivateProjectGrant(ctx context.Context, in *management.ProjectGrantID) (*management.ProjectGrant, error) {
|
2020-04-23 05:54:40 +00:00
|
|
|
grant, err := s.project.DeactivateProjectGrant(ctx, in.ProjectId, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectGrantFromModel(grant), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-04-23 05:54:40 +00:00
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ReactivateProjectGrant(ctx context.Context, in *management.ProjectGrantID) (*management.ProjectGrant, error) {
|
2020-04-23 05:54:40 +00:00
|
|
|
grant, err := s.project.ReactivateProjectGrant(ctx, in.ProjectId, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectGrantFromModel(grant), nil
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) RemoveProjectGrant(ctx context.Context, in *management.ProjectGrantID) (*empty.Empty, error) {
|
2020-04-23 05:54:40 +00:00
|
|
|
err := s.project.RemoveProjectGrant(ctx, in.ProjectId, in.Id)
|
|
|
|
return &empty.Empty{}, err
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|