mirror of
https://github.com/zitadel/zitadel.git
synced 2025-11-14 15:13:15 +00:00
feat: translate error messages (#254)
* feat: translate error messages in error interceptor * fix: add statik import * feat: user error msgs * feat: add translations * feat: add translations * feat: add translations * feat: add translations * feat: add translations * feat: add translations * some fixes and improved error messages Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -25,16 +25,13 @@ func (es *PolicyEventstore) GetPasswordAgePolicy(ctx context.Context, id string)
|
||||
}
|
||||
|
||||
func (es *PolicyEventstore) CreatePasswordAgePolicy(ctx context.Context, policy *pol_model.PasswordAgePolicy) (*pol_model.PasswordAgePolicy, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-fbX5K", "Description is required")
|
||||
}
|
||||
ctxData := auth.GetCtxData(ctx)
|
||||
existingPolicy, err := es.GetPasswordAgePolicy(ctx, ctxData.OrgID)
|
||||
if err != nil && !caos_errs.IsNotFound(err) {
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy != nil && existingPolicy.Sequence > 0 {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-yDJ5I", "Policy allready exists")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-yDJ5I", "Errors.Policy.AlreadyExists")
|
||||
}
|
||||
|
||||
id, err := es.idGenerator.Next()
|
||||
@@ -56,9 +53,6 @@ func (es *PolicyEventstore) CreatePasswordAgePolicy(ctx context.Context, policy
|
||||
}
|
||||
|
||||
func (es *PolicyEventstore) UpdatePasswordAgePolicy(ctx context.Context, policy *pol_model.PasswordAgePolicy) (*pol_model.PasswordAgePolicy, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-44jB3", "Description is required")
|
||||
}
|
||||
ctxData := auth.GetCtxData(ctx)
|
||||
existingPolicy, err := es.GetPasswordAgePolicy(ctx, ctxData.OrgID)
|
||||
if err != nil {
|
||||
|
||||
@@ -91,18 +91,6 @@ func TestCreatePasswordAgePolicy(t *testing.T) {
|
||||
policy: &model.PasswordAgePolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID1", Sequence: 2}, Description: "Name"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "create policy no name",
|
||||
args: args{
|
||||
es: GetMockPasswordAgePolicyNoEvents(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
policy: &model.PasswordAgePolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -149,18 +137,6 @@ func TestUpdatePasswordAgePolicy(t *testing.T) {
|
||||
policy: &model.PasswordAgePolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Description: "NameNew"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update policy no name",
|
||||
args: args{
|
||||
es: GetMockPasswordAgePolicy(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
new: &model.PasswordAgePolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Description: ""},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "existing policy not found",
|
||||
args: args{
|
||||
|
||||
@@ -28,16 +28,13 @@ func (es *PolicyEventstore) GetPasswordComplexityPolicy(ctx context.Context, id
|
||||
}
|
||||
|
||||
func (es *PolicyEventstore) CreatePasswordComplexityPolicy(ctx context.Context, policy *pol_model.PasswordComplexityPolicy) (*pol_model.PasswordComplexityPolicy, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9dk45", "Description is required")
|
||||
}
|
||||
ctxData := auth.GetCtxData(ctx)
|
||||
existingPolicy, err := es.GetPasswordComplexityPolicy(ctx, ctxData.OrgID)
|
||||
if err != nil && !caos_errs.IsNotFound(err) {
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy != nil && existingPolicy.Sequence > 0 {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-yDJ5I", "Policy allready exists")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-yDJ5I", "Errors.Policy.AlreadyExists")
|
||||
}
|
||||
|
||||
id, err := es.idGenerator.Next()
|
||||
@@ -59,9 +56,6 @@ func (es *PolicyEventstore) CreatePasswordComplexityPolicy(ctx context.Context,
|
||||
}
|
||||
|
||||
func (es *PolicyEventstore) UpdatePasswordComplexityPolicy(ctx context.Context, policy *pol_model.PasswordComplexityPolicy) (*pol_model.PasswordComplexityPolicy, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9dk45", "Description is required")
|
||||
}
|
||||
ctxData := auth.GetCtxData(ctx)
|
||||
existingPolicy, err := es.GetPasswordComplexityPolicy(ctx, ctxData.OrgID)
|
||||
if err != nil {
|
||||
|
||||
@@ -91,18 +91,6 @@ func TestCreatePasswordComplexityPolicy(t *testing.T) {
|
||||
policy: &model.PasswordComplexityPolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID1", Sequence: 2}, Description: "Name"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "create policy no name",
|
||||
args: args{
|
||||
es: GetMockPasswordComplexityPolicyNoEvents(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
policy: &model.PasswordComplexityPolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -149,18 +137,6 @@ func TestUpdatePasswordComplexityPolicy(t *testing.T) {
|
||||
policy: &model.PasswordComplexityPolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Description: "NameNew"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update policy no name",
|
||||
args: args{
|
||||
es: GetMockPasswordComplexityPolicy(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
new: &model.PasswordComplexityPolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Description: ""},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "existing policy not found",
|
||||
args: args{
|
||||
|
||||
@@ -25,16 +25,13 @@ func (es *PolicyEventstore) GetPasswordLockoutPolicy(ctx context.Context, id str
|
||||
}
|
||||
|
||||
func (es *PolicyEventstore) CreatePasswordLockoutPolicy(ctx context.Context, policy *pol_model.PasswordLockoutPolicy) (*pol_model.PasswordLockoutPolicy, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9dk45", "Description is required")
|
||||
}
|
||||
ctxData := auth.GetCtxData(ctx)
|
||||
existingPolicy, err := es.GetPasswordLockoutPolicy(ctx, ctxData.OrgID)
|
||||
if err != nil && !caos_errs.IsNotFound(err) {
|
||||
return nil, err
|
||||
}
|
||||
if existingPolicy != nil && existingPolicy.Sequence > 0 {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-yDJ5I", "Policy allready exists")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-yDJ5I", "Errors.Policy.AlreadyExists")
|
||||
}
|
||||
|
||||
id, err := es.idGenerator.Next()
|
||||
@@ -56,9 +53,6 @@ func (es *PolicyEventstore) CreatePasswordLockoutPolicy(ctx context.Context, pol
|
||||
}
|
||||
|
||||
func (es *PolicyEventstore) UpdatePasswordLockoutPolicy(ctx context.Context, policy *pol_model.PasswordLockoutPolicy) (*pol_model.PasswordLockoutPolicy, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9dk45", "Description is required")
|
||||
}
|
||||
ctxData := auth.GetCtxData(ctx)
|
||||
existingPolicy, err := es.GetPasswordLockoutPolicy(ctx, ctxData.OrgID)
|
||||
if err != nil {
|
||||
|
||||
@@ -91,18 +91,6 @@ func TestCreatePasswordLockoutPolicy(t *testing.T) {
|
||||
policy: &model.PasswordLockoutPolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID1", Sequence: 2}, Description: "Name"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "create policy no name",
|
||||
args: args{
|
||||
es: GetMockPasswordLockoutPolicyNoEvents(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
policy: &model.PasswordLockoutPolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -149,18 +137,6 @@ func TestUpdatePasswordLockoutPolicy(t *testing.T) {
|
||||
policy: &model.PasswordLockoutPolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Description: "NameNew"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update policy no name",
|
||||
args: args{
|
||||
es: GetMockPasswordLockoutPolicy(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
new: &model.PasswordLockoutPolicy{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Description: ""},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "existing policy not found",
|
||||
args: args{
|
||||
|
||||
@@ -17,7 +17,7 @@ func PasswordAgePolicyQuery(recourceOwner string, latestSequence uint64) *es_mod
|
||||
|
||||
func PasswordAgePolicyAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, policy *PasswordAgePolicy) (*es_models.Aggregate, error) {
|
||||
if policy == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-1T05i", "existing policy should not be nil")
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-1T05i", "Errors.Internal")
|
||||
}
|
||||
return aggCreator.NewAggregate(ctx, policy.AggregateID, model.PasswordAgePolicyAggregate, policyAgeVersion, policy.Sequence)
|
||||
}
|
||||
@@ -25,7 +25,7 @@ func PasswordAgePolicyAggregate(ctx context.Context, aggCreator *es_models.Aggre
|
||||
func PasswordAgePolicyCreateAggregate(aggCreator *es_models.AggregateCreator, policy *PasswordAgePolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if policy == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-kdie6", "policy should not be nil")
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-kdie6", "Errors.Internal")
|
||||
}
|
||||
agg, err := PasswordAgePolicyAggregate(ctx, aggCreator, policy)
|
||||
if err != nil {
|
||||
@@ -39,7 +39,7 @@ func PasswordAgePolicyCreateAggregate(aggCreator *es_models.AggregateCreator, po
|
||||
func PasswordAgePolicyUpdateAggregate(aggCreator *es_models.AggregateCreator, existing *PasswordAgePolicy, new *PasswordAgePolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if new == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dhr74", "new policy should not be nil")
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dhr74", "Errors.Internal")
|
||||
}
|
||||
agg, err := PasswordAgePolicyAggregate(ctx, aggCreator, existing)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,7 +18,7 @@ func PasswordComplexityPolicyQuery(recourceOwner string, latestSequence uint64)
|
||||
|
||||
func PasswordComplexityPolicyAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, policy *PasswordComplexityPolicy) (*es_models.Aggregate, error) {
|
||||
if policy == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-fRVr9", "existing policy should not be nil")
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-fRVr9", "Errors.Internal")
|
||||
}
|
||||
return aggCreator.NewAggregate(ctx, policy.AggregateID, model.PasswordComplexityPolicyAggregate, policyComplexityVersion, policy.Sequence)
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func PasswordComplexityPolicyAggregate(ctx context.Context, aggCreator *es_model
|
||||
func PasswordComplexityPolicyCreateAggregate(aggCreator *es_models.AggregateCreator, policy *PasswordComplexityPolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if policy == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-kdie6", "policy should not be nil")
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-kdie6", "Errors.Internal")
|
||||
}
|
||||
agg, err := PasswordComplexityPolicyAggregate(ctx, aggCreator, policy)
|
||||
if err != nil {
|
||||
@@ -40,7 +40,7 @@ func PasswordComplexityPolicyCreateAggregate(aggCreator *es_models.AggregateCrea
|
||||
func PasswordComplexityPolicyUpdateAggregate(aggCreator *es_models.AggregateCreator, existing *PasswordComplexityPolicy, new *PasswordComplexityPolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if new == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dhr74", "new policy should not be nil")
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dhr74", "Errors.Internal")
|
||||
}
|
||||
agg, err := PasswordComplexityPolicyAggregate(ctx, aggCreator, existing)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,7 +18,7 @@ func PasswordLockoutPolicyQuery(recourceOwner string, latestSequence uint64) *es
|
||||
|
||||
func PasswordLockoutPolicyAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, policy *PasswordLockoutPolicy) (*es_models.Aggregate, error) {
|
||||
if policy == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-aTRlj", "existing policy should not be nil")
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-aTRlj", "Errors.Internal")
|
||||
}
|
||||
return aggCreator.NewAggregate(ctx, policy.AggregateID, model.PasswordLockoutPolicyAggregate, policyLockoutVersion, policy.Sequence)
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func PasswordLockoutPolicyAggregate(ctx context.Context, aggCreator *es_models.A
|
||||
func PasswordLockoutPolicyCreateAggregate(aggCreator *es_models.AggregateCreator, policy *PasswordLockoutPolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if policy == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-kdie6", "policy should not be nil")
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-kdie6", "Errors.Internal")
|
||||
}
|
||||
|
||||
agg, err := PasswordLockoutPolicyAggregate(ctx, aggCreator, policy)
|
||||
@@ -41,7 +41,7 @@ func PasswordLockoutPolicyCreateAggregate(aggCreator *es_models.AggregateCreator
|
||||
func PasswordLockoutPolicyUpdateAggregate(aggCreator *es_models.AggregateCreator, existing *PasswordLockoutPolicy, new *PasswordLockoutPolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if new == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dhr74", "new policy should not be nil")
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dhr74", "Errors.Internal")
|
||||
}
|
||||
agg, err := PasswordLockoutPolicyAggregate(ctx, aggCreator, existing)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user