mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-02 08:58:52 +00:00
feat(rt): project grants (#10951)
This pull request introduces a new feature that allows adding, updating, and querying project grants The changes are primarily in the backend and include new database tables, repositories, and domain logic to support project grants. ## Changes * New `project_grants` table: A new table `zitadel.project_grants` is introduced to store project grants It includes columns for `instance_id`, `id`, `state`, `project_id`, `granted_org_id` and `granting_org_id`. * New `ProjectGrantRepository`: A new repository `ProjectGrantRepository` is created to handle all database operations for project grants. It provides methods to `Get`, `List`, `Create`, `Update`, and `Delete`. * New `project_grant_roles` table: A new table `zitadel.project_grant_roles` is introduced to store project grant roles It includes columns for `instance_id`, `grant_id`, `key`, `project_id` and `project_org_id`. * New `ProjectGrantRoleRepository`: A new repository `ProjectGrantRoleRepository` is created to handle all database operations for project grant roles. It provides methods to `Get`, `List`, `Add`, and `Delete`. * New `project_grant_relational_projection`: A new projection `project_grant_relational_projection` is added to update the `zitadel.project_grants` and `zitadel.project_grant_roles` tables based on events. It handles all project grant events. * Updated `ProjectRepository`: The `ProjectRepository` is updated to list granted projects. # Additional Context Closes https://github.com/zitadel/zitadel/issues/10766 --------- Co-authored-by: Stefan Benz <[email protected]> Co-authored-by: Marco A. <[email protected]> Co-authored-by: Silvan <[email protected]>
This commit is contained in:
co-authored by
Stefan Benz
Marco A.
Silvan
parent
6051ce591d
commit
9274e008fe
@@ -65,3 +65,46 @@ func getMany[Target any](ctx context.Context, querier database.Querier, builder
|
||||
}
|
||||
return targets, nil
|
||||
}
|
||||
|
||||
type updatable interface {
|
||||
PrimaryKeyColumns() []database.Column
|
||||
UpdatedAtColumn() database.Column
|
||||
qualifiedTableName() string
|
||||
}
|
||||
|
||||
func updateOne[Target updatable](ctx context.Context, client database.QueryExecutor, target Target, condition database.Condition, changes ...database.Change) (int64, error) {
|
||||
if len(changes) == 0 {
|
||||
return 0, database.ErrNoChanges
|
||||
}
|
||||
if err := checkPKCondition(target, condition); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if !database.Changes(changes).IsOnColumn(target.UpdatedAtColumn()) {
|
||||
changes = append(changes, database.NewChange(target.UpdatedAtColumn(), database.NullInstruction))
|
||||
}
|
||||
builder := database.NewStatementBuilder("UPDATE ")
|
||||
builder.WriteString(target.qualifiedTableName())
|
||||
builder.WriteString(" SET ")
|
||||
database.Changes(changes).Write(builder)
|
||||
writeCondition(builder, condition)
|
||||
|
||||
return client.Exec(ctx, builder.String(), builder.Args()...)
|
||||
}
|
||||
|
||||
type deletable interface {
|
||||
PrimaryKeyColumns() []database.Column
|
||||
qualifiedTableName() string
|
||||
}
|
||||
|
||||
func deleteOne[Target deletable](ctx context.Context, client database.QueryExecutor, target Target, condition database.Condition) (int64, error) {
|
||||
if err := checkPKCondition(target, condition); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
builder := database.NewStatementBuilder("DELETE FROM ")
|
||||
builder.WriteString(target.qualifiedTableName())
|
||||
builder.WriteRune(' ')
|
||||
writeCondition(builder, condition)
|
||||
|
||||
return client.Exec(ctx, builder.String(), builder.Args()...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user