2020-07-08 11:56:37 +00:00
|
|
|
package management
|
2020-03-24 09:14:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-06-15 14:50:09 +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/internal/api/authz"
|
|
|
|
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) CreateProject(ctx context.Context, in *management.ProjectCreateRequest) (*management.Project, error) {
|
2020-04-07 11:23:04 +00:00
|
|
|
project, err := s.project.CreateProject(ctx, in.Name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectFromModel(project), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) UpdateProject(ctx context.Context, in *management.ProjectUpdateRequest) (*management.Project, error) {
|
2020-04-07 11:23:04 +00:00
|
|
|
project, err := s.project.UpdateProject(ctx, projectUpdateToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectFromModel(project), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) DeactivateProject(ctx context.Context, in *management.ProjectID) (*management.Project, error) {
|
2020-04-07 11:23:04 +00:00
|
|
|
project, err := s.project.DeactivateProject(ctx, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectFromModel(project), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ReactivateProject(ctx context.Context, in *management.ProjectID) (*management.Project, error) {
|
2020-04-07 11:23:04 +00:00
|
|
|
project, err := s.project.ReactivateProject(ctx, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectFromModel(project), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 16:32:25 +00:00
|
|
|
func (s *Server) RemoveProject(ctx context.Context, in *management.ProjectID) (*empty.Empty, error) {
|
|
|
|
err := s.project.RemoveProject(ctx, in.Id)
|
|
|
|
return &empty.Empty{}, err
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) SearchProjects(ctx context.Context, in *management.ProjectSearchRequest) (*management.ProjectSearchResponse, error) {
|
2020-06-15 12:50:39 +00:00
|
|
|
request := projectSearchRequestsToModel(in)
|
2020-07-08 11:56:37 +00:00
|
|
|
request.AppendMyResourceOwnerQuery(grpc_util.GetHeader(ctx, http.ZitadelOrgID))
|
2020-06-15 12:50:39 +00:00
|
|
|
response, err := s.project.SearchProjects(ctx, request)
|
2020-05-11 10:16:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-15 12:50:39 +00:00
|
|
|
return projectSearchResponseFromModel(response), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ProjectByID(ctx context.Context, id *management.ProjectID) (*management.ProjectView, error) {
|
2020-04-07 11:23:04 +00:00
|
|
|
project, err := s.project.ProjectByID(ctx, id.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-23 05:06:07 +00:00
|
|
|
return projectViewFromModel(project), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) SearchGrantedProjects(ctx context.Context, in *management.GrantedProjectSearchRequest) (*management.ProjectGrantSearchResponse, error) {
|
2020-06-15 12:50:39 +00:00
|
|
|
request := grantedProjectSearchRequestsToModel(in)
|
2020-07-08 11:56:37 +00:00
|
|
|
request.AppendMyOrgQuery(grpc_util.GetHeader(ctx, http.ZitadelOrgID))
|
2020-07-22 12:00:29 +00:00
|
|
|
response, err := s.project.SearchGrantedProjects(ctx, request)
|
2020-06-15 12:50:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectGrantSearchResponseFromModel(response), nil
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) GetGrantedProjectByID(ctx context.Context, in *management.ProjectGrantID) (*management.ProjectGrantView, error) {
|
2020-06-15 12:50:39 +00:00
|
|
|
project, err := s.project.ProjectGrantViewByID(ctx, in.Id)
|
2020-05-11 10:16:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-15 12:50:39 +00:00
|
|
|
return projectGrantFromGrantedProjectModel(project), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) AddProjectRole(ctx context.Context, in *management.ProjectRoleAdd) (*management.ProjectRole, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
role, err := s.project.AddProjectRole(ctx, projectRoleAddToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectRoleFromModel(role), nil
|
|
|
|
}
|
2020-06-19 13:32:03 +00:00
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) BulkAddProjectRole(ctx context.Context, in *management.ProjectRoleAddBulk) (*empty.Empty, error) {
|
2020-06-19 13:32:03 +00:00
|
|
|
err := s.project.BulkAddProjectRole(ctx, projectRoleAddBulkToModel(in))
|
|
|
|
return &empty.Empty{}, err
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ChangeProjectRole(ctx context.Context, in *management.ProjectRoleChange) (*management.ProjectRole, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
role, err := s.project.ChangeProjectRole(ctx, projectRoleChangeToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectRoleFromModel(role), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-04-21 15:00:32 +00:00
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) RemoveProjectRole(ctx context.Context, in *management.ProjectRoleRemove) (*empty.Empty, error) {
|
2020-04-21 15:00:32 +00:00
|
|
|
err := s.project.RemoveProjectRole(ctx, in.Id, in.Key)
|
|
|
|
return &empty.Empty{}, err
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) SearchProjectRoles(ctx context.Context, in *management.ProjectRoleSearchRequest) (*management.ProjectRoleSearchResponse, error) {
|
2020-05-11 10:16:29 +00:00
|
|
|
request := projectRoleSearchRequestsToModel(in)
|
2020-07-08 11:56:37 +00:00
|
|
|
request.AppendMyOrgQuery(authz.GetCtxData(ctx).OrgID)
|
2020-07-15 11:24:36 +00:00
|
|
|
response, err := s.project.SearchProjectRoles(ctx, in.ProjectId, request)
|
2020-05-11 10:16:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectRoleSearchResponseFromModel(response), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ProjectChanges(ctx context.Context, changesRequest *management.ChangeRequest) (*management.Changes, error) {
|
2020-06-25 09:25:38 +00:00
|
|
|
response, err := s.project.ProjectChanges(ctx, changesRequest.Id, changesRequest.SequenceOffset, changesRequest.Limit, changesRequest.Asc)
|
2020-06-15 14:50:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return projectChangesToResponse(response, changesRequest.GetSequenceOffset(), changesRequest.GetLimit()), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|