fix: usergrant pre condition check (#1947)

* fix: usergrant pre condition check

* fix: usergrant pre condition check

* fix: usergrant pre condition check
This commit is contained in:
Fabi
2021-07-01 15:53:52 +02:00
committed by GitHub
parent c6ad784a6c
commit 2037d7d41c
4 changed files with 10 additions and 5 deletions

View File

@@ -92,7 +92,7 @@ func (c *Commands) changeUserGrant(ctx context.Context, userGrant *domain.UserGr
if reflect.DeepEqual(existingUserGrant.RoleKeys, userGrant.RoleKeys) {
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "COMMAND-Rs8fy", "Errors.UserGrant.NotChanged")
}
err = c.checkUserGrantPreCondition(ctx, userGrantWriteModelToUserGrant(existingUserGrant))
err = c.checkUserGrantPreCondition(ctx, userGrant)
if err != nil {
return nil, nil, err
}

View File

@@ -117,15 +117,18 @@ func (wm *UserGrantPreConditionReadModel) Reduce() error {
case *project.GrantAddedEvent:
if wm.ProjectGrantID == e.GrantID {
wm.ProjectGrantExists = true
wm.ExistingRoleKeys = e.RoleKeys
}
wm.ExistingRoleKeys = e.RoleKeys
case *project.GrantChangedEvent:
wm.ExistingRoleKeys = e.RoleKeys
if wm.ProjectGrantID == e.GrantID {
wm.ProjectGrantExists = true
wm.ExistingRoleKeys = e.RoleKeys
}
case *project.GrantRemovedEvent:
if wm.ProjectGrantID == e.GrantID {
wm.ProjectGrantExists = false
wm.ExistingRoleKeys = []string{}
}
wm.ExistingRoleKeys = []string{}
case *project.RoleAddedEvent:
if wm.ProjectGrantID != "" {
continue