2020-07-08 11:56:37 +00:00
|
|
|
package management
|
2020-03-24 09:14:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
2020-05-11 08:16:27 +00:00
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
|
|
"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) SearchUserGrants(ctx context.Context, in *management.UserGrantSearchRequest) (*management.UserGrantSearchResponse, error) {
|
2020-05-12 04:30:53 +00:00
|
|
|
request := userGrantSearchRequestsToModel(in)
|
2020-07-08 11:56:37 +00:00
|
|
|
request.AppendMyOrgQuery(authz.GetCtxData(ctx).OrgID)
|
2020-05-12 04:30:53 +00:00
|
|
|
response, err := s.usergrant.SearchUserGrants(ctx, request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return userGrantSearchResponseFromModel(response), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) UserGrantByID(ctx context.Context, request *management.UserGrantID) (*management.UserGrantView, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.UserGrantByID(ctx, request.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-23 05:06:07 +00:00
|
|
|
return userGrantViewFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) DeactivateUserGrant(ctx context.Context, in *management.UserGrantID) (*management.UserGrant, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.DeactivateUserGrant(ctx, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ReactivateUserGrant(ctx context.Context, in *management.UserGrantID) (*management.UserGrant, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.ReactivateUserGrant(ctx, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) RemoveUserGrant(ctx context.Context, in *management.UserGrantID) (*empty.Empty, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
err := s.usergrant.RemoveUserGrant(ctx, in.Id)
|
|
|
|
return &empty.Empty{}, err
|
2020-06-19 13:32:03 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) BulkRemoveUserGrant(ctx context.Context, in *management.UserGrantRemoveBulk) (*empty.Empty, error) {
|
2020-06-19 13:32:03 +00:00
|
|
|
err := s.usergrant.BulkRemoveUserGrant(ctx, userGrantRemoveBulkToModel(in)...)
|
|
|
|
return &empty.Empty{}, err
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) SearchProjectUserGrants(ctx context.Context, in *management.ProjectUserGrantSearchRequest) (*management.UserGrantSearchResponse, error) {
|
2020-07-06 13:27:29 +00:00
|
|
|
request := projectUserGrantSearchRequestsToModel(in)
|
2020-07-08 11:56:37 +00:00
|
|
|
request.AppendMyOrgQuery(authz.GetCtxData(ctx).OrgID)
|
2020-07-06 13:27:29 +00:00
|
|
|
request.AppendProjectIDQuery(in.ProjectId)
|
|
|
|
response, err := s.usergrant.SearchUserGrants(ctx, request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return userGrantSearchResponseFromModel(response), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ProjectUserGrantByID(ctx context.Context, request *management.ProjectUserGrantID) (*management.UserGrantView, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.UserGrantByID(ctx, request.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-23 05:06:07 +00:00
|
|
|
return userGrantViewFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) CreateProjectUserGrant(ctx context.Context, in *management.UserGrantCreate) (*management.UserGrant, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.AddUserGrant(ctx, userGrantCreateToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) UpdateProjectUserGrant(ctx context.Context, in *management.ProjectUserGrantUpdate) (*management.UserGrant, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.ChangeUserGrant(ctx, projectUserGrantUpdateToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) DeactivateProjectUserGrant(ctx context.Context, in *management.ProjectUserGrantID) (*management.UserGrant, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.DeactivateUserGrant(ctx, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ReactivateProjectUserGrant(ctx context.Context, in *management.ProjectUserGrantID) (*management.UserGrant, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.ReactivateUserGrant(ctx, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) SearchProjectGrantUserGrants(ctx context.Context, in *management.ProjectGrantUserGrantSearchRequest) (*management.UserGrantSearchResponse, error) {
|
2020-07-06 13:27:29 +00:00
|
|
|
grant, err := s.project.ProjectGrantByID(ctx, in.ProjectGrantId)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
request := projectGrantUserGrantSearchRequestsToModel(in)
|
2020-07-08 11:56:37 +00:00
|
|
|
request.AppendMyOrgQuery(authz.GetCtxData(ctx).OrgID)
|
2020-07-06 13:27:29 +00:00
|
|
|
request.AppendProjectIDQuery(grant.ProjectID)
|
|
|
|
response, err := s.usergrant.SearchUserGrants(ctx, request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return userGrantSearchResponseFromModel(response), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ProjectGrantUserGrantByID(ctx context.Context, request *management.ProjectGrantUserGrantID) (*management.UserGrantView, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.UserGrantByID(ctx, request.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-23 05:06:07 +00:00
|
|
|
return userGrantViewFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) CreateProjectGrantUserGrant(ctx context.Context, in *management.ProjectGrantUserGrantCreate) (*management.UserGrant, error) {
|
2020-07-08 09:24:34 +00:00
|
|
|
user, err := s.usergrant.AddUserGrant(ctx, projectGrantUserGrantCreateToModel(in))
|
2020-05-11 08:16:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) UpdateProjectGrantUserGrant(ctx context.Context, in *management.ProjectGrantUserGrantUpdate) (*management.UserGrant, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.ChangeUserGrant(ctx, projectGrantUserGrantUpdateToModel(in))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) DeactivateProjectGrantUserGrant(ctx context.Context, in *management.ProjectGrantUserGrantID) (*management.UserGrant, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.DeactivateUserGrant(ctx, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func (s *Server) ReactivateProjectGrantUserGrant(ctx context.Context, in *management.ProjectGrantUserGrantID) (*management.UserGrant, error) {
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := s.usergrant.ReactivateUserGrant(ctx, in.Id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return usergrantFromModel(user), nil
|
2020-03-24 09:14:39 +00:00
|
|
|
}
|