mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
f3e6f3b23b
* feat(command): remove org * refactor: imports, unused code, error handling * reduce org removed in action * add org deletion to projections * add org removal to projections * add org removal to projections * org removed projection * lint import * projections * fix: table names in tests * fix: table names in tests * logging * add org state * fix(domain): add Owner removed to object details * feat(ListQuery): add with owner removed * fix(org-delete): add bool to functions to select with owner removed * fix(org-delete): add bools to user grants with events to determine if dependencies lost owner * fix(org-delete): add unit tests for owner removed and org removed events * fix(org-delete): add handling of org remove for grants and members * fix(org-delete): correction of unit tests for owner removed * fix(org-delete): update projections, unit tests and get functions * fix(org-delete): add change date to authnkeys and owner removed to org metadata * fix(org-delete): include owner removed for login names * fix(org-delete): some column fixes in projections and build for queries with owner removed * indexes * fix(org-delete): include review changes * fix(org-delete): change user projection name after merge * fix(org-delete): include review changes for project grant where no project owner is necessary * fix(org-delete): include auth and adminapi tables with owner removed information * fix(org-delete): cleanup username and orgdomain uniqueconstraints when org is removed * fix(org-delete): add permissions for org.remove * remove unnecessary unique constraints * fix column order in primary keys * fix(org-delete): include review changes * fix(org-delete): add owner removed indexes and chang setup step to create tables * fix(org-delete): move PK order of instance_id and change added user_grant from review * fix(org-delete): no params for prepareUserQuery * change to step 6 * merge main * fix(org-delete): OldUserName rename to private * fix linting * cleanup * fix: remove org test * create prerelease * chore: delete org-delete as prerelease Co-authored-by: Stefan Benz <stefan@caos.ch> Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Fabi <38692350+hifabienne@users.noreply.github.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
350 lines
14 KiB
Go
350 lines
14 KiB
Go
package management
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.org/x/text/language"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
|
text_grpc "github.com/zitadel/zitadel/internal/api/grpc/text"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
mgmt_pb "github.com/zitadel/zitadel/pkg/grpc/management"
|
|
)
|
|
|
|
func (s *Server) GetCustomInitMessageText(ctx context.Context, req *mgmt_pb.GetCustomInitMessageTextRequest) (*mgmt_pb.GetCustomInitMessageTextResponse, error) {
|
|
msg, err := s.query.CustomMessageTextByTypeAndLanguage(ctx, authz.GetCtxData(ctx).OrgID, domain.InitCodeMessageType, req.Language, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetCustomInitMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetDefaultInitMessageText(ctx context.Context, req *mgmt_pb.GetDefaultInitMessageTextRequest) (*mgmt_pb.GetDefaultInitMessageTextResponse, error) {
|
|
msg, err := s.query.IAMMessageTextByTypeAndLanguage(ctx, domain.InitCodeMessageType, req.Language)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetDefaultInitMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) SetCustomInitMessageText(ctx context.Context, req *mgmt_pb.SetCustomInitMessageTextRequest) (*mgmt_pb.SetCustomInitMessageTextResponse, error) {
|
|
result, err := s.command.SetOrgMessageText(ctx, authz.GetCtxData(ctx).OrgID, SetInitCustomTextToDomain(req))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.SetCustomInitMessageTextResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ResetCustomInitMessageTextToDefault(ctx context.Context, req *mgmt_pb.ResetCustomInitMessageTextToDefaultRequest) (*mgmt_pb.ResetCustomInitMessageTextToDefaultResponse, error) {
|
|
result, err := s.command.RemoveOrgMessageTexts(ctx, authz.GetCtxData(ctx).OrgID, domain.InitCodeMessageType, language.Make(req.Language))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.ResetCustomInitMessageTextToDefaultResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetCustomPasswordResetMessageText(ctx context.Context, req *mgmt_pb.GetCustomPasswordResetMessageTextRequest) (*mgmt_pb.GetCustomPasswordResetMessageTextResponse, error) {
|
|
msg, err := s.query.CustomMessageTextByTypeAndLanguage(ctx, authz.GetCtxData(ctx).OrgID, domain.PasswordResetMessageType, req.Language, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetCustomPasswordResetMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetDefaultPasswordResetMessageText(ctx context.Context, req *mgmt_pb.GetDefaultPasswordResetMessageTextRequest) (*mgmt_pb.GetDefaultPasswordResetMessageTextResponse, error) {
|
|
msg, err := s.query.IAMMessageTextByTypeAndLanguage(ctx, domain.PasswordResetMessageType, req.Language)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetDefaultPasswordResetMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) SetCustomPasswordResetMessageText(ctx context.Context, req *mgmt_pb.SetCustomPasswordResetMessageTextRequest) (*mgmt_pb.SetCustomPasswordResetMessageTextResponse, error) {
|
|
result, err := s.command.SetOrgMessageText(ctx, authz.GetCtxData(ctx).OrgID, SetPasswordResetCustomTextToDomain(req))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.SetCustomPasswordResetMessageTextResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ResetCustomPasswordResetMessageTextToDefault(ctx context.Context, req *mgmt_pb.ResetCustomPasswordResetMessageTextToDefaultRequest) (*mgmt_pb.ResetCustomPasswordResetMessageTextToDefaultResponse, error) {
|
|
result, err := s.command.RemoveOrgMessageTexts(ctx, authz.GetCtxData(ctx).OrgID, domain.PasswordResetMessageType, language.Make(req.Language))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.ResetCustomPasswordResetMessageTextToDefaultResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetCustomVerifyEmailMessageText(ctx context.Context, req *mgmt_pb.GetCustomVerifyEmailMessageTextRequest) (*mgmt_pb.GetCustomVerifyEmailMessageTextResponse, error) {
|
|
msg, err := s.query.CustomMessageTextByTypeAndLanguage(ctx, authz.GetCtxData(ctx).OrgID, domain.VerifyEmailMessageType, req.Language, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetCustomVerifyEmailMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetDefaultVerifyEmailMessageText(ctx context.Context, req *mgmt_pb.GetDefaultVerifyEmailMessageTextRequest) (*mgmt_pb.GetDefaultVerifyEmailMessageTextResponse, error) {
|
|
msg, err := s.query.IAMMessageTextByTypeAndLanguage(ctx, domain.VerifyEmailMessageType, req.Language)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetDefaultVerifyEmailMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) SetCustomVerifyEmailMessageText(ctx context.Context, req *mgmt_pb.SetCustomVerifyEmailMessageTextRequest) (*mgmt_pb.SetCustomVerifyEmailMessageTextResponse, error) {
|
|
result, err := s.command.SetOrgMessageText(ctx, authz.GetCtxData(ctx).OrgID, SetVerifyEmailCustomTextToDomain(req))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.SetCustomVerifyEmailMessageTextResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ResetCustomVerifyEmailMessageTextToDefault(ctx context.Context, req *mgmt_pb.ResetCustomVerifyEmailMessageTextToDefaultRequest) (*mgmt_pb.ResetCustomVerifyEmailMessageTextToDefaultResponse, error) {
|
|
result, err := s.command.RemoveOrgMessageTexts(ctx, authz.GetCtxData(ctx).OrgID, domain.VerifyEmailMessageType, language.Make(req.Language))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.ResetCustomVerifyEmailMessageTextToDefaultResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetCustomVerifyPhoneMessageText(ctx context.Context, req *mgmt_pb.GetCustomVerifyPhoneMessageTextRequest) (*mgmt_pb.GetCustomVerifyPhoneMessageTextResponse, error) {
|
|
msg, err := s.query.CustomMessageTextByTypeAndLanguage(ctx, authz.GetCtxData(ctx).OrgID, domain.VerifyPhoneMessageType, req.Language, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetCustomVerifyPhoneMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetDefaultVerifyPhoneMessageText(ctx context.Context, req *mgmt_pb.GetDefaultVerifyPhoneMessageTextRequest) (*mgmt_pb.GetDefaultVerifyPhoneMessageTextResponse, error) {
|
|
msg, err := s.query.IAMMessageTextByTypeAndLanguage(ctx, domain.VerifyPhoneMessageType, req.Language)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetDefaultVerifyPhoneMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) SetCustomVerifyPhoneMessageText(ctx context.Context, req *mgmt_pb.SetCustomVerifyPhoneMessageTextRequest) (*mgmt_pb.SetCustomVerifyPhoneMessageTextResponse, error) {
|
|
result, err := s.command.SetOrgMessageText(ctx, authz.GetCtxData(ctx).OrgID, SetVerifyPhoneCustomTextToDomain(req))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.SetCustomVerifyPhoneMessageTextResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ResetCustomVerifyPhoneMessageTextToDefault(ctx context.Context, req *mgmt_pb.ResetCustomVerifyPhoneMessageTextToDefaultRequest) (*mgmt_pb.ResetCustomVerifyPhoneMessageTextToDefaultResponse, error) {
|
|
result, err := s.command.RemoveOrgMessageTexts(ctx, authz.GetCtxData(ctx).OrgID, domain.VerifyPhoneMessageType, language.Make(req.Language))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.ResetCustomVerifyPhoneMessageTextToDefaultResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetCustomDomainClaimedMessageText(ctx context.Context, req *mgmt_pb.GetCustomDomainClaimedMessageTextRequest) (*mgmt_pb.GetCustomDomainClaimedMessageTextResponse, error) {
|
|
msg, err := s.query.CustomMessageTextByTypeAndLanguage(ctx, authz.GetCtxData(ctx).OrgID, domain.DomainClaimedMessageType, req.Language, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetCustomDomainClaimedMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetDefaultDomainClaimedMessageText(ctx context.Context, req *mgmt_pb.GetDefaultDomainClaimedMessageTextRequest) (*mgmt_pb.GetDefaultDomainClaimedMessageTextResponse, error) {
|
|
msg, err := s.query.IAMMessageTextByTypeAndLanguage(ctx, domain.DomainClaimedMessageType, req.Language)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetDefaultDomainClaimedMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) SetCustomDomainClaimedMessageCustomText(ctx context.Context, req *mgmt_pb.SetCustomDomainClaimedMessageTextRequest) (*mgmt_pb.SetCustomDomainClaimedMessageTextResponse, error) {
|
|
result, err := s.command.SetOrgMessageText(ctx, authz.GetCtxData(ctx).OrgID, SetDomainClaimedCustomTextToDomain(req))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.SetCustomDomainClaimedMessageTextResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ResetCustomDomainClaimedMessageTextToDefault(ctx context.Context, req *mgmt_pb.ResetCustomDomainClaimedMessageTextToDefaultRequest) (*mgmt_pb.ResetCustomDomainClaimedMessageTextToDefaultResponse, error) {
|
|
result, err := s.command.RemoveOrgMessageTexts(ctx, authz.GetCtxData(ctx).OrgID, domain.DomainClaimedMessageType, language.Make(req.Language))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.ResetCustomDomainClaimedMessageTextToDefaultResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetCustomPasswordlessRegistrationMessageText(ctx context.Context, req *mgmt_pb.GetCustomPasswordlessRegistrationMessageTextRequest) (*mgmt_pb.GetCustomPasswordlessRegistrationMessageTextResponse, error) {
|
|
msg, err := s.query.CustomMessageTextByTypeAndLanguage(ctx, authz.GetCtxData(ctx).OrgID, domain.PasswordlessRegistrationMessageType, req.Language, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetCustomPasswordlessRegistrationMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetDefaultPasswordlessRegistrationMessageText(ctx context.Context, req *mgmt_pb.GetDefaultPasswordlessRegistrationMessageTextRequest) (*mgmt_pb.GetDefaultPasswordlessRegistrationMessageTextResponse, error) {
|
|
msg, err := s.query.IAMMessageTextByTypeAndLanguage(ctx, domain.PasswordlessRegistrationMessageType, req.Language)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetDefaultPasswordlessRegistrationMessageTextResponse{
|
|
CustomText: text_grpc.ModelCustomMessageTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) SetCustomPasswordlessRegistrationMessageCustomText(ctx context.Context, req *mgmt_pb.SetCustomPasswordlessRegistrationMessageTextRequest) (*mgmt_pb.SetCustomPasswordlessRegistrationMessageTextResponse, error) {
|
|
result, err := s.command.SetOrgMessageText(ctx, authz.GetCtxData(ctx).OrgID, SetPasswordlessRegistrationCustomTextToDomain(req))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.SetCustomPasswordlessRegistrationMessageTextResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ResetCustomPasswordlessRegistrationMessageTextToDefault(ctx context.Context, req *mgmt_pb.ResetCustomPasswordlessRegistrationMessageTextToDefaultRequest) (*mgmt_pb.ResetCustomPasswordlessRegistrationMessageTextToDefaultResponse, error) {
|
|
result, err := s.command.RemoveOrgMessageTexts(ctx, authz.GetCtxData(ctx).OrgID, domain.PasswordlessRegistrationMessageType, language.Make(req.Language))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.ResetCustomPasswordlessRegistrationMessageTextToDefaultResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetCustomLoginTexts(ctx context.Context, req *mgmt_pb.GetCustomLoginTextsRequest) (*mgmt_pb.GetCustomLoginTextsResponse, error) {
|
|
msg, err := s.query.GetCustomLoginTexts(ctx, authz.GetCtxData(ctx).OrgID, req.Language)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetCustomLoginTextsResponse{
|
|
CustomText: text_grpc.CustomLoginTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) GetDefaultLoginTexts(ctx context.Context, req *mgmt_pb.GetDefaultLoginTextsRequest) (*mgmt_pb.GetDefaultLoginTextsResponse, error) {
|
|
msg, err := s.query.IAMLoginTexts(ctx, req.Language)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.GetDefaultLoginTextsResponse{
|
|
CustomText: text_grpc.CustomLoginTextToPb(msg),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) SetCustomLoginText(ctx context.Context, req *mgmt_pb.SetCustomLoginTextsRequest) (*mgmt_pb.SetCustomLoginTextsResponse, error) {
|
|
result, err := s.command.SetOrgLoginText(ctx, authz.GetCtxData(ctx).OrgID, SetLoginCustomTextToDomain(req))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.SetCustomLoginTextsResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ResetCustomLoginTextToDefault(ctx context.Context, req *mgmt_pb.ResetCustomLoginTextsToDefaultRequest) (*mgmt_pb.ResetCustomLoginTextsToDefaultResponse, error) {
|
|
result, err := s.command.RemoveOrgLoginTexts(ctx, authz.GetCtxData(ctx).OrgID, language.Make(req.Language))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &mgmt_pb.ResetCustomLoginTextsToDefaultResponse{
|
|
Details: object.ChangeToDetailsPb(
|
|
result.Sequence,
|
|
result.EventDate,
|
|
result.ResourceOwner,
|
|
),
|
|
}, nil
|
|
}
|