zitadel/internal/query/projection/user_grant.go

318 lines
9.9 KiB
Go
Raw Normal View History

fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
package projection
import (
"context"
feat(database): support for postgres (#3998) * beginning with postgres statements * try pgx * use pgx * database * init works for postgres * arrays working * init for cockroach * init * start tests * tests * TESTS * ch * ch * chore: use go 1.18 * read stmts * fix typo * tests * connection string * add missing error handler * cleanup * start all apis * go mod tidy * old update * switch back to minute * on conflict * replace string slice with `database.StringArray` in db models * fix tests and start * update go version in dockerfile * setup go * clean up * remove notification migration * update * docs: add deploy guide for postgres * fix: revert sonyflake * use `database.StringArray` for daos * use `database.StringArray` every where * new tables * index naming, metadata primary key, project grant role key type * docs(postgres): change to beta * chore: correct compose * fix(defaults): add empty postgres config * refactor: remove unused code * docs: add postgres to self hosted * fix broken link * so? * change title * add mdx to link * fix stmt * update goreleaser in test-code * docs: improve postgres example * update more projections * fix: add beta log for postgres * revert index name change * prerelease * fix: add sequence to v1 "reduce paniced" * log if nil * add logging * fix: log output * fix(import): check if org exists and user * refactor: imports * fix(user): ignore malformed events * refactor: method naming * fix: test * refactor: correct errors.Is call * ci: don't build dev binaries on main * fix(go releaser): update version to 1.11.0 * fix(user): projection should not break * fix(user): handle error properly * docs: correct config example * Update .releaserc.js * Update .releaserc.js Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com>
2022-08-31 07:52:43 +00:00
"github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/handler"
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/repository/user"
"github.com/zitadel/zitadel/internal/repository/usergrant"
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
)
const (
feat(database): support for postgres (#3998) * beginning with postgres statements * try pgx * use pgx * database * init works for postgres * arrays working * init for cockroach * init * start tests * tests * TESTS * ch * ch * chore: use go 1.18 * read stmts * fix typo * tests * connection string * add missing error handler * cleanup * start all apis * go mod tidy * old update * switch back to minute * on conflict * replace string slice with `database.StringArray` in db models * fix tests and start * update go version in dockerfile * setup go * clean up * remove notification migration * update * docs: add deploy guide for postgres * fix: revert sonyflake * use `database.StringArray` for daos * use `database.StringArray` every where * new tables * index naming, metadata primary key, project grant role key type * docs(postgres): change to beta * chore: correct compose * fix(defaults): add empty postgres config * refactor: remove unused code * docs: add postgres to self hosted * fix broken link * so? * change title * add mdx to link * fix stmt * update goreleaser in test-code * docs: improve postgres example * update more projections * fix: add beta log for postgres * revert index name change * prerelease * fix: add sequence to v1 "reduce paniced" * log if nil * add logging * fix: log output * fix(import): check if org exists and user * refactor: imports * fix(user): ignore malformed events * refactor: method naming * fix: test * refactor: correct errors.Is call * ci: don't build dev binaries on main * fix(go releaser): update version to 1.11.0 * fix(user): projection should not break * fix(user): handle error properly * docs: correct config example * Update .releaserc.js * Update .releaserc.js Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com>
2022-08-31 07:52:43 +00:00
UserGrantProjectionTable = "projections.user_grants2"
UserGrantID = "id"
UserGrantCreationDate = "creation_date"
UserGrantChangeDate = "change_date"
UserGrantSequence = "sequence"
UserGrantState = "state"
UserGrantResourceOwner = "resource_owner"
UserGrantInstanceID = "instance_id"
UserGrantUserID = "user_id"
UserGrantProjectID = "project_id"
UserGrantGrantID = "grant_id"
UserGrantRoles = "roles"
)
type userGrantProjection struct {
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
crdb.StatementHandler
}
func newUserGrantProjection(ctx context.Context, config crdb.StatementHandlerConfig) *userGrantProjection {
p := new(userGrantProjection)
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
config.ProjectionName = UserGrantProjectionTable
config.Reducers = p.reducers()
config.InitCheck = crdb.NewTableCheck(
crdb.NewTable([]*crdb.Column{
crdb.NewColumn(UserGrantID, crdb.ColumnTypeText),
crdb.NewColumn(UserGrantCreationDate, crdb.ColumnTypeTimestamp),
crdb.NewColumn(UserGrantChangeDate, crdb.ColumnTypeTimestamp),
crdb.NewColumn(UserGrantSequence, crdb.ColumnTypeInt64),
crdb.NewColumn(UserGrantState, crdb.ColumnTypeEnum),
crdb.NewColumn(UserGrantResourceOwner, crdb.ColumnTypeText),
crdb.NewColumn(UserGrantInstanceID, crdb.ColumnTypeText),
crdb.NewColumn(UserGrantUserID, crdb.ColumnTypeText),
crdb.NewColumn(UserGrantProjectID, crdb.ColumnTypeText),
crdb.NewColumn(UserGrantGrantID, crdb.ColumnTypeText),
crdb.NewColumn(UserGrantRoles, crdb.ColumnTypeTextArray, crdb.Nullable()),
},
crdb.NewPrimaryKey(UserGrantInstanceID, UserGrantID),
feat(database): support for postgres (#3998) * beginning with postgres statements * try pgx * use pgx * database * init works for postgres * arrays working * init for cockroach * init * start tests * tests * TESTS * ch * ch * chore: use go 1.18 * read stmts * fix typo * tests * connection string * add missing error handler * cleanup * start all apis * go mod tidy * old update * switch back to minute * on conflict * replace string slice with `database.StringArray` in db models * fix tests and start * update go version in dockerfile * setup go * clean up * remove notification migration * update * docs: add deploy guide for postgres * fix: revert sonyflake * use `database.StringArray` for daos * use `database.StringArray` every where * new tables * index naming, metadata primary key, project grant role key type * docs(postgres): change to beta * chore: correct compose * fix(defaults): add empty postgres config * refactor: remove unused code * docs: add postgres to self hosted * fix broken link * so? * change title * add mdx to link * fix stmt * update goreleaser in test-code * docs: improve postgres example * update more projections * fix: add beta log for postgres * revert index name change * prerelease * fix: add sequence to v1 "reduce paniced" * log if nil * add logging * fix: log output * fix(import): check if org exists and user * refactor: imports * fix(user): ignore malformed events * refactor: method naming * fix: test * refactor: correct errors.Is call * ci: don't build dev binaries on main * fix(go releaser): update version to 1.11.0 * fix(user): projection should not break * fix(user): handle error properly * docs: correct config example * Update .releaserc.js * Update .releaserc.js Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com>
2022-08-31 07:52:43 +00:00
crdb.WithIndex(crdb.NewIndex("user_grant_user_idx", []string{UserGrantUserID})),
crdb.WithIndex(crdb.NewIndex("user_grant_ro_idx", []string{UserGrantResourceOwner})),
),
)
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
return p
}
func (p *userGrantProjection) reducers() []handler.AggregateReducer {
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
return []handler.AggregateReducer{
{
Aggregate: usergrant.AggregateType,
EventRedusers: []handler.EventReducer{
{
Event: usergrant.UserGrantAddedType,
Reduce: p.reduceAdded,
},
{
Event: usergrant.UserGrantChangedType,
Reduce: p.reduceChanged,
},
{
Event: usergrant.UserGrantCascadeChangedType,
Reduce: p.reduceChanged,
},
{
Event: usergrant.UserGrantRemovedType,
Reduce: p.reduceRemoved,
},
{
Event: usergrant.UserGrantCascadeRemovedType,
Reduce: p.reduceRemoved,
},
{
Event: usergrant.UserGrantDeactivatedType,
Reduce: p.reduceDeactivated,
},
{
Event: usergrant.UserGrantReactivatedType,
Reduce: p.reduceReactivated,
},
},
},
{
Aggregate: user.AggregateType,
EventRedusers: []handler.EventReducer{
{
Event: user.UserRemovedType,
Reduce: p.reduceUserRemoved,
},
},
},
{
Aggregate: project.AggregateType,
EventRedusers: []handler.EventReducer{
{
Event: project.ProjectRemovedType,
Reduce: p.reduceProjectRemoved,
},
{
Event: project.GrantRemovedType,
Reduce: p.reduceProjectGrantRemoved,
},
{
Event: project.RoleRemovedType,
Reduce: p.reduceRoleRemoved,
},
{
Event: project.GrantChangedType,
Reduce: p.reduceProjectGrantChanged,
},
{
Event: project.GrantCascadeChangedType,
Reduce: p.reduceProjectGrantChanged,
},
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
},
},
}
}
func (p *userGrantProjection) reduceAdded(event eventstore.Event) (*handler.Statement, error) {
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
e, ok := event.(*usergrant.UserGrantAddedEvent)
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-MQHVB", "reduce.wrong.event.type %s", usergrant.UserGrantAddedType)
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
}
return crdb.NewCreateStatement(
e,
[]handler.Column{
handler.NewCol(UserGrantID, e.Aggregate().ID),
handler.NewCol(UserGrantResourceOwner, e.Aggregate().ResourceOwner),
handler.NewCol(UserGrantInstanceID, e.Aggregate().InstanceID),
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
handler.NewCol(UserGrantCreationDate, e.CreationDate()),
handler.NewCol(UserGrantChangeDate, e.CreationDate()),
handler.NewCol(UserGrantSequence, e.Sequence()),
handler.NewCol(UserGrantUserID, e.UserID),
handler.NewCol(UserGrantProjectID, e.ProjectID),
handler.NewCol(UserGrantGrantID, e.ProjectGrantID),
feat(database): support for postgres (#3998) * beginning with postgres statements * try pgx * use pgx * database * init works for postgres * arrays working * init for cockroach * init * start tests * tests * TESTS * ch * ch * chore: use go 1.18 * read stmts * fix typo * tests * connection string * add missing error handler * cleanup * start all apis * go mod tidy * old update * switch back to minute * on conflict * replace string slice with `database.StringArray` in db models * fix tests and start * update go version in dockerfile * setup go * clean up * remove notification migration * update * docs: add deploy guide for postgres * fix: revert sonyflake * use `database.StringArray` for daos * use `database.StringArray` every where * new tables * index naming, metadata primary key, project grant role key type * docs(postgres): change to beta * chore: correct compose * fix(defaults): add empty postgres config * refactor: remove unused code * docs: add postgres to self hosted * fix broken link * so? * change title * add mdx to link * fix stmt * update goreleaser in test-code * docs: improve postgres example * update more projections * fix: add beta log for postgres * revert index name change * prerelease * fix: add sequence to v1 "reduce paniced" * log if nil * add logging * fix: log output * fix(import): check if org exists and user * refactor: imports * fix(user): ignore malformed events * refactor: method naming * fix: test * refactor: correct errors.Is call * ci: don't build dev binaries on main * fix(go releaser): update version to 1.11.0 * fix(user): projection should not break * fix(user): handle error properly * docs: correct config example * Update .releaserc.js * Update .releaserc.js Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com>
2022-08-31 07:52:43 +00:00
handler.NewCol(UserGrantRoles, database.StringArray(e.RoleKeys)),
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
handler.NewCol(UserGrantState, domain.UserGrantStateActive),
},
), nil
}
func (p *userGrantProjection) reduceChanged(event eventstore.Event) (*handler.Statement, error) {
feat(database): support for postgres (#3998) * beginning with postgres statements * try pgx * use pgx * database * init works for postgres * arrays working * init for cockroach * init * start tests * tests * TESTS * ch * ch * chore: use go 1.18 * read stmts * fix typo * tests * connection string * add missing error handler * cleanup * start all apis * go mod tidy * old update * switch back to minute * on conflict * replace string slice with `database.StringArray` in db models * fix tests and start * update go version in dockerfile * setup go * clean up * remove notification migration * update * docs: add deploy guide for postgres * fix: revert sonyflake * use `database.StringArray` for daos * use `database.StringArray` every where * new tables * index naming, metadata primary key, project grant role key type * docs(postgres): change to beta * chore: correct compose * fix(defaults): add empty postgres config * refactor: remove unused code * docs: add postgres to self hosted * fix broken link * so? * change title * add mdx to link * fix stmt * update goreleaser in test-code * docs: improve postgres example * update more projections * fix: add beta log for postgres * revert index name change * prerelease * fix: add sequence to v1 "reduce paniced" * log if nil * add logging * fix: log output * fix(import): check if org exists and user * refactor: imports * fix(user): ignore malformed events * refactor: method naming * fix: test * refactor: correct errors.Is call * ci: don't build dev binaries on main * fix(go releaser): update version to 1.11.0 * fix(user): projection should not break * fix(user): handle error properly * docs: correct config example * Update .releaserc.js * Update .releaserc.js Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com>
2022-08-31 07:52:43 +00:00
var roles database.StringArray
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
switch e := event.(type) {
case *usergrant.UserGrantChangedEvent:
roles = e.RoleKeys
case *usergrant.UserGrantCascadeChangedEvent:
roles = e.RoleKeys
default:
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-hOr1E", "reduce.wrong.event.type %v", []eventstore.EventType{usergrant.UserGrantChangedType, usergrant.UserGrantCascadeChangedType})
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
}
return crdb.NewUpdateStatement(
event,
[]handler.Column{
handler.NewCol(UserGrantChangeDate, event.CreationDate()),
handler.NewCol(UserGrantRoles, roles),
handler.NewCol(UserGrantSequence, event.Sequence()),
},
[]handler.Condition{
handler.NewCond(UserGrantID, event.Aggregate().ID),
},
), nil
}
func (p *userGrantProjection) reduceRemoved(event eventstore.Event) (*handler.Statement, error) {
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
switch event.(type) {
case *usergrant.UserGrantRemovedEvent, *usergrant.UserGrantCascadeRemovedEvent:
// ok
default:
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-7OBEC", "reduce.wrong.event.type %v", []eventstore.EventType{usergrant.UserGrantRemovedType, usergrant.UserGrantCascadeRemovedType})
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
}
return crdb.NewDeleteStatement(
event,
[]handler.Condition{
handler.NewCond(UserGrantID, event.Aggregate().ID),
},
), nil
}
func (p *userGrantProjection) reduceDeactivated(event eventstore.Event) (*handler.Statement, error) {
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
if _, ok := event.(*usergrant.UserGrantDeactivatedEvent); !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-oP7Gm", "reduce.wrong.event.type %s", usergrant.UserGrantDeactivatedType)
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
}
return crdb.NewUpdateStatement(
event,
[]handler.Column{
handler.NewCol(UserGrantChangeDate, event.CreationDate()),
handler.NewCol(UserGrantState, domain.UserGrantStateInactive),
handler.NewCol(UserGrantSequence, event.Sequence()),
},
[]handler.Condition{
handler.NewCond(UserGrantID, event.Aggregate().ID),
},
), nil
}
func (p *userGrantProjection) reduceReactivated(event eventstore.Event) (*handler.Statement, error) {
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
if _, ok := event.(*usergrant.UserGrantDeactivatedEvent); !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-DGsKh", "reduce.wrong.event.type %s", usergrant.UserGrantReactivatedType)
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
}
return crdb.NewUpdateStatement(
event,
[]handler.Column{
handler.NewCol(UserGrantChangeDate, event.CreationDate()),
handler.NewCol(UserGrantState, domain.UserGrantStateActive),
handler.NewCol(UserGrantSequence, event.Sequence()),
},
[]handler.Condition{
handler.NewCond(UserGrantID, event.Aggregate().ID),
},
), nil
}
func (p *userGrantProjection) reduceUserRemoved(event eventstore.Event) (*handler.Statement, error) {
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
if _, ok := event.(*user.UserRemovedEvent); !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Bner2a", "reduce.wrong.event.type %s", user.UserRemovedType)
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
}
return crdb.NewDeleteStatement(
event,
[]handler.Condition{
handler.NewCond(UserGrantUserID, event.Aggregate().ID),
},
), nil
}
func (p *userGrantProjection) reduceProjectRemoved(event eventstore.Event) (*handler.Statement, error) {
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
if _, ok := event.(*project.ProjectRemovedEvent); !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Bne2a", "reduce.wrong.event.type %s", project.ProjectRemovedType)
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
}
return crdb.NewDeleteStatement(
event,
[]handler.Condition{
handler.NewCond(UserGrantProjectID, event.Aggregate().ID),
},
), nil
}
func (p *userGrantProjection) reduceProjectGrantRemoved(event eventstore.Event) (*handler.Statement, error) {
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
e, ok := event.(*project.GrantRemovedEvent)
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-dGr2a", "reduce.wrong.event.type %s", project.GrantRemovedType)
fix(projections): add user grant projection (#2837) * refactor(domain): add user type * fix(projections): start with login names * fix(login_policy): correct handling of user domain claimed event * fix(projections): add members * refactor: simplify member projections * add migration for members * add metadata to member projections * refactor: login name projection * fix: set correct suffixes on login name projections * test(projections): login name reduces * fix: correct cols in reduce member * test(projections): org, iam, project members * member additional cols and conds as opt, add project grant members * fix(migration): members * fix(migration): correct database name * migration version * migs * better naming for member cond and col * split project and project grant members * prepare member columns * feat(queries): membership query * test(queries): membership prepare * fix(queries): multiple projections for latest sequence * fix(api): use query for membership queries in auth and management * feat: org member queries * fix(api): use query for iam member calls * fix(queries): org members * fix(queries): project members * fix(queries): project grant members * fix(query): member queries and user avatar column * member cols * fix(queries): membership stmt * fix user test * fix user test * fix(projections): add user grant projection * fix(user_grant): handle state changes * add state to migration * merge eventstore-naming into user-grant-projection * fix(migrations): version * fix(query): event mappers for usergrant aggregate * fix(projection): correct aggregate for user grants * cleanup reducers * add tests for projection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-01-13 10:02:39 +00:00
}
return crdb.NewDeleteStatement(
event,
[]handler.Condition{
handler.NewCond(UserGrantGrantID, e.GrantID),
},
), nil
}
func (p *userGrantProjection) reduceRoleRemoved(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*project.RoleRemovedEvent)
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-dswg2", "reduce.wrong.event.type %s", project.RoleRemovedType)
}
return crdb.NewUpdateStatement(
event,
[]handler.Column{
crdb.NewArrayRemoveCol(UserGrantRoles, e.Key),
},
[]handler.Condition{
handler.NewCond(UserGrantProjectID, e.Aggregate().ID),
},
), nil
}
func (p *userGrantProjection) reduceProjectGrantChanged(event eventstore.Event) (*handler.Statement, error) {
var grantID string
var keys []string
switch e := event.(type) {
case *project.GrantChangedEvent:
grantID = e.GrantID
keys = e.RoleKeys
case *project.GrantCascadeChangedEvent:
grantID = e.GrantID
keys = e.RoleKeys
default:
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Fh3gw", "reduce.wrong.event.type %v", []eventstore.EventType{project.GrantChangedType, project.GrantCascadeChangedType})
}
return crdb.NewUpdateStatement(
event,
[]handler.Column{
feat(database): support for postgres (#3998) * beginning with postgres statements * try pgx * use pgx * database * init works for postgres * arrays working * init for cockroach * init * start tests * tests * TESTS * ch * ch * chore: use go 1.18 * read stmts * fix typo * tests * connection string * add missing error handler * cleanup * start all apis * go mod tidy * old update * switch back to minute * on conflict * replace string slice with `database.StringArray` in db models * fix tests and start * update go version in dockerfile * setup go * clean up * remove notification migration * update * docs: add deploy guide for postgres * fix: revert sonyflake * use `database.StringArray` for daos * use `database.StringArray` every where * new tables * index naming, metadata primary key, project grant role key type * docs(postgres): change to beta * chore: correct compose * fix(defaults): add empty postgres config * refactor: remove unused code * docs: add postgres to self hosted * fix broken link * so? * change title * add mdx to link * fix stmt * update goreleaser in test-code * docs: improve postgres example * update more projections * fix: add beta log for postgres * revert index name change * prerelease * fix: add sequence to v1 "reduce paniced" * log if nil * add logging * fix: log output * fix(import): check if org exists and user * refactor: imports * fix(user): ignore malformed events * refactor: method naming * fix: test * refactor: correct errors.Is call * ci: don't build dev binaries on main * fix(go releaser): update version to 1.11.0 * fix(user): projection should not break * fix(user): handle error properly * docs: correct config example * Update .releaserc.js * Update .releaserc.js Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com>
2022-08-31 07:52:43 +00:00
crdb.NewArrayIntersectCol(UserGrantRoles, database.StringArray(keys)),
},
[]handler.Condition{
handler.NewCond(UserGrantGrantID, grantID),
},
), nil
}