2020-07-08 11:56:37 +00:00
|
|
|
package management
|
2020-03-24 09:14:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-07-09 14:47:48 +00:00
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
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
|
|
|
|
|
|
|
"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-09 14:47:48 +00:00
|
|
|
ctxData := authz.GetCtxData(ctx)
|
|
|
|
request.AppendMyResourceOwnerQuery(ctxData.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) {
|
2021-01-28 05:35:26 +00:00
|
|
|
grant, err := s.command.AddProjectGrant(ctx, projectGrantCreateToDomain(in), authz.GetCtxData(ctx).OrgID)
|
2020-04-23 05:54:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-28 05:35:26 +00:00
|
|
|
return projectGrantFromDomain(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) {
|
2021-01-28 05:35:26 +00:00
|
|
|
grant, err := s.command.ChangeProjectGrant(ctx, projectGrantUpdateToDomain(in), authz.GetCtxData(ctx).OrgID)
|
2020-04-23 05:54:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-28 05:35:26 +00:00
|
|
|
return projectGrantFromDomain(grant), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2021-01-28 05:35:26 +00:00
|
|
|
func (s *Server) DeactivateProjectGrant(ctx context.Context, in *management.ProjectGrantID) (*empty.Empty, error) {
|
|
|
|
err := s.command.DeactivateProjectGrant(ctx, in.ProjectId, in.Id, authz.GetCtxData(ctx).OrgID)
|
|
|
|
return &empty.Empty{}, err
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-04-23 05:54:40 +00:00
|
|
|
|
2021-01-28 05:35:26 +00:00
|
|
|
func (s *Server) ReactivateProjectGrant(ctx context.Context, in *management.ProjectGrantID) (*empty.Empty, error) {
|
|
|
|
err := s.command.ReactivateProjectGrant(ctx, in.ProjectId, in.Id, authz.GetCtxData(ctx).OrgID)
|
|
|
|
return &empty.Empty{}, err
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) RemoveProjectGrant(ctx context.Context, in *management.ProjectGrantID) (*empty.Empty, error) {
|
2021-01-28 05:35:26 +00:00
|
|
|
err := s.command.RemoveProjectGrant(ctx, in.ProjectId, in.Id, authz.GetCtxData(ctx).OrgID)
|
2020-04-23 05:54:40 +00:00
|
|
|
return &empty.Empty{}, err
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|