mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
feat: split users into human and machine (#470)
* feat(management): service accounts * chore: current go version * init * refactor: apis * feat(internal): start impl of service account * chore: start impl of machine/human users * code compiles * fix: tests * fix: tests * fix: add new event types to switches * chore: add cases to event types * fix(management): definitive proto messages * fix: machine/human * fix: add missing tables as todos * fix: remove unused permissions * fix: refactoring * fix: refactor * fix: human registered * fix: user id * fix: logid * fix: proto remove //equal * chore(management): remove no comment * fix: human mfas * fix: user subobjects * chore: rename existing to better name * fix: username in user (#634) * fix: username in user * fix: username * fix remove unused code * fix add validations * fix: use new user in all apis * fix: regexp for username in api * fix: fill user data for human and machine (#638) * fix: fill Display name grant/member handlers fix: add description to grant/member objects in api fix: check if user is human in login * fix: remove description from member and grant * chore: remove todos * feat: machine keys * fix: implement missing parts * feat: machine key management view * fix: remove keys from machine view * fix: set default expiration date * fix: get key by ids * feat: add machine keys in proto * feat: machine keys * fix: add migration * fix: mig * fix: correct method name * feat: user search * feat: user search * fix: log ids * fix partial authconfig prompt, domain c perm * membership read check * contributor refresh trigger, observe org write * fix: migrations * fix(console): machine build (#660) * frontend 1 * fix html bindings * trailing comma * user permissions, project deactivate * fix(console): human view (#661) * fix search user view, user detail form * rm log * feat(console): user services list and create (#663) * fix search user view, user detail form * rm log * machine list * generic table component * create user service * proove table for undefined values * tmp disable user link if machine * lint * lint styles * user table lint * Update console/src/assets/i18n/de.json Co-authored-by: Florian Forster <florian@caos.ch> * feat(console): service user detail view, keys cr_d, fix search user autocomplete (#664) * service users for sidenav, routing * i18n * back routes * machine detail form * update machine detail, fix svc user grants * keys table * add key dialog, timestamp creation * check permission on create, delete, fix selection * lint ts, scss * Update console/src/assets/i18n/de.json * Apply suggestions from code review Co-authored-by: Florian Forster <florian@caos.ch> * allow user grants for project.write * management service * fix mgmt service * feat: Machine keys (#655) * fix: memberships (#633) * feat: add iam members to memberships * fix: search project grants * fix: rename * feat: idp and login policy configurations (#619) * feat: oidc config * fix: oidc configurations * feat: oidc idp config * feat: add oidc config test * fix: tests * fix: tests * feat: translate new events * feat: idp eventstore * feat: idp eventstore * fix: tests * feat: command side idp * feat: query side idp * feat: idp config on org * fix: tests * feat: authz idp on org * feat: org idps * feat: login policy * feat: login policy * feat: login policy * feat: add idp func on login policy * feat: add validation to loginpolicy and idp provider * feat: add default login policy * feat: login policy on org * feat: login policy on org * fix: id config handlers * fix: id config handlers * fix: create idp on org * fix: create idp on org * fix: not existing idp config * fix: default login policy * fix: add login policy on org * fix: idp provider search on org * fix: test * fix: remove idp on org * fix: test * fix: test * fix: remove admin idp * fix: logo src as byte * fix: migration * fix: tests * Update internal/iam/repository/eventsourcing/iam.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/iam_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/iam_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/org/repository/eventsourcing/org_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/iam/repository/eventsourcing/model/login_policy_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: pr comments * fix: tests * Update types.go * fix: merge request changes * fix: reduce optimization Co-authored-by: Silvan <silvan.reusser@gmail.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: reread user mfas, preferred loginname as otp account name (#636) * fix: reread user mfas * fix: use preferred login name as otp account name * fix: tests * fix: reduce (#635) * fix: management reduce optimization * fix: reduce optimization * fix: reduce optimization * fix: merge master * chore(deps): bump github.com/gorilla/schema from 1.1.0 to 1.2.0 (#627) Bumps [github.com/gorilla/schema](https://github.com/gorilla/schema) from 1.1.0 to 1.2.0. - [Release notes](https://github.com/gorilla/schema/releases) - [Commits](https://github.com/gorilla/schema/compare/v1.1.0...v1.2.0) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump github.com/gorilla/mux from 1.7.4 to 1.8.0 (#624) Bumps [github.com/gorilla/mux](https://github.com/gorilla/mux) from 1.7.4 to 1.8.0. - [Release notes](https://github.com/gorilla/mux/releases) - [Commits](https://github.com/gorilla/mux/compare/v1.7.4...v1.8.0) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump github.com/DATA-DOG/go-sqlmock from 1.4.1 to 1.5.0 (#591) Bumps [github.com/DATA-DOG/go-sqlmock](https://github.com/DATA-DOG/go-sqlmock) from 1.4.1 to 1.5.0. - [Release notes](https://github.com/DATA-DOG/go-sqlmock/releases) - [Commits](https://github.com/DATA-DOG/go-sqlmock/compare/v1.4.1...v1.5.0) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: auto assign issues and PR to ZTIADEL project board (#643) * Create main.yml * Update main.yml Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix(console): project grant members, update deps (#645) * fix: searchprojectgrantmembers * chore(deps-dev): bump @angular/cli from 10.0.6 to 10.0.7 in /console (#622) Bumps [@angular/cli](https://github.com/angular/angular-cli) from 10.0.6 to 10.0.7. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/compare/v10.0.6...v10.0.7) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular-devkit/build-angular in /console (#626) Bumps [@angular-devkit/build-angular](https://github.com/angular/angular-cli) from 0.1000.6 to 0.1000.7. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Peintner <max@caos.ch> * chore(deps-dev): bump @types/jasmine from 3.5.12 to 3.5.13 in /console (#623) Bumps [@types/jasmine](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jasmine) from 3.5.12 to 3.5.13. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jasmine) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump ts-node from 8.10.2 to 9.0.0 in /console (#629) Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 8.10.2 to 9.0.0. - [Release notes](https://github.com/TypeStrong/ts-node/releases) - [Commits](https://github.com/TypeStrong/ts-node/compare/v8.10.2...v9.0.0) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * update packlock Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: delete main.yml (#648) * fix: usergrant (#650) * fix(console): mfa refresh after verification, member eventemitter (#651) * refresh mfa * fix: detail link from contributors * lint * feat: add domain verification notification (#649) * fix: dont (re)generate client secret with auth type none * fix(cors): allow Origin from request * feat: add origin allow list and fix some core issues * rename migration * fix UserIDsByDomain * feat: send email to users after domain claim * username * check origin on userinfo * update oidc pkg * fix: add migration 1.6 * change username * change username * remove unique email aggregate * change username in mgmt * search global user by login name * fix test * change user search in angular * fix tests * merge * userview in angular * fix merge * Update pkg/grpc/management/proto/management.proto Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * Update internal/notification/static/i18n/de.yaml Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * fix Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * fix: translation (#647) * fix: translation * fix: translation * fix: translation * fix: remove unused code * fix: log err * fix: migration numbers (#652) * chore: issue / feature templates (#642) * feat: machine keys * fix: implement missing parts * feat: machine key management view * fix: remove keys from machine view * feat: global org read (#657) * fix: set default expiration date * fix: get key by ids * feat: add machine keys in proto * feat: machine keys * fix: add migration * fix: mig * fix: correct method name * feat: user search * feat: user search * fix: log ids * fix: migrations * fix(console): machine build (#660) * frontend 1 * fix html bindings * trailing comma * fix(console): human view (#661) * fix search user view, user detail form * rm log * feat(console): user services list and create (#663) * fix search user view, user detail form * rm log * machine list * generic table component * create user service * proove table for undefined values * tmp disable user link if machine * lint * lint styles * user table lint * Update console/src/assets/i18n/de.json Co-authored-by: Florian Forster <florian@caos.ch> * feat(console): service user detail view, keys cr_d, fix search user autocomplete (#664) * service users for sidenav, routing * i18n * back routes * machine detail form * update machine detail, fix svc user grants * keys table * add key dialog, timestamp creation * check permission on create, delete, fix selection * lint ts, scss * Update console/src/assets/i18n/de.json * Apply suggestions from code review Co-authored-by: Florian Forster <florian@caos.ch> * refactor: protos * fix(management): key expiration date * fix: check if user is human * fix: marshal key details * fix: correct generate login names * fix: logid Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com> Co-authored-by: Florian Forster <florian@caos.ch> * fix: naming * refactor: findings * fix: username * fix: mfa upper case * fix: tests * fix: add translations * reactivatemyorg req typeö * fix: projectType for console * fix: user changes * fix: translate events * fix: event type translation * fix: remove unused types Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com> Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -80,7 +80,7 @@ func (es *ProjectEventstore) ProjectEventsByID(ctx context.Context, id string, s
|
||||
|
||||
func (es *ProjectEventstore) CreateProject(ctx context.Context, project *proj_model.Project) (*proj_model.Project, error) {
|
||||
if !project.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9dk45", "Errors.Project.Invalid")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-IOVCC", "Errors.Project.Invalid")
|
||||
}
|
||||
id, err := es.idGenerator.Next()
|
||||
if err != nil {
|
||||
@@ -106,7 +106,7 @@ func (es *ProjectEventstore) CreateProject(ctx context.Context, project *proj_mo
|
||||
|
||||
func (es *ProjectEventstore) UpdateProject(ctx context.Context, project *proj_model.Project) (*proj_model.Project, error) {
|
||||
if !project.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9dk45", "Errors.Project.Invalid")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-7eBD6", "Errors.Project.Invalid")
|
||||
}
|
||||
existingProject, err := es.ProjectByID(ctx, project.AggregateID)
|
||||
if err != nil {
|
||||
@@ -126,15 +126,15 @@ func (es *ProjectEventstore) UpdateProject(ctx context.Context, project *proj_mo
|
||||
}
|
||||
|
||||
func (es *ProjectEventstore) DeactivateProject(ctx context.Context, id string) (*proj_model.Project, error) {
|
||||
existing, err := es.ProjectByID(ctx, id)
|
||||
existingProject, err := es.ProjectByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !existing.IsActive() {
|
||||
if !existingProject.IsActive() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-die45", "Errors.Project.NotActive")
|
||||
}
|
||||
|
||||
repoExisting := model.ProjectFromModel(existing)
|
||||
repoExisting := model.ProjectFromModel(existingProject)
|
||||
aggregate := ProjectDeactivateAggregate(es.AggregateCreator(), repoExisting)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoExisting.AppendEvents, aggregate)
|
||||
if err != nil {
|
||||
@@ -145,15 +145,15 @@ func (es *ProjectEventstore) DeactivateProject(ctx context.Context, id string) (
|
||||
}
|
||||
|
||||
func (es *ProjectEventstore) ReactivateProject(ctx context.Context, id string) (*proj_model.Project, error) {
|
||||
existing, err := es.ProjectByID(ctx, id)
|
||||
existingProject, err := es.ProjectByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existing.IsActive() {
|
||||
if existingProject.IsActive() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-die45", "Errors.Project.NotInactive")
|
||||
}
|
||||
|
||||
repoExisting := model.ProjectFromModel(existing)
|
||||
repoExisting := model.ProjectFromModel(existingProject)
|
||||
aggregate := ProjectReactivateAggregate(es.AggregateCreator(), repoExisting)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoExisting.AppendEvents, aggregate)
|
||||
if err != nil {
|
||||
@@ -180,11 +180,11 @@ func (es *ProjectEventstore) PrepareRemoveProject(ctx context.Context, proj *pro
|
||||
if proj.AggregateID == "" {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-Akbov", "Errors.ProjectInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, proj.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, proj.AggregateID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
projectAggregate, err := ProjectRemovedAggregate(ctx, es.Eventstore.AggregateCreator(), repoProject)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -209,16 +209,16 @@ func (es *ProjectEventstore) ProjectMemberByIDs(ctx context.Context, member *pro
|
||||
|
||||
func (es *ProjectEventstore) AddProjectMember(ctx context.Context, member *proj_model.ProjectMember) (*proj_model.ProjectMember, error) {
|
||||
if !member.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9dk45", "Errors.Project.MemberInvalid")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-2OWkC", "Errors.Project.MemberInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, m := existing.GetMember(member.UserID); m != nil {
|
||||
if _, m := existingProject.GetMember(member.UserID); m != nil {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "EVENT-idke6", "Errors.Project.MemberAlreadyExists")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoMember := model.ProjectMemberFromModel(member)
|
||||
|
||||
addAggregate := ProjectMemberAddedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoMember)
|
||||
@@ -236,16 +236,16 @@ func (es *ProjectEventstore) AddProjectMember(ctx context.Context, member *proj_
|
||||
|
||||
func (es *ProjectEventstore) ChangeProjectMember(ctx context.Context, member *proj_model.ProjectMember) (*proj_model.ProjectMember, error) {
|
||||
if !member.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9dk45", "Errors.Project.MemberInvalid")
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-Buh04", "Errors.Project.MemberInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, m := existing.GetMember(member.UserID); m == nil {
|
||||
if _, m := existingProject.GetMember(member.UserID); m == nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-oe39f", "Errors.Project.MemberNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoMember := model.ProjectMemberFromModel(member)
|
||||
|
||||
projectAggregate := ProjectMemberChangedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoMember)
|
||||
@@ -265,14 +265,14 @@ func (es *ProjectEventstore) RemoveProjectMember(ctx context.Context, member *pr
|
||||
if member.UserID == "" {
|
||||
return caos_errs.ThrowPreconditionFailed(nil, "EVENT-d43fs", "Errors.Project.MemberInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, m := existing.GetMember(member.UserID); m == nil {
|
||||
if _, m := existingProject.GetMember(member.UserID); m == nil {
|
||||
return caos_errs.ThrowPreconditionFailed(nil, "EVENT-swf34", "Errors.Project.MemberNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoMember := model.ProjectMemberFromModel(member)
|
||||
|
||||
projectAggregate := ProjectMemberRemovedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoMember)
|
||||
@@ -288,14 +288,14 @@ func (es *ProjectEventstore) PrepareRemoveProjectMember(ctx context.Context, mem
|
||||
if member.UserID == "" {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-tCXHE", "Errors.Project.MemberInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if _, m := existing.GetMember(member.UserID); m == nil {
|
||||
if _, m := existingProject.GetMember(member.UserID); m == nil {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-wPcg5", "Errors.Project.MemberNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoMember := model.ProjectMemberFromModel(member)
|
||||
|
||||
projectAggregate := ProjectMemberRemovedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoMember)
|
||||
@@ -316,17 +316,17 @@ func (es *ProjectEventstore) AddProjectRoles(ctx context.Context, roles ...*proj
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-idue3", "Errors.Project.MemberInvalid")
|
||||
}
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, roles[0].AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, roles[0].AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, role := range roles {
|
||||
if existing.ContainsRole(role) {
|
||||
if existingProject.ContainsRole(role) {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "EVENT-sk35t", "Errors.Project.RoleAlreadyExists")
|
||||
}
|
||||
}
|
||||
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoRoles := model.ProjectRolesFromModel(roles)
|
||||
projectAggregate := ProjectRoleAddedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoRoles...)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoProject.AppendEvents, projectAggregate)
|
||||
@@ -347,14 +347,14 @@ func (es *ProjectEventstore) ChangeProjectRole(ctx context.Context, role *proj_m
|
||||
if !role.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9die3", "Errors.Project.RoleInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, role.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, role.AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !existing.ContainsRole(role) {
|
||||
if !existingProject.ContainsRole(role) {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-die34", "Errors.Project.RoleNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoRole := model.ProjectRoleFromModel(role)
|
||||
projectAggregate := ProjectRoleChangedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoRole)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoProject.AppendEvents, projectAggregate)
|
||||
@@ -374,14 +374,14 @@ func (es *ProjectEventstore) PrepareRemoveProjectRole(ctx context.Context, role
|
||||
if role.Key == "" {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-id823", "Errors.Project.RoleInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, role.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, role.AggregateID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if !existing.ContainsRole(role) {
|
||||
if !existingProject.ContainsRole(role) {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-oe823", "Errors.Project.RoleNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoRole := model.ProjectRoleFromModel(role)
|
||||
grants := es.RemoveRoleFromGrants(repoProject, role.Key)
|
||||
projectAggregate, err := ProjectRoleRemovedAggregate(ctx, es.Eventstore.AggregateCreator(), repoProject, repoRole, grants)
|
||||
@@ -391,9 +391,9 @@ func (es *ProjectEventstore) PrepareRemoveProjectRole(ctx context.Context, role
|
||||
return repoProject, projectAggregate, nil
|
||||
}
|
||||
|
||||
func (es *ProjectEventstore) RemoveRoleFromGrants(existing *model.Project, roleKey string) []*model.ProjectGrant {
|
||||
grants := make([]*model.ProjectGrant, len(existing.Grants))
|
||||
for i, grant := range existing.Grants {
|
||||
func (es *ProjectEventstore) RemoveRoleFromGrants(existingProject *model.Project, roleKey string) []*model.ProjectGrant {
|
||||
grants := make([]*model.ProjectGrant, len(existingProject.Grants))
|
||||
for i, grant := range existingProject.Grants {
|
||||
newGrant := *grant
|
||||
roles := make([]string, 0)
|
||||
for _, role := range newGrant.RoleKeys {
|
||||
@@ -468,7 +468,7 @@ func (es *ProjectEventstore) ProjectChanges(ctx context.Context, id string, last
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ChangesQuery(projID string, latestSequence, limit uint64, sortAscending bool) *es_models.SearchQuery {
|
||||
func ChangesQuery(projectID string, latestSequence, limit uint64, sortAscending bool) *es_models.SearchQuery {
|
||||
query := es_models.NewSearchQuery().
|
||||
AggregateTypeFilter(model.ProjectAggregate)
|
||||
if !sortAscending {
|
||||
@@ -476,7 +476,7 @@ func ChangesQuery(projID string, latestSequence, limit uint64, sortAscending boo
|
||||
}
|
||||
|
||||
query.LatestSequenceFilter(latestSequence).
|
||||
AggregateIDFilter(projID).
|
||||
AggregateIDFilter(projectID).
|
||||
SetLimit(limit)
|
||||
return query
|
||||
}
|
||||
@@ -500,7 +500,7 @@ func (es *ProjectEventstore) AddApplication(ctx context.Context, app *proj_model
|
||||
if app == nil || !app.IsValid(true) {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9eidw", "Errors.Project.AppInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, app.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, app.AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -513,7 +513,7 @@ func (es *ProjectEventstore) AddApplication(ctx context.Context, app *proj_model
|
||||
var stringPw string
|
||||
if app.OIDCConfig != nil {
|
||||
app.OIDCConfig.AppID = id
|
||||
err := app.OIDCConfig.GenerateNewClientID(es.idGenerator, existing)
|
||||
err := app.OIDCConfig.GenerateNewClientID(es.idGenerator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -522,7 +522,7 @@ func (es *ProjectEventstore) AddApplication(ctx context.Context, app *proj_model
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoApp := model.AppFromModel(app)
|
||||
|
||||
addAggregate := ApplicationAddedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoApp)
|
||||
@@ -544,14 +544,14 @@ func (es *ProjectEventstore) ChangeApplication(ctx context.Context, app *proj_mo
|
||||
if app == nil || !app.IsValid(false) {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-dieuw", "Errors.Project.AppInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, app.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, app.AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, app := existing.GetApp(app.AppID); app == nil {
|
||||
if _, app := existingProject.GetApp(app.AppID); app == nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-die83", "Errors.Project.AppNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoApp := model.AppFromModel(app)
|
||||
|
||||
projectAggregate := ApplicationChangedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoApp)
|
||||
@@ -570,14 +570,14 @@ func (es *ProjectEventstore) RemoveApplication(ctx context.Context, app *proj_mo
|
||||
if app.AppID == "" {
|
||||
return caos_errs.ThrowPreconditionFailed(nil, "EVENT-id832", "Errors.Project.IDMissing")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, app.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, app.AggregateID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, app := existing.GetApp(app.AppID); app == nil {
|
||||
if _, app := existingProject.GetApp(app.AppID); app == nil {
|
||||
return caos_errs.ThrowPreconditionFailed(nil, "EVENT-di83s", "Errors.Project.AppNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
appRepo := model.AppFromModel(app)
|
||||
projectAggregate := ApplicationRemovedAggregate(es.Eventstore.AggregateCreator(), repoProject, appRepo)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoProject.AppendEvents, projectAggregate)
|
||||
@@ -592,14 +592,14 @@ func (es *ProjectEventstore) PrepareRemoveApplication(ctx context.Context, app *
|
||||
if app.AppID == "" {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-xu0Wy", "Errors.Project.IDMissing")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, app.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, app.AggregateID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if _, app := existing.GetApp(app.AppID); app == nil {
|
||||
if _, app := existingProject.GetApp(app.AppID); app == nil {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-gaOD2", "Errors.Project.AppNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
appRepo := model.AppFromModel(app)
|
||||
projectAggregate := ApplicationRemovedAggregate(es.Eventstore.AggregateCreator(), repoProject, appRepo)
|
||||
agg, err := projectAggregate(ctx)
|
||||
@@ -659,15 +659,15 @@ func (es *ProjectEventstore) DeactivateApplication(ctx context.Context, projectI
|
||||
if appID == "" {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-dlp9e", "Errors.Project.IDMissing")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, projectID)
|
||||
existingProject, err := es.ProjectByID(ctx, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
app := &proj_model.Application{AppID: appID}
|
||||
if _, app := existing.GetApp(app.AppID); app == nil {
|
||||
if _, app := existingProject.GetApp(app.AppID); app == nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-slpe9", "Errors.Project.AppNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoApp := model.AppFromModel(app)
|
||||
|
||||
projectAggregate := ApplicationDeactivatedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoApp)
|
||||
@@ -686,15 +686,15 @@ func (es *ProjectEventstore) ReactivateApplication(ctx context.Context, projectI
|
||||
if appID == "" {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-0odi2", "Errors.Project.IDMissing")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, projectID)
|
||||
existingProject, err := es.ProjectByID(ctx, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
app := &proj_model.Application{AppID: appID}
|
||||
if _, app := existing.GetApp(app.AppID); app == nil {
|
||||
if _, app := existingProject.GetApp(app.AppID); app == nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-ld92d", "Errors.Project.AppNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoApp := model.AppFromModel(app)
|
||||
|
||||
projectAggregate := ApplicationReactivatedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoApp)
|
||||
@@ -713,18 +713,18 @@ func (es *ProjectEventstore) ChangeOIDCConfig(ctx context.Context, config *proj_
|
||||
if config == nil || !config.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-du834", "Errors.Project.OIDCConfigInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, config.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, config.AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var app *proj_model.Application
|
||||
if _, app = existing.GetApp(config.AppID); app == nil {
|
||||
if _, app = existingProject.GetApp(config.AppID); app == nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-dkso8", "Errors.Project.AppNoExisting")
|
||||
}
|
||||
if app.Type != proj_model.AppTypeOIDC {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-98uje", "Errors.Project.AppIsNotOIDC")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoConfig := model.OIDCConfigFromModel(config)
|
||||
|
||||
projectAggregate := OIDCConfigChangedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoConfig)
|
||||
@@ -743,12 +743,12 @@ func (es *ProjectEventstore) ChangeOIDCConfigSecret(ctx context.Context, project
|
||||
if appID == "" {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-7ue34", "Errors.Project.OIDCConfigInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, projectID)
|
||||
existingProject, err := es.ProjectByID(ctx, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var app *proj_model.Application
|
||||
if _, app = existing.GetApp(appID); app == nil {
|
||||
if _, app = existingProject.GetApp(appID); app == nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9odi4", "Errors.Project.AppNotExisting")
|
||||
}
|
||||
if app.Type != proj_model.AppTypeOIDC {
|
||||
@@ -757,7 +757,7 @@ func (es *ProjectEventstore) ChangeOIDCConfigSecret(ctx context.Context, project
|
||||
if app.OIDCConfig.AuthMethodType == proj_model.OIDCAuthMethodTypeNone {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-GDrg2", "Errors.Project.OIDCAuthMethodNoneSecret")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
|
||||
stringPw, err := app.OIDCConfig.GenerateNewClientSecret(es.pwGenerator)
|
||||
if err != nil {
|
||||
@@ -784,12 +784,12 @@ func (es *ProjectEventstore) VerifyOIDCClientSecret(ctx context.Context, project
|
||||
if appID == "" {
|
||||
return caos_errs.ThrowPreconditionFailed(nil, "EVENT-H3RT2", "Errors.Project.RequiredFieldsMissing")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, projectID)
|
||||
existingProject, err := es.ProjectByID(ctx, projectID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var app *proj_model.Application
|
||||
if _, app = existing.GetApp(appID); app == nil {
|
||||
if _, app = existingProject.GetApp(appID); app == nil {
|
||||
return caos_errs.ThrowPreconditionFailed(nil, "EVENT-D6hba", "Errors.Project.AppNoExisting")
|
||||
}
|
||||
if app.Type != proj_model.AppTypeOIDC {
|
||||
@@ -797,9 +797,9 @@ func (es *ProjectEventstore) VerifyOIDCClientSecret(ctx context.Context, project
|
||||
}
|
||||
|
||||
if err := crypto.CompareHash(app.OIDCConfig.ClientSecret, []byte(secret), es.passwordAlg); err == nil {
|
||||
return es.setOIDCClientSecretCheckResult(ctx, existing, app.AppID, OIDCClientSecretCheckSucceededAggregate)
|
||||
return es.setOIDCClientSecretCheckResult(ctx, existingProject, app.AppID, OIDCClientSecretCheckSucceededAggregate)
|
||||
}
|
||||
if err := es.setOIDCClientSecretCheckResult(ctx, existing, app.AppID, OIDCClientSecretCheckFailedAggregate); err != nil {
|
||||
if err := es.setOIDCClientSecretCheckResult(ctx, existingProject, app.AppID, OIDCClientSecretCheckFailedAggregate); err != nil {
|
||||
return err
|
||||
}
|
||||
return caos_errs.ThrowInvalidArgument(nil, "EVENT-wg24q", "Errors.Internal")
|
||||
@@ -834,14 +834,14 @@ func (es *ProjectEventstore) AddProjectGrant(ctx context.Context, grant *proj_mo
|
||||
if grant == nil || !grant.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-37dhs", "Errors.Project.GrantInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, grant.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, grant.AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existing.ContainsGrantForOrg(grant.GrantedOrgID) {
|
||||
if existingProject.ContainsGrantForOrg(grant.GrantedOrgID) {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-7ug4g", "Errors.Project.GrantAlreadyExists")
|
||||
}
|
||||
if !existing.ContainsRoles(grant.RoleKeys) {
|
||||
if !existingProject.ContainsRoles(grant.RoleKeys) {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-di83d", "Errors.Project.GrantHasNotExistingRole")
|
||||
}
|
||||
id, err := es.idGenerator.Next()
|
||||
@@ -850,7 +850,7 @@ func (es *ProjectEventstore) AddProjectGrant(ctx context.Context, grant *proj_mo
|
||||
}
|
||||
grant.GrantID = id
|
||||
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoGrant := model.GrantFromModel(grant)
|
||||
|
||||
addAggregate := ProjectGrantAddedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoGrant)
|
||||
@@ -868,19 +868,19 @@ func (es *ProjectEventstore) PrepareChangeProjectGrant(ctx context.Context, gran
|
||||
if grant == nil && grant.GrantID == "" {
|
||||
return nil, nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-8sie3", "Errors.Project.GrantInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, grant.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, grant.AggregateID)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
_, existingGrant := existing.GetGrant(grant.GrantID)
|
||||
_, existingGrant := existingProject.GetGrant(grant.GrantID)
|
||||
if existingGrant == nil {
|
||||
return nil, nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-die83", "Errors.Project.GrantNotExisting")
|
||||
}
|
||||
if !existing.ContainsRoles(grant.RoleKeys) {
|
||||
if !existingProject.ContainsRoles(grant.RoleKeys) {
|
||||
return nil, nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-di83d", "Error.Project.GrantHasNotExistingRole")
|
||||
}
|
||||
removedRoles := existingGrant.GetRemovedRoles(grant.RoleKeys)
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoGrant := model.GrantFromModel(grant)
|
||||
|
||||
projectAggregate := ProjectGrantChangedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoGrant)
|
||||
@@ -920,14 +920,14 @@ func (es *ProjectEventstore) PrepareRemoveProjectGrant(ctx context.Context, gran
|
||||
if grant.GrantID == "" {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-8eud6", "Errors.Project.IDMissing")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, grant.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, grant.AggregateID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if _, g := existing.GetGrant(grant.GrantID); g == nil {
|
||||
if _, g := existingProject.GetGrant(grant.GrantID); g == nil {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-9ie3s", "Errors.Project.GrantNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
grantRepo := model.GrantFromModel(grant)
|
||||
projectAggregate := ProjectGrantRemovedAggregate(es.Eventstore.AggregateCreator(), repoProject, grantRepo)
|
||||
return repoProject, projectAggregate, nil
|
||||
@@ -937,15 +937,15 @@ func (es *ProjectEventstore) DeactivateProjectGrant(ctx context.Context, project
|
||||
if grantID == "" {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-7due2", "Errors.Project.IDMissing")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, projectID)
|
||||
existingProject, err := es.ProjectByID(ctx, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
grant := &proj_model.ProjectGrant{GrantID: grantID}
|
||||
if _, g := existing.GetGrant(grant.GrantID); g == nil {
|
||||
if _, g := existingProject.GetGrant(grant.GrantID); g == nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-slpe9", "Errors.Project.GrantNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoGrant := model.GrantFromModel(grant)
|
||||
|
||||
projectAggregate := ProjectGrantDeactivatedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoGrant)
|
||||
@@ -964,15 +964,15 @@ func (es *ProjectEventstore) ReactivateProjectGrant(ctx context.Context, project
|
||||
if grantID == "" {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-d7suw", "Errors.Project.IDMissing")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, projectID)
|
||||
existingProject, err := es.ProjectByID(ctx, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
grant := &proj_model.ProjectGrant{GrantID: grantID}
|
||||
if _, g := existing.GetGrant(grant.GrantID); g == nil {
|
||||
if _, g := existingProject.GetGrant(grant.GrantID); g == nil {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-0spew", "Errors.Project.GrantNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoGrant := model.GrantFromModel(grant)
|
||||
|
||||
projectAggregate := ProjectGrantReactivatedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoGrant)
|
||||
@@ -1008,14 +1008,14 @@ func (es *ProjectEventstore) AddProjectGrantMember(ctx context.Context, member *
|
||||
if !member.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-0dor4", "Errors.Project.MemberInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existing.ContainsGrantMember(member) {
|
||||
if existingProject.ContainsGrantMember(member) {
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "EVENT-8die3", "Errors.Project.MemberAlreadyExists")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoMember := model.GrantMemberFromModel(member)
|
||||
|
||||
addAggregate := ProjectGrantMemberAddedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoMember)
|
||||
@@ -1036,14 +1036,14 @@ func (es *ProjectEventstore) ChangeProjectGrantMember(ctx context.Context, membe
|
||||
if !member.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-dkw35", "Errors.Project.MemberInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !existing.ContainsGrantMember(member) {
|
||||
if !existingProject.ContainsGrantMember(member) {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-8dj4s", "Errors.Project.MemberNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoMember := model.GrantMemberFromModel(member)
|
||||
|
||||
projectAggregate := ProjectGrantMemberChangedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoMember)
|
||||
@@ -1064,14 +1064,14 @@ func (es *ProjectEventstore) RemoveProjectGrantMember(ctx context.Context, membe
|
||||
if member.UserID == "" {
|
||||
return caos_errs.ThrowPreconditionFailed(nil, "EVENT-8su4r", "Errors.Project.MemberInvalid")
|
||||
}
|
||||
existing, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
existingProject, err := es.ProjectByID(ctx, member.AggregateID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !existing.ContainsGrantMember(member) {
|
||||
if !existingProject.ContainsGrantMember(member) {
|
||||
return caos_errs.ThrowPreconditionFailed(nil, "EVENT-9ode4", "Errors.Project.MemberNotExisting")
|
||||
}
|
||||
repoProject := model.ProjectFromModel(existing)
|
||||
repoProject := model.ProjectFromModel(existingProject)
|
||||
repoMember := model.GrantMemberFromModel(member)
|
||||
|
||||
projectAggregate := ProjectGrantMemberRemovedAggregate(es.Eventstore.AggregateCreator(), repoProject, repoMember)
|
||||
|
@@ -207,10 +207,10 @@ func TestUpdateProject(t *testing.T) {
|
||||
func TestDeactivateProject(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
type args struct {
|
||||
es *ProjectEventstore
|
||||
ctx context.Context
|
||||
existing *model.Project
|
||||
new *model.Project
|
||||
es *ProjectEventstore
|
||||
ctx context.Context
|
||||
existingProject *model.Project
|
||||
newProject *model.Project
|
||||
}
|
||||
type res struct {
|
||||
project *model.Project
|
||||
@@ -225,9 +225,9 @@ func TestDeactivateProject(t *testing.T) {
|
||||
{
|
||||
name: "deactivate project, ok",
|
||||
args: args{
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive},
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existingProject: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive},
|
||||
},
|
||||
res: res{
|
||||
project: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "NameNew", State: model.ProjectStateInactive},
|
||||
@@ -236,9 +236,9 @@ func TestDeactivateProject(t *testing.T) {
|
||||
{
|
||||
name: "deactivate project with inactive state",
|
||||
args: args{
|
||||
es: GetMockManipulateInactiveProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateInactive},
|
||||
es: GetMockManipulateInactiveProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existingProject: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateInactive},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
@@ -248,9 +248,9 @@ func TestDeactivateProject(t *testing.T) {
|
||||
{
|
||||
name: "existing not found",
|
||||
args: args{
|
||||
es: GetMockManipulateProjectNoEvents(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive},
|
||||
es: GetMockManipulateProjectNoEvents(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existingProject: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
@@ -260,7 +260,7 @@ func TestDeactivateProject(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result, err := tt.args.es.DeactivateProject(tt.args.ctx, tt.args.existing.AggregateID)
|
||||
result, err := tt.args.es.DeactivateProject(tt.args.ctx, tt.args.existingProject.AggregateID)
|
||||
|
||||
if !tt.res.wantErr && result.AggregateID == "" {
|
||||
t.Errorf("result has no id")
|
||||
@@ -278,10 +278,10 @@ func TestDeactivateProject(t *testing.T) {
|
||||
func TestReactivateProject(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
type args struct {
|
||||
es *ProjectEventstore
|
||||
ctx context.Context
|
||||
existing *model.Project
|
||||
new *model.Project
|
||||
es *ProjectEventstore
|
||||
ctx context.Context
|
||||
existingPolicy *model.Project
|
||||
newPolicy *model.Project
|
||||
}
|
||||
type res struct {
|
||||
project *model.Project
|
||||
@@ -296,9 +296,9 @@ func TestReactivateProject(t *testing.T) {
|
||||
{
|
||||
name: "reactivate project, ok",
|
||||
args: args{
|
||||
es: GetMockManipulateInactiveProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateInactive},
|
||||
es: GetMockManipulateInactiveProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existingPolicy: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateInactive},
|
||||
},
|
||||
res: res{
|
||||
project: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "NameNew", State: model.ProjectStateActive},
|
||||
@@ -307,9 +307,9 @@ func TestReactivateProject(t *testing.T) {
|
||||
{
|
||||
name: "reactivate project with inactive state",
|
||||
args: args{
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive},
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existingPolicy: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
@@ -319,9 +319,9 @@ func TestReactivateProject(t *testing.T) {
|
||||
{
|
||||
name: "existing not found",
|
||||
args: args{
|
||||
es: GetMockManipulateProjectNoEvents(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive},
|
||||
es: GetMockManipulateProjectNoEvents(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existingPolicy: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Name: "Name", State: model.ProjectStateActive},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
@@ -331,7 +331,7 @@ func TestReactivateProject(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result, err := tt.args.es.ReactivateProject(tt.args.ctx, tt.args.existing.AggregateID)
|
||||
result, err := tt.args.es.ReactivateProject(tt.args.ctx, tt.args.existingPolicy.AggregateID)
|
||||
|
||||
if !tt.res.wantErr && result.AggregateID == "" {
|
||||
t.Errorf("result has no id")
|
||||
@@ -349,9 +349,9 @@ func TestReactivateProject(t *testing.T) {
|
||||
func TestRemoveProject(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
type args struct {
|
||||
es *ProjectEventstore
|
||||
ctx context.Context
|
||||
existing *model.Project
|
||||
es *ProjectEventstore
|
||||
ctx context.Context
|
||||
existingPolicy *model.Project
|
||||
}
|
||||
type res struct {
|
||||
result *model.Project
|
||||
@@ -368,10 +368,12 @@ func TestRemoveProject(t *testing.T) {
|
||||
args: args{
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{
|
||||
existingPolicy: &model.Project{
|
||||
ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1},
|
||||
Name: "Name",
|
||||
Members: []*model.ProjectMember{&model.ProjectMember{UserID: "UserID", Roles: []string{"Roles"}}},
|
||||
Members: []*model.ProjectMember{
|
||||
{UserID: "UserID", Roles: []string{"Roles"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -383,10 +385,12 @@ func TestRemoveProject(t *testing.T) {
|
||||
args: args{
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{
|
||||
existingPolicy: &model.Project{
|
||||
ObjectRoot: es_models.ObjectRoot{Sequence: 1},
|
||||
Name: "Name",
|
||||
Members: []*model.ProjectMember{&model.ProjectMember{UserID: "UserID", Roles: []string{"Roles"}}},
|
||||
Members: []*model.ProjectMember{
|
||||
{UserID: "UserID", Roles: []string{"Roles"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -397,9 +401,9 @@ func TestRemoveProject(t *testing.T) {
|
||||
{
|
||||
name: "project not existing",
|
||||
args: args{
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{},
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existingPolicy: &model.Project{},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
@@ -409,9 +413,9 @@ func TestRemoveProject(t *testing.T) {
|
||||
{
|
||||
name: "existing not found",
|
||||
args: args{
|
||||
es: GetMockManipulateProjectNoEvents(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "OtherAggregateID", Sequence: 1}},
|
||||
es: GetMockManipulateProjectNoEvents(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existingPolicy: &model.Project{ObjectRoot: es_models.ObjectRoot{AggregateID: "OtherAggregateID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
@@ -421,7 +425,7 @@ func TestRemoveProject(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := tt.args.es.RemoveProject(tt.args.ctx, tt.args.existing)
|
||||
err := tt.args.es.RemoveProject(tt.args.ctx, tt.args.existingPolicy)
|
||||
|
||||
if !tt.res.wantErr && err != nil {
|
||||
t.Errorf("should not get err")
|
||||
@@ -700,10 +704,10 @@ func TestChangeProjectMember(t *testing.T) {
|
||||
func TestRemoveProjectMember(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
type args struct {
|
||||
es *ProjectEventstore
|
||||
ctx context.Context
|
||||
existing *model.Project
|
||||
member *model.ProjectMember
|
||||
es *ProjectEventstore
|
||||
ctx context.Context
|
||||
existingProject *model.Project
|
||||
member *model.ProjectMember
|
||||
}
|
||||
type res struct {
|
||||
result *model.ProjectMember
|
||||
@@ -720,10 +724,12 @@ func TestRemoveProjectMember(t *testing.T) {
|
||||
args: args{
|
||||
es: GetMockManipulateProjectWithMember(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{
|
||||
existingProject: &model.Project{
|
||||
ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1},
|
||||
Name: "Name",
|
||||
Members: []*model.ProjectMember{&model.ProjectMember{UserID: "UserID", Roles: []string{"Roles"}}},
|
||||
Members: []*model.ProjectMember{
|
||||
{UserID: "UserID", Roles: []string{"Roles"}},
|
||||
},
|
||||
},
|
||||
member: &model.ProjectMember{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, UserID: "UserID"},
|
||||
},
|
||||
@@ -736,10 +742,12 @@ func TestRemoveProjectMember(t *testing.T) {
|
||||
args: args{
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{
|
||||
existingProject: &model.Project{
|
||||
ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1},
|
||||
Name: "Name",
|
||||
Members: []*model.ProjectMember{&model.ProjectMember{UserID: "UserID", Roles: []string{"Roles"}}},
|
||||
Members: []*model.ProjectMember{
|
||||
{UserID: "UserID", Roles: []string{"Roles"}},
|
||||
},
|
||||
},
|
||||
member: &model.ProjectMember{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Roles: []string{"ChangeRoles"}},
|
||||
},
|
||||
@@ -753,7 +761,7 @@ func TestRemoveProjectMember(t *testing.T) {
|
||||
args: args{
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.Project{
|
||||
existingProject: &model.Project{
|
||||
ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1},
|
||||
Name: "Name",
|
||||
},
|
||||
@@ -811,9 +819,11 @@ func TestAddProjectRole(t *testing.T) {
|
||||
{
|
||||
name: "add project role, ok",
|
||||
args: args{
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
roles: []*model.ProjectRole{&model.ProjectRole{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Key: "Key", DisplayName: "DisplayName", Group: "Group"}},
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
roles: []*model.ProjectRole{
|
||||
{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Key: "Key", DisplayName: "DisplayName", Group: "Group"},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
result: &model.ProjectRole{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Key: "Key", DisplayName: "DisplayName", Group: "Group"},
|
||||
@@ -822,9 +832,11 @@ func TestAddProjectRole(t *testing.T) {
|
||||
{
|
||||
name: "no key",
|
||||
args: args{
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
roles: []*model.ProjectRole{&model.ProjectRole{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, DisplayName: "DisplayName", Group: "Group"}},
|
||||
es: GetMockManipulateProject(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
roles: []*model.ProjectRole{
|
||||
{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, DisplayName: "DisplayName", Group: "Group"},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
@@ -834,9 +846,11 @@ func TestAddProjectRole(t *testing.T) {
|
||||
{
|
||||
name: "role already existing",
|
||||
args: args{
|
||||
es: GetMockManipulateProjectWithRole(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
roles: []*model.ProjectRole{&model.ProjectRole{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Key: "Key", DisplayName: "DisplayName", Group: "Group"}},
|
||||
es: GetMockManipulateProjectWithRole(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
roles: []*model.ProjectRole{
|
||||
{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Key: "Key", DisplayName: "DisplayName", Group: "Group"},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
@@ -846,9 +860,11 @@ func TestAddProjectRole(t *testing.T) {
|
||||
{
|
||||
name: "existing project not found",
|
||||
args: args{
|
||||
es: GetMockManipulateProjectNoEvents(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
roles: []*model.ProjectRole{&model.ProjectRole{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Key: "Key", DisplayName: "DisplayName", Group: "Group"}},
|
||||
es: GetMockManipulateProjectNoEvents(ctrl),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
roles: []*model.ProjectRole{
|
||||
{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}, Key: "Key", DisplayName: "DisplayName", Group: "Group"},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
wantErr: true,
|
||||
@@ -2733,7 +2749,12 @@ func TestChangesProject(t *testing.T) {
|
||||
limit: 0,
|
||||
},
|
||||
res: res{
|
||||
changes: &model.ProjectChanges{Changes: []*model.ProjectChange{&model.ProjectChange{EventType: "", Sequence: 1, ModifierId: ""}}, LastSequence: 1},
|
||||
changes: &model.ProjectChanges{
|
||||
Changes: []*model.ProjectChange{
|
||||
{EventType: "", Sequence: 1, ModifierId: ""},
|
||||
},
|
||||
LastSequence: 1,
|
||||
},
|
||||
project: &model.Project{Name: "MusterProject"},
|
||||
},
|
||||
},
|
||||
@@ -2777,7 +2798,7 @@ func TestChangesApplication(t *testing.T) {
|
||||
type args struct {
|
||||
es *ProjectEventstore
|
||||
id string
|
||||
secId string
|
||||
secID string
|
||||
lastSequence uint64
|
||||
limit uint64
|
||||
}
|
||||
@@ -2797,13 +2818,18 @@ func TestChangesApplication(t *testing.T) {
|
||||
args: args{
|
||||
es: GetMockChangesApplicationOK(ctrl),
|
||||
id: "1",
|
||||
secId: "AppId",
|
||||
secID: "AppId",
|
||||
lastSequence: 0,
|
||||
limit: 0,
|
||||
},
|
||||
res: res{
|
||||
changes: &model.ApplicationChanges{Changes: []*model.ApplicationChange{&model.ApplicationChange{EventType: "", Sequence: 1, ModifierId: ""}}, LastSequence: 1},
|
||||
app: &model.Application{Name: "MusterApp", AppID: "AppId", Type: 3},
|
||||
changes: &model.ApplicationChanges{
|
||||
Changes: []*model.ApplicationChange{
|
||||
{EventType: "", Sequence: 1, ModifierId: ""},
|
||||
},
|
||||
LastSequence: 1,
|
||||
},
|
||||
app: &model.Application{Name: "MusterApp", AppID: "AppId", Type: 3},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -2811,7 +2837,7 @@ func TestChangesApplication(t *testing.T) {
|
||||
args: args{
|
||||
es: GetMockChangesApplicationNoEvents(ctrl),
|
||||
id: "2",
|
||||
secId: "2",
|
||||
secID: "2",
|
||||
lastSequence: 0,
|
||||
limit: 0,
|
||||
},
|
||||
@@ -2823,7 +2849,7 @@ func TestChangesApplication(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result, err := tt.args.es.ApplicationChanges(nil, tt.args.id, tt.args.secId, tt.args.lastSequence, tt.args.limit, false)
|
||||
result, err := tt.args.es.ApplicationChanges(nil, tt.args.id, tt.args.secID, tt.args.lastSequence, tt.args.limit, false)
|
||||
|
||||
app := &model.Application{}
|
||||
if result != nil && len(result.Changes) > 0 {
|
||||
|
@@ -2,15 +2,16 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/project/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestApplicationChanges(t *testing.T) {
|
||||
type args struct {
|
||||
existing *Application
|
||||
new *Application
|
||||
existingProject *Application
|
||||
newProject *Application
|
||||
}
|
||||
type res struct {
|
||||
changesLen int
|
||||
@@ -23,8 +24,8 @@ func TestApplicationChanges(t *testing.T) {
|
||||
{
|
||||
name: "application name changes",
|
||||
args: args{
|
||||
existing: &Application{AppID: "AppID", Name: "Name"},
|
||||
new: &Application{AppID: "AppID", Name: "NameChanged"},
|
||||
existingProject: &Application{AppID: "AppID", Name: "Name"},
|
||||
newProject: &Application{AppID: "AppID", Name: "NameChanged"},
|
||||
},
|
||||
res: res{
|
||||
changesLen: 2,
|
||||
@@ -33,8 +34,8 @@ func TestApplicationChanges(t *testing.T) {
|
||||
{
|
||||
name: "no changes",
|
||||
args: args{
|
||||
existing: &Application{AppID: "AppID", Name: "Name"},
|
||||
new: &Application{AppID: "AppID", Name: "Name"},
|
||||
existingProject: &Application{AppID: "AppID", Name: "Name"},
|
||||
newProject: &Application{AppID: "AppID", Name: "Name"},
|
||||
},
|
||||
res: res{
|
||||
changesLen: 1,
|
||||
@@ -43,7 +44,7 @@ func TestApplicationChanges(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
changes := tt.args.existing.Changes(tt.args.new)
|
||||
changes := tt.args.existingProject.Changes(tt.args.newProject)
|
||||
if len(changes) != tt.res.changesLen {
|
||||
t.Errorf("got wrong changes len: expected: %v, actual: %v ", tt.res.changesLen, len(changes))
|
||||
}
|
||||
@@ -69,7 +70,11 @@ func TestAppendAddAppEvent(t *testing.T) {
|
||||
app: &Application{Name: "Application"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{Applications: []*Application{&Application{Name: "Application"}}},
|
||||
result: &Project{
|
||||
Applications: []*Application{
|
||||
{Name: "Application"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -103,11 +108,19 @@ func TestAppendChangeAppEvent(t *testing.T) {
|
||||
{
|
||||
name: "append change application event",
|
||||
args: args{
|
||||
project: &Project{Applications: []*Application{&Application{Name: "Application"}}},
|
||||
app: &Application{Name: "Application Change"},
|
||||
event: &es_models.Event{},
|
||||
project: &Project{
|
||||
Applications: []*Application{
|
||||
{Name: "Application"},
|
||||
},
|
||||
},
|
||||
app: &Application{Name: "Application Change"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{
|
||||
Applications: []*Application{
|
||||
{Name: "Application Change"},
|
||||
},
|
||||
},
|
||||
result: &Project{Applications: []*Application{&Application{Name: "Application Change"}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -141,9 +154,13 @@ func TestAppendRemoveAppEvent(t *testing.T) {
|
||||
{
|
||||
name: "append remove application event",
|
||||
args: args{
|
||||
project: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application"}}},
|
||||
app: &Application{AppID: "AppID", Name: "Application"},
|
||||
event: &es_models.Event{},
|
||||
project: &Project{
|
||||
Applications: []*Application{
|
||||
{AppID: "AppID", Name: "Application"},
|
||||
},
|
||||
},
|
||||
app: &Application{AppID: "AppID", Name: "Application"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{Applications: []*Application{}},
|
||||
},
|
||||
@@ -177,22 +194,38 @@ func TestAppendAppStateEvent(t *testing.T) {
|
||||
{
|
||||
name: "append deactivate application event",
|
||||
args: args{
|
||||
project: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.AppStateActive)}}},
|
||||
app: &ApplicationID{AppID: "AppID"},
|
||||
event: &es_models.Event{},
|
||||
state: model.AppStateInactive,
|
||||
project: &Project{
|
||||
Applications: []*Application{
|
||||
{AppID: "AppID", Name: "Application", State: int32(model.AppStateActive)},
|
||||
},
|
||||
},
|
||||
app: &ApplicationID{AppID: "AppID"},
|
||||
event: &es_models.Event{},
|
||||
state: model.AppStateInactive,
|
||||
},
|
||||
result: &Project{
|
||||
Applications: []*Application{
|
||||
{AppID: "AppID", Name: "Application", State: int32(model.AppStateInactive)},
|
||||
},
|
||||
},
|
||||
result: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.AppStateInactive)}}},
|
||||
},
|
||||
{
|
||||
name: "append reactivate application event",
|
||||
args: args{
|
||||
project: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.AppStateInactive)}}},
|
||||
app: &ApplicationID{AppID: "AppID"},
|
||||
event: &es_models.Event{},
|
||||
state: model.AppStateActive,
|
||||
project: &Project{
|
||||
Applications: []*Application{
|
||||
{AppID: "AppID", Name: "Application", State: int32(model.AppStateInactive)},
|
||||
},
|
||||
},
|
||||
app: &ApplicationID{AppID: "AppID"},
|
||||
event: &es_models.Event{},
|
||||
state: model.AppStateActive,
|
||||
},
|
||||
result: &Project{
|
||||
Applications: []*Application{
|
||||
{AppID: "AppID", Name: "Application", State: int32(model.AppStateActive)},
|
||||
},
|
||||
},
|
||||
result: &Project{Applications: []*Application{&Application{AppID: "AppID", Name: "Application", State: int32(model.AppStateActive)}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@@ -2,14 +2,15 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
"testing"
|
||||
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
)
|
||||
|
||||
func TestOIDCConfigChanges(t *testing.T) {
|
||||
type args struct {
|
||||
existing *OIDCConfig
|
||||
new *OIDCConfig
|
||||
existingConfig *OIDCConfig
|
||||
newConfig *OIDCConfig
|
||||
}
|
||||
type res struct {
|
||||
changesLen int
|
||||
@@ -22,7 +23,7 @@ func TestOIDCConfigChanges(t *testing.T) {
|
||||
{
|
||||
name: "all possible values change",
|
||||
args: args{
|
||||
existing: &OIDCConfig{
|
||||
existingConfig: &OIDCConfig{
|
||||
AppID: "AppID",
|
||||
RedirectUris: []string{"RedirectUris"},
|
||||
ResponseTypes: []int32{1},
|
||||
@@ -31,7 +32,7 @@ func TestOIDCConfigChanges(t *testing.T) {
|
||||
AuthMethodType: 1,
|
||||
PostLogoutRedirectUris: []string{"PostLogoutRedirectUris"},
|
||||
},
|
||||
new: &OIDCConfig{
|
||||
newConfig: &OIDCConfig{
|
||||
AppID: "AppID",
|
||||
RedirectUris: []string{"RedirectUrisChanged"},
|
||||
ResponseTypes: []int32{2},
|
||||
@@ -48,7 +49,7 @@ func TestOIDCConfigChanges(t *testing.T) {
|
||||
{
|
||||
name: "no changes",
|
||||
args: args{
|
||||
existing: &OIDCConfig{
|
||||
existingConfig: &OIDCConfig{
|
||||
AppID: "AppID",
|
||||
RedirectUris: []string{"RedirectUris"},
|
||||
ResponseTypes: []int32{1},
|
||||
@@ -57,7 +58,7 @@ func TestOIDCConfigChanges(t *testing.T) {
|
||||
AuthMethodType: 1,
|
||||
PostLogoutRedirectUris: []string{"PostLogoutRedirectUris"},
|
||||
},
|
||||
new: &OIDCConfig{
|
||||
newConfig: &OIDCConfig{
|
||||
AppID: "AppID",
|
||||
RedirectUris: []string{"RedirectUris"},
|
||||
ResponseTypes: []int32{1},
|
||||
@@ -74,11 +75,11 @@ func TestOIDCConfigChanges(t *testing.T) {
|
||||
{
|
||||
name: "change not changeable attributes",
|
||||
args: args{
|
||||
existing: &OIDCConfig{
|
||||
existingConfig: &OIDCConfig{
|
||||
AppID: "AppID",
|
||||
ClientID: "ClientID",
|
||||
},
|
||||
new: &OIDCConfig{
|
||||
newConfig: &OIDCConfig{
|
||||
AppID: "AppIDChange",
|
||||
ClientID: "ClientIDChange",
|
||||
},
|
||||
@@ -90,7 +91,7 @@ func TestOIDCConfigChanges(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
changes := tt.args.existing.Changes(tt.args.new)
|
||||
changes := tt.args.existingConfig.Changes(tt.args.newConfig)
|
||||
if len(changes) != tt.res.changesLen {
|
||||
t.Errorf("got wrong changes len: expected: %v, actual: %v ", tt.res.changesLen, len(changes))
|
||||
}
|
||||
@@ -112,11 +113,19 @@ func TestAppendAddOIDCConfigEvent(t *testing.T) {
|
||||
{
|
||||
name: "append add application event",
|
||||
args: args{
|
||||
project: &Project{Applications: []*Application{&Application{AppID: "AppID"}}},
|
||||
config: &OIDCConfig{AppID: "AppID", ClientID: "ClientID"},
|
||||
event: &es_models.Event{},
|
||||
project: &Project{
|
||||
Applications: []*Application{
|
||||
{AppID: "AppID"},
|
||||
},
|
||||
},
|
||||
config: &OIDCConfig{AppID: "AppID", ClientID: "ClientID"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{
|
||||
Applications: []*Application{
|
||||
{AppID: "AppID", OIDCConfig: &OIDCConfig{AppID: "AppID", ClientID: "ClientID"}},
|
||||
},
|
||||
},
|
||||
result: &Project{Applications: []*Application{&Application{AppID: "AppID", OIDCConfig: &OIDCConfig{AppID: "AppID", ClientID: "ClientID"}}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -153,11 +162,19 @@ func TestAppendChangeOIDCConfigEvent(t *testing.T) {
|
||||
{
|
||||
name: "append change application event",
|
||||
args: args{
|
||||
project: &Project{Applications: []*Application{&Application{AppID: "AppID", OIDCConfig: &OIDCConfig{AppID: "AppID", ClientID: "ClientID"}}}},
|
||||
config: &OIDCConfig{AppID: "AppID", ClientID: "ClientID Changed"},
|
||||
event: &es_models.Event{},
|
||||
project: &Project{
|
||||
Applications: []*Application{
|
||||
{AppID: "AppID", OIDCConfig: &OIDCConfig{AppID: "AppID", ClientID: "ClientID"}},
|
||||
},
|
||||
},
|
||||
config: &OIDCConfig{AppID: "AppID", ClientID: "ClientID Changed"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Project{
|
||||
Applications: []*Application{
|
||||
{AppID: "AppID", OIDCConfig: &OIDCConfig{AppID: "AppID", ClientID: "ClientID Changed"}},
|
||||
},
|
||||
},
|
||||
result: &Project{Applications: []*Application{&Application{AppID: "AppID", OIDCConfig: &OIDCConfig{AppID: "AppID", ClientID: "ClientID Changed"}}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@@ -2,15 +2,16 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/project/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProjectChanges(t *testing.T) {
|
||||
type args struct {
|
||||
existing *Project
|
||||
new *Project
|
||||
existingProject *Project
|
||||
newProject *Project
|
||||
}
|
||||
type res struct {
|
||||
changesLen int
|
||||
@@ -23,8 +24,8 @@ func TestProjectChanges(t *testing.T) {
|
||||
{
|
||||
name: "project name changes",
|
||||
args: args{
|
||||
existing: &Project{Name: "Name"},
|
||||
new: &Project{Name: "NameChanged"},
|
||||
existingProject: &Project{Name: "Name"},
|
||||
newProject: &Project{Name: "NameChanged"},
|
||||
},
|
||||
res: res{
|
||||
changesLen: 1,
|
||||
@@ -33,8 +34,8 @@ func TestProjectChanges(t *testing.T) {
|
||||
{
|
||||
name: "no changes",
|
||||
args: args{
|
||||
existing: &Project{Name: "Name"},
|
||||
new: &Project{Name: "Name"},
|
||||
existingProject: &Project{Name: "Name"},
|
||||
newProject: &Project{Name: "Name"},
|
||||
},
|
||||
res: res{
|
||||
changesLen: 0,
|
||||
@@ -43,7 +44,7 @@ func TestProjectChanges(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
changes := tt.args.existing.Changes(tt.args.new)
|
||||
changes := tt.args.existingProject.Changes(tt.args.newProject)
|
||||
if len(changes) != tt.res.changesLen {
|
||||
t.Errorf("got wrong changes len: expected: %v, actual: %v ", tt.res.changesLen, len(changes))
|
||||
}
|
||||
@@ -65,7 +66,7 @@ func TestProjectFromEvents(t *testing.T) {
|
||||
name: "project from events, ok",
|
||||
args: args{
|
||||
event: []*es_models.Event{
|
||||
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectAdded},
|
||||
{AggregateID: "AggregateID", Sequence: 1, Type: ProjectAdded},
|
||||
},
|
||||
project: &Project{Name: "ProjectName"},
|
||||
},
|
||||
@@ -75,7 +76,7 @@ func TestProjectFromEvents(t *testing.T) {
|
||||
name: "project from events, nil project",
|
||||
args: args{
|
||||
event: []*es_models.Event{
|
||||
&es_models.Event{AggregateID: "AggregateID", Sequence: 1, Type: ProjectAdded},
|
||||
{AggregateID: "AggregateID", Sequence: 1, Type: ProjectAdded},
|
||||
},
|
||||
project: nil,
|
||||
},
|
||||
|
@@ -2,6 +2,7 @@ package eventsourcing
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
@@ -59,25 +60,25 @@ func ProjectCreateAggregate(aggCreator *es_models.AggregateCreator, project *mod
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectUpdateAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, new *model.Project) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectUpdateAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, newProject *model.Project) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if new == nil {
|
||||
if newProject == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dhr74", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
changes := existing.Changes(new)
|
||||
changes := existingProject.Changes(newProject)
|
||||
if len(changes) == 0 {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-9soPE", "Errors.NoChangesFound")
|
||||
}
|
||||
if existing.Name != new.Name {
|
||||
if existingProject.Name != newProject.Name {
|
||||
validationQuery := es_models.NewSearchQuery().
|
||||
AggregateTypeFilter(model.ProjectAggregate).
|
||||
EventTypesFilter(model.ProjectAdded, model.ProjectChanged, model.ProjectRemoved)
|
||||
|
||||
validation := addProjectValidation(new.Name)
|
||||
validation := addProjectValidation(newProject.Name)
|
||||
agg.SetPrecondition(validationQuery, validation)
|
||||
}
|
||||
return agg.AppendEvent(model.ProjectChanged, changes)
|
||||
@@ -102,23 +103,23 @@ func projectStateAggregate(aggCreator *es_models.AggregateCreator, project *mode
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectRemovedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existing *model.Project) (*es_models.Aggregate, error) {
|
||||
if existing == nil {
|
||||
func ProjectRemovedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existingProject *model.Project) (*es_models.Aggregate, error) {
|
||||
if existingProject == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Cj7lb", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return agg.AppendEvent(model.ProjectRemoved, existing)
|
||||
return agg.AppendEvent(model.ProjectRemoved, existingProject)
|
||||
}
|
||||
|
||||
func ProjectMemberAddedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, member *model.ProjectMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectMemberAddedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, member *model.ProjectMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if member == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-ie34f", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -131,13 +132,13 @@ func ProjectMemberAddedAggregate(aggCreator *es_models.AggregateCreator, existin
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectMemberChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, member *model.ProjectMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectMemberChangedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, member *model.ProjectMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if member == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-d34fs", "Errors.Internal")
|
||||
}
|
||||
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -145,12 +146,12 @@ func ProjectMemberChangedAggregate(aggCreator *es_models.AggregateCreator, exist
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectMemberRemovedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, member *model.ProjectMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectMemberRemovedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, member *model.ProjectMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if member == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dieu7", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -158,12 +159,12 @@ func ProjectMemberRemovedAggregate(aggCreator *es_models.AggregateCreator, exist
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectRoleAddedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, roles ...*model.ProjectRole) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectRoleAddedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, roles ...*model.ProjectRole) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if roles == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-sleo9", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -177,12 +178,12 @@ func ProjectRoleAddedAggregate(aggCreator *es_models.AggregateCreator, existing
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectRoleChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, role *model.ProjectRole) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectRoleChangedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, role *model.ProjectRole) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if role == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-oe8sf", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -190,11 +191,11 @@ func ProjectRoleChangedAggregate(aggCreator *es_models.AggregateCreator, existin
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectRoleRemovedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existing *model.Project, role *model.ProjectRole, grants []*model.ProjectGrant) (*es_models.Aggregate, error) {
|
||||
func ProjectRoleRemovedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existingProject *model.Project, role *model.ProjectRole, grants []*model.ProjectGrant) (*es_models.Aggregate, error) {
|
||||
if role == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-d8eis", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -204,7 +205,7 @@ func ProjectRoleRemovedAggregate(ctx context.Context, aggCreator *es_models.Aggr
|
||||
}
|
||||
for _, grant := range grants {
|
||||
var changes map[string]interface{}
|
||||
if _, g := model.GetProjectGrant(existing.Grants, grant.GrantID); grant != nil {
|
||||
if _, g := model.GetProjectGrant(existingProject.Grants, grant.GrantID); grant != nil {
|
||||
changes = g.Changes(grant)
|
||||
agg, err = agg.AppendEvent(model.ProjectGrantCascadeChanged, changes)
|
||||
if err != nil {
|
||||
@@ -215,12 +216,12 @@ func ProjectRoleRemovedAggregate(ctx context.Context, aggCreator *es_models.Aggr
|
||||
return agg, nil
|
||||
}
|
||||
|
||||
func ApplicationAddedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ApplicationAddedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if app == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-09du7", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -232,17 +233,17 @@ func ApplicationAddedAggregate(aggCreator *es_models.AggregateCreator, existing
|
||||
}
|
||||
}
|
||||
|
||||
func ApplicationChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ApplicationChangedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if app == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-sleo9", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var changes map[string]interface{}
|
||||
for _, a := range existing.Applications {
|
||||
for _, a := range existingProject.Applications {
|
||||
if a.AppID == app.AppID {
|
||||
changes = a.Changes(app)
|
||||
}
|
||||
@@ -253,12 +254,12 @@ func ApplicationChangedAggregate(aggCreator *es_models.AggregateCreator, existin
|
||||
}
|
||||
}
|
||||
|
||||
func ApplicationRemovedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ApplicationRemovedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if app == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-se23g", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -268,12 +269,12 @@ func ApplicationRemovedAggregate(aggCreator *es_models.AggregateCreator, existin
|
||||
}
|
||||
}
|
||||
|
||||
func ApplicationDeactivatedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ApplicationDeactivatedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if app == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-slfi3", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -283,12 +284,12 @@ func ApplicationDeactivatedAggregate(aggCreator *es_models.AggregateCreator, exi
|
||||
}
|
||||
}
|
||||
|
||||
func ApplicationReactivatedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ApplicationReactivatedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, app *model.Application) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if app == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-slf32", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -298,17 +299,17 @@ func ApplicationReactivatedAggregate(aggCreator *es_models.AggregateCreator, exi
|
||||
}
|
||||
}
|
||||
|
||||
func OIDCConfigChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, config *model.OIDCConfig) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func OIDCConfigChangedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, config *model.OIDCConfig) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if config == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-slf32", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var changes map[string]interface{}
|
||||
for _, a := range existing.Applications {
|
||||
for _, a := range existingProject.Applications {
|
||||
if a.AppID == config.AppID {
|
||||
if a.OIDCConfig != nil {
|
||||
changes = a.OIDCConfig.Changes(config)
|
||||
@@ -321,9 +322,9 @@ func OIDCConfigChangedAggregate(aggCreator *es_models.AggregateCreator, existing
|
||||
}
|
||||
}
|
||||
|
||||
func OIDCConfigSecretChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, appID string, secret *crypto.CryptoValue) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func OIDCConfigSecretChangedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, appID string, secret *crypto.CryptoValue) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -337,9 +338,9 @@ func OIDCConfigSecretChangedAggregate(aggCreator *es_models.AggregateCreator, ex
|
||||
}
|
||||
}
|
||||
|
||||
func OIDCClientSecretCheckSucceededAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, appID string) es_sdk.AggregateFunc {
|
||||
func OIDCClientSecretCheckSucceededAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, appID string) es_sdk.AggregateFunc {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -352,9 +353,9 @@ func OIDCClientSecretCheckSucceededAggregate(aggCreator *es_models.AggregateCrea
|
||||
}
|
||||
}
|
||||
|
||||
func OIDCClientSecretCheckFailedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, appID string) es_sdk.AggregateFunc {
|
||||
func OIDCClientSecretCheckFailedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, appID string) es_sdk.AggregateFunc {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -367,12 +368,12 @@ func OIDCClientSecretCheckFailedAggregate(aggCreator *es_models.AggregateCreator
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantAddedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectGrantAddedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if grant == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-kd89w", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -386,17 +387,17 @@ func ProjectGrantAddedAggregate(aggCreator *es_models.AggregateCreator, existing
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectGrantChangedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if grant == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-d9ie2", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var changes map[string]interface{}
|
||||
for _, g := range existing.Grants {
|
||||
for _, g := range existingProject.Grants {
|
||||
if g.GrantID == grant.GrantID {
|
||||
changes = g.Changes(grant)
|
||||
}
|
||||
@@ -407,12 +408,12 @@ func ProjectGrantChangedAggregate(aggCreator *es_models.AggregateCreator, existi
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantRemovedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectGrantRemovedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if grant == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-kci8d", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -422,12 +423,12 @@ func ProjectGrantRemovedAggregate(aggCreator *es_models.AggregateCreator, existi
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantDeactivatedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectGrantDeactivatedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if grant == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-id832", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -437,12 +438,12 @@ func ProjectGrantDeactivatedAggregate(aggCreator *es_models.AggregateCreator, ex
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantReactivatedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectGrantReactivatedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, grant *model.ProjectGrant) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if grant == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-8diw2", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -450,12 +451,12 @@ func ProjectGrantReactivatedAggregate(aggCreator *es_models.AggregateCreator, ex
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantMemberAddedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, member *model.ProjectGrantMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectGrantMemberAddedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, member *model.ProjectGrantMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if member == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-4ufh6", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -468,13 +469,13 @@ func ProjectGrantMemberAddedAggregate(aggCreator *es_models.AggregateCreator, ex
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantMemberChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, member *model.ProjectGrantMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectGrantMemberChangedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, member *model.ProjectGrantMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if member == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-d8i4h", "Errors.Internal")
|
||||
}
|
||||
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -487,12 +488,12 @@ func ProjectGrantMemberChangedAggregate(aggCreator *es_models.AggregateCreator,
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantMemberRemovedAggregate(aggCreator *es_models.AggregateCreator, existing *model.Project, member *model.ProjectGrantMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
func ProjectGrantMemberRemovedAggregate(aggCreator *es_models.AggregateCreator, existingProject *model.Project, member *model.ProjectGrantMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
||||
if member == nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-slp0r", "Errors.Internal")
|
||||
}
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existing)
|
||||
agg, err := ProjectAggregate(ctx, aggCreator, existingProject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -570,7 +571,7 @@ func checkExistsUser(events ...*es_models.Event) error {
|
||||
switch event.AggregateType {
|
||||
case usr_model.UserAggregate:
|
||||
switch event.Type {
|
||||
case usr_model.UserAdded, usr_model.UserRegistered:
|
||||
case usr_model.UserAdded, usr_model.UserRegistered, usr_model.HumanRegistered, usr_model.MachineAdded, usr_model.HumanAdded:
|
||||
existsUser = true
|
||||
case usr_model.UserRemoved:
|
||||
existsUser = false
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -38,23 +38,6 @@ type ProjectGrantMemberView struct {
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
}
|
||||
|
||||
func ProjectGrantMemberViewFromModel(member *model.ProjectGrantMemberView) *ProjectGrantMemberView {
|
||||
return &ProjectGrantMemberView{
|
||||
UserID: member.UserID,
|
||||
GrantID: member.GrantID,
|
||||
ProjectID: member.ProjectID,
|
||||
UserName: member.UserName,
|
||||
Email: member.Email,
|
||||
FirstName: member.FirstName,
|
||||
LastName: member.LastName,
|
||||
DisplayName: member.DisplayName,
|
||||
Roles: member.Roles,
|
||||
Sequence: member.Sequence,
|
||||
CreationDate: member.CreationDate,
|
||||
ChangeDate: member.ChangeDate,
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectGrantMemberToModel(member *ProjectGrantMemberView) *model.ProjectGrantMemberView {
|
||||
return &model.ProjectGrantMemberView{
|
||||
UserID: member.UserID,
|
||||
|
@@ -2,13 +2,14 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/caos/logging"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/project/model"
|
||||
es_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
|
||||
"github.com/lib/pq"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,22 +36,6 @@ type ProjectMemberView struct {
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
}
|
||||
|
||||
func ProjectMemberViewFromModel(member *model.ProjectMemberView) *ProjectMemberView {
|
||||
return &ProjectMemberView{
|
||||
UserID: member.UserID,
|
||||
ProjectID: member.ProjectID,
|
||||
UserName: member.UserName,
|
||||
Email: member.Email,
|
||||
FirstName: member.FirstName,
|
||||
LastName: member.LastName,
|
||||
DisplayName: member.DisplayName,
|
||||
Roles: member.Roles,
|
||||
Sequence: member.Sequence,
|
||||
CreationDate: member.CreationDate,
|
||||
ChangeDate: member.ChangeDate,
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectMemberToModel(member *ProjectMemberView) *model.ProjectMemberView {
|
||||
return &model.ProjectMemberView{
|
||||
UserID: member.UserID,
|
||||
|
Reference in New Issue
Block a user