fix: cascading changes for usergrants when managing projects / projectgrants (#3035)

This commit is contained in:
Livio Amstutz
2022-01-20 08:33:51 +01:00
committed by GitHub
parent eaaf76a6eb
commit 24aef8d16e
5 changed files with 161 additions and 5 deletions

View File

@@ -4,6 +4,8 @@ import (
"strconv"
"strings"
"github.com/lib/pq"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/handler"
@@ -201,6 +203,25 @@ func NewArrayRemoveCol(column string, value interface{}) handler.Column {
}
}
func NewArrayIntersectCol(column string, value interface{}) handler.Column {
var arrayType string
switch value.(type) {
case pq.StringArray:
arrayType = "STRING"
case pq.Int32Array,
pq.Int64Array:
arrayType = "INT"
//TODO: handle more types if necessary
}
return handler.Column{
Name: column,
Value: value,
ParameterOpt: func(placeholder string) string {
return "SELECT ARRAY( SELECT UNNEST(" + column + ") INTERSECT SELECT UNNEST (" + placeholder + "::" + arrayType + "[]))"
},
}
}
//NewCopyStatement creates a new upsert statement which updates a column from an existing row
// cols represent the columns which are objective to change.
// if the value of a col is empty the data will be copied from the selected row