mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
5251fc712c
* fix: add needed permissions * feat: search project/projectgrant user grants * fix: no zitadel permissions * fix: queries length
180 lines
6.0 KiB
Go
180 lines
6.0 KiB
Go
package grpc
|
|
|
|
import (
|
|
"context"
|
|
"github.com/caos/zitadel/internal/api/auth"
|
|
"github.com/golang/protobuf/ptypes/empty"
|
|
)
|
|
|
|
func (s *Server) SearchUserGrants(ctx context.Context, in *UserGrantSearchRequest) (*UserGrantSearchResponse, error) {
|
|
request := userGrantSearchRequestsToModel(in)
|
|
request.AppendMyOrgQuery(auth.GetCtxData(ctx).OrgID)
|
|
response, err := s.usergrant.SearchUserGrants(ctx, request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userGrantSearchResponseFromModel(response), nil
|
|
}
|
|
|
|
func (s *Server) UserGrantByID(ctx context.Context, request *UserGrantID) (*UserGrantView, error) {
|
|
user, err := s.usergrant.UserGrantByID(ctx, request.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userGrantViewFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) CreateUserGrant(ctx context.Context, in *UserGrantCreate) (*UserGrant, error) {
|
|
user, err := s.usergrant.AddUserGrant(ctx, userGrantCreateToModel(in))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) UpdateUserGrant(ctx context.Context, in *UserGrantUpdate) (*UserGrant, error) {
|
|
user, err := s.usergrant.ChangeUserGrant(ctx, userGrantUpdateToModel(in))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
func (s *Server) DeactivateUserGrant(ctx context.Context, in *UserGrantID) (*UserGrant, error) {
|
|
user, err := s.usergrant.DeactivateUserGrant(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
func (s *Server) ReactivateUserGrant(ctx context.Context, in *UserGrantID) (*UserGrant, error) {
|
|
user, err := s.usergrant.ReactivateUserGrant(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) RemoveUserGrant(ctx context.Context, in *UserGrantID) (*empty.Empty, error) {
|
|
err := s.usergrant.RemoveUserGrant(ctx, in.Id)
|
|
return &empty.Empty{}, err
|
|
}
|
|
|
|
func (s *Server) BulkCreateUserGrant(ctx context.Context, in *UserGrantCreateBulk) (*empty.Empty, error) {
|
|
err := s.usergrant.BulkAddUserGrant(ctx, userGrantCreateBulkToModel(in)...)
|
|
return &empty.Empty{}, err
|
|
}
|
|
|
|
func (s *Server) BulkUpdateUserGrant(ctx context.Context, in *UserGrantUpdateBulk) (*empty.Empty, error) {
|
|
err := s.usergrant.BulkChangeUserGrant(ctx, userGrantUpdateBulkToModel(in)...)
|
|
return &empty.Empty{}, err
|
|
}
|
|
|
|
func (s *Server) BulkRemoveUserGrant(ctx context.Context, in *UserGrantRemoveBulk) (*empty.Empty, error) {
|
|
err := s.usergrant.BulkRemoveUserGrant(ctx, userGrantRemoveBulkToModel(in)...)
|
|
return &empty.Empty{}, err
|
|
}
|
|
|
|
func (s *Server) SearchProjectUserGrants(ctx context.Context, in *ProjectUserGrantSearchRequest) (*UserGrantSearchResponse, error) {
|
|
request := projectUserGrantSearchRequestsToModel(in)
|
|
request.AppendMyOrgQuery(auth.GetCtxData(ctx).OrgID)
|
|
request.AppendProjectIDQuery(in.ProjectId)
|
|
response, err := s.usergrant.SearchUserGrants(ctx, request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userGrantSearchResponseFromModel(response), nil
|
|
}
|
|
|
|
func (s *Server) ProjectUserGrantByID(ctx context.Context, request *ProjectUserGrantID) (*UserGrantView, error) {
|
|
user, err := s.usergrant.UserGrantByID(ctx, request.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userGrantViewFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) CreateProjectUserGrant(ctx context.Context, in *UserGrantCreate) (*UserGrant, error) {
|
|
user, err := s.usergrant.AddUserGrant(ctx, userGrantCreateToModel(in))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
func (s *Server) UpdateProjectUserGrant(ctx context.Context, in *ProjectUserGrantUpdate) (*UserGrant, error) {
|
|
user, err := s.usergrant.ChangeUserGrant(ctx, projectUserGrantUpdateToModel(in))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) DeactivateProjectUserGrant(ctx context.Context, in *ProjectUserGrantID) (*UserGrant, error) {
|
|
user, err := s.usergrant.DeactivateUserGrant(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) ReactivateProjectUserGrant(ctx context.Context, in *ProjectUserGrantID) (*UserGrant, error) {
|
|
user, err := s.usergrant.ReactivateUserGrant(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) SearchProjectGrantUserGrants(ctx context.Context, in *ProjectGrantUserGrantSearchRequest) (*UserGrantSearchResponse, error) {
|
|
grant, err := s.project.ProjectGrantByID(ctx, in.ProjectGrantId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
request := projectGrantUserGrantSearchRequestsToModel(in)
|
|
request.AppendMyOrgQuery(auth.GetCtxData(ctx).OrgID)
|
|
request.AppendProjectIDQuery(grant.ProjectID)
|
|
response, err := s.usergrant.SearchUserGrants(ctx, request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userGrantSearchResponseFromModel(response), nil
|
|
}
|
|
|
|
func (s *Server) ProjectGrantUserGrantByID(ctx context.Context, request *ProjectGrantUserGrantID) (*UserGrantView, error) {
|
|
user, err := s.usergrant.UserGrantByID(ctx, request.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userGrantViewFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) CreateProjectGrantUserGrant(ctx context.Context, in *ProjectGrantUserGrantCreate) (*UserGrant, error) {
|
|
user, err := s.usergrant.ChangeUserGrant(ctx, projectGrantUserGrantCreateToModel(in))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
func (s *Server) UpdateProjectGrantUserGrant(ctx context.Context, in *ProjectGrantUserGrantUpdate) (*UserGrant, error) {
|
|
user, err := s.usergrant.ChangeUserGrant(ctx, projectGrantUserGrantUpdateToModel(in))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) DeactivateProjectGrantUserGrant(ctx context.Context, in *ProjectGrantUserGrantID) (*UserGrant, error) {
|
|
user, err := s.usergrant.DeactivateUserGrant(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) ReactivateProjectGrantUserGrant(ctx context.Context, in *ProjectGrantUserGrantID) (*UserGrant, error) {
|
|
user, err := s.usergrant.ReactivateUserGrant(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return usergrantFromModel(user), nil
|
|
}
|