mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
3549a8b64e
* move mgmt pkg * begin package restructure * rename auth package to authz * begin start api * move auth * move admin * fix merge * configs and interceptors * interceptor * revert generate-grpc.sh * some cleanups * console * move console * fix tests and merging * js linting * merge * merging and configs * change k8s base to current ports * fixes * cleanup * regenerate proto * remove unnecessary whitespace * missing param * go mod tidy * fix merging * move login pkg * cleanup * move api pkgs again * fix pkg naming * fix generate-static.sh for login * update workflow * fixes * logging * remove duplicate * comment for optional gateway interfaces * regenerate protos * fix proto imports for grpc web * protos * grpc web generate * grpc web generate * fix changes * add translation interceptor * fix merging * regenerate mgmt proto
197 lines
6.4 KiB
Go
197 lines
6.4 KiB
Go
package management
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
|
|
|
grpc_util "github.com/caos/zitadel/internal/api/grpc"
|
|
"github.com/caos/zitadel/internal/api/http"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/pkg/grpc/management"
|
|
)
|
|
|
|
func (s *Server) GetUserByID(ctx context.Context, id *management.UserID) (*management.UserView, error) {
|
|
user, err := s.user.UserByID(ctx, id.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userViewFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) GetUserByEmailGlobal(ctx context.Context, email *management.Email) (*management.UserView, error) {
|
|
user, err := s.user.GetGlobalUserByEmail(ctx, email.Email)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userViewFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) SearchUsers(ctx context.Context, in *management.UserSearchRequest) (*management.UserSearchResponse, error) {
|
|
request := userSearchRequestsToModel(in)
|
|
orgID := grpc_util.GetHeader(ctx, http.ZitadelOrgID)
|
|
request.AppendMyOrgQuery(orgID)
|
|
response, err := s.user.SearchUsers(ctx, request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userSearchResponseFromModel(response), nil
|
|
}
|
|
|
|
func (s *Server) UserChanges(ctx context.Context, changesRequest *management.ChangeRequest) (*management.Changes, error) {
|
|
response, err := s.user.UserChanges(ctx, changesRequest.Id, changesRequest.SequenceOffset, changesRequest.Limit, changesRequest.Asc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userChangesToResponse(response, changesRequest.GetSequenceOffset(), changesRequest.GetLimit()), nil
|
|
}
|
|
|
|
func (s *Server) IsUserUnique(ctx context.Context, request *management.UniqueUserRequest) (*management.UniqueUserResponse, error) {
|
|
unique, err := s.user.IsUserUnique(ctx, request.UserName, request.Email)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &management.UniqueUserResponse{IsUnique: unique}, nil
|
|
}
|
|
|
|
func (s *Server) CreateUser(ctx context.Context, in *management.CreateUserRequest) (*management.User, error) {
|
|
user, err := s.user.CreateUser(ctx, userCreateToModel(in))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) DeactivateUser(ctx context.Context, in *management.UserID) (*management.User, error) {
|
|
user, err := s.user.DeactivateUser(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) ReactivateUser(ctx context.Context, in *management.UserID) (*management.User, error) {
|
|
user, err := s.user.ReactivateUser(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) LockUser(ctx context.Context, in *management.UserID) (*management.User, error) {
|
|
user, err := s.user.LockUser(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) UnlockUser(ctx context.Context, in *management.UserID) (*management.User, error) {
|
|
user, err := s.user.UnlockUser(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userFromModel(user), nil
|
|
}
|
|
|
|
func (s *Server) DeleteUser(ctx context.Context, in *management.UserID) (*empty.Empty, error) {
|
|
return nil, errors.ThrowUnimplemented(nil, "GRPC-as4fg", "Not implemented")
|
|
}
|
|
|
|
func (s *Server) GetUserProfile(ctx context.Context, in *management.UserID) (*management.UserProfileView, error) {
|
|
profile, err := s.user.ProfileByID(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return profileViewFromModel(profile), nil
|
|
}
|
|
|
|
func (s *Server) UpdateUserProfile(ctx context.Context, request *management.UpdateUserProfileRequest) (*management.UserProfile, error) {
|
|
profile, err := s.user.ChangeProfile(ctx, updateProfileToModel(request))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return profileFromModel(profile), nil
|
|
}
|
|
|
|
func (s *Server) GetUserEmail(ctx context.Context, in *management.UserID) (*management.UserEmailView, error) {
|
|
email, err := s.user.EmailByID(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return emailViewFromModel(email), nil
|
|
}
|
|
|
|
func (s *Server) ChangeUserEmail(ctx context.Context, request *management.UpdateUserEmailRequest) (*management.UserEmail, error) {
|
|
email, err := s.user.ChangeEmail(ctx, updateEmailToModel(request))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return emailFromModel(email), nil
|
|
}
|
|
|
|
func (s *Server) ResendEmailVerificationMail(ctx context.Context, in *management.UserID) (*empty.Empty, error) {
|
|
err := s.user.CreateEmailVerificationCode(ctx, in.Id)
|
|
return &empty.Empty{}, err
|
|
}
|
|
|
|
func (s *Server) GetUserPhone(ctx context.Context, in *management.UserID) (*management.UserPhoneView, error) {
|
|
phone, err := s.user.PhoneByID(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return phoneViewFromModel(phone), nil
|
|
}
|
|
|
|
func (s *Server) ChangeUserPhone(ctx context.Context, request *management.UpdateUserPhoneRequest) (*management.UserPhone, error) {
|
|
phone, err := s.user.ChangePhone(ctx, updatePhoneToModel(request))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return phoneFromModel(phone), nil
|
|
}
|
|
|
|
func (s *Server) RemoveUserPhone(ctx context.Context, userID *management.UserID) (*empty.Empty, error) {
|
|
err := s.user.RemovePhone(ctx, userID.Id)
|
|
return &empty.Empty{}, err
|
|
}
|
|
|
|
func (s *Server) ResendPhoneVerificationCode(ctx context.Context, in *management.UserID) (*empty.Empty, error) {
|
|
err := s.user.CreatePhoneVerificationCode(ctx, in.Id)
|
|
return &empty.Empty{}, err
|
|
}
|
|
|
|
func (s *Server) GetUserAddress(ctx context.Context, in *management.UserID) (*management.UserAddressView, error) {
|
|
address, err := s.user.AddressByID(ctx, in.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return addressViewFromModel(address), nil
|
|
}
|
|
|
|
func (s *Server) UpdateUserAddress(ctx context.Context, request *management.UpdateUserAddressRequest) (*management.UserAddress, error) {
|
|
address, err := s.user.ChangeAddress(ctx, updateAddressToModel(request))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return addressFromModel(address), nil
|
|
}
|
|
|
|
func (s *Server) SendSetPasswordNotification(ctx context.Context, request *management.SetPasswordNotificationRequest) (*empty.Empty, error) {
|
|
err := s.user.RequestSetPassword(ctx, request.Id, notifyTypeToModel(request.Type))
|
|
return &empty.Empty{}, err
|
|
}
|
|
|
|
func (s *Server) SetInitialPassword(ctx context.Context, request *management.PasswordRequest) (*empty.Empty, error) {
|
|
_, err := s.user.SetOneTimePassword(ctx, passwordRequestToModel(request))
|
|
return &empty.Empty{}, err
|
|
}
|
|
|
|
func (s *Server) GetUserMfas(ctx context.Context, userID *management.UserID) (*management.MultiFactors, error) {
|
|
mfas, err := s.user.UserMfas(ctx, userID.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &management.MultiFactors{Mfas: mfasFromModel(mfas)}, nil
|
|
}
|