mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +00:00
feat: remove org (#4148)
* feat(command): remove org * refactor: imports, unused code, error handling * reduce org removed in action * add org deletion to projections * add org removal to projections * add org removal to projections * org removed projection * lint import * projections * fix: table names in tests * fix: table names in tests * logging * add org state * fix(domain): add Owner removed to object details * feat(ListQuery): add with owner removed * fix(org-delete): add bool to functions to select with owner removed * fix(org-delete): add bools to user grants with events to determine if dependencies lost owner * fix(org-delete): add unit tests for owner removed and org removed events * fix(org-delete): add handling of org remove for grants and members * fix(org-delete): correction of unit tests for owner removed * fix(org-delete): update projections, unit tests and get functions * fix(org-delete): add change date to authnkeys and owner removed to org metadata * fix(org-delete): include owner removed for login names * fix(org-delete): some column fixes in projections and build for queries with owner removed * indexes * fix(org-delete): include review changes * fix(org-delete): change user projection name after merge * fix(org-delete): include review changes for project grant where no project owner is necessary * fix(org-delete): include auth and adminapi tables with owner removed information * fix(org-delete): cleanup username and orgdomain uniqueconstraints when org is removed * fix(org-delete): add permissions for org.remove * remove unnecessary unique constraints * fix column order in primary keys * fix(org-delete): include review changes * fix(org-delete): add owner removed indexes and chang setup step to create tables * fix(org-delete): move PK order of instance_id and change added user_grant from review * fix(org-delete): no params for prepareUserQuery * change to step 6 * merge main * fix(org-delete): OldUserName rename to private * fix linting * cleanup * fix: remove org test * create prerelease * chore: delete org-delete as prerelease Co-authored-by: Stefan Benz <stefan@caos.ch> Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Fabi <38692350+hifabienne@users.noreply.github.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
This commit is contained in:
@@ -28,14 +28,15 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.authn_keys`),
|
||||
` FROM projections.authn_keys2`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -47,17 +48,19 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.authn_keys`),
|
||||
` FROM projections.authn_keys2`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"sequence",
|
||||
"expiration",
|
||||
@@ -68,6 +71,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
"id",
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
@@ -84,6 +88,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
ID: "id",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "ro",
|
||||
Sequence: 20211109,
|
||||
Expiration: testNow,
|
||||
@@ -97,17 +102,19 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.authn_keys`),
|
||||
` FROM projections.authn_keys2`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"sequence",
|
||||
"expiration",
|
||||
@@ -118,6 +125,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
"id-1",
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
@@ -126,6 +134,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
"id-2",
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
@@ -142,6 +151,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
ID: "id-1",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "ro",
|
||||
Sequence: 20211109,
|
||||
Expiration: testNow,
|
||||
@@ -150,6 +160,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
ID: "id-2",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "ro",
|
||||
Sequence: 20211109,
|
||||
Expiration: testNow,
|
||||
@@ -163,14 +174,15 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.authn_keys`),
|
||||
` FROM projections.authn_keys2`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -187,16 +199,17 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysDataQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
` projections.authn_keys.identifier,`+
|
||||
` projections.authn_keys.public_key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type,`+
|
||||
` projections.authn_keys2.identifier,`+
|
||||
` projections.authn_keys2.public_key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.authn_keys`),
|
||||
` FROM projections.authn_keys2`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -208,19 +221,21 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysDataQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
` projections.authn_keys.identifier,`+
|
||||
` projections.authn_keys.public_key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type,`+
|
||||
` projections.authn_keys2.identifier,`+
|
||||
` projections.authn_keys2.public_key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.authn_keys`),
|
||||
` FROM projections.authn_keys2`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"sequence",
|
||||
"expiration",
|
||||
@@ -233,6 +248,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
"id",
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
@@ -251,6 +267,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
ID: "id",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "ro",
|
||||
Sequence: 20211109,
|
||||
Expiration: testNow,
|
||||
@@ -266,19 +283,21 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysDataQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
` projections.authn_keys.identifier,`+
|
||||
` projections.authn_keys.public_key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type,`+
|
||||
` projections.authn_keys2.identifier,`+
|
||||
` projections.authn_keys2.public_key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.authn_keys`),
|
||||
` FROM projections.authn_keys2`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"sequence",
|
||||
"expiration",
|
||||
@@ -291,6 +310,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
"id-1",
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
@@ -301,6 +321,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
"id-2",
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
@@ -319,6 +340,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
ID: "id-1",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "ro",
|
||||
Sequence: 20211109,
|
||||
Expiration: testNow,
|
||||
@@ -329,6 +351,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
{
|
||||
ID: "id-2",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "ro",
|
||||
Sequence: 20211109,
|
||||
Expiration: testNow,
|
||||
@@ -344,16 +367,17 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeysDataQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type,`+
|
||||
` projections.authn_keys.identifier,`+
|
||||
` projections.authn_keys.public_key,`+
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type,`+
|
||||
` projections.authn_keys2.identifier,`+
|
||||
` projections.authn_keys2.public_key,`+
|
||||
` COUNT(*) OVER ()`+
|
||||
` FROM projections.authn_keys`),
|
||||
` FROM projections.authn_keys2`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -370,13 +394,14 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type`+
|
||||
` FROM projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type`+
|
||||
` FROM projections.authn_keys2`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -394,16 +419,18 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type`+
|
||||
` FROM projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type`+
|
||||
` FROM projections.authn_keys2`),
|
||||
[]string{
|
||||
"id",
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"resource_owner",
|
||||
"sequence",
|
||||
"expiration",
|
||||
@@ -412,6 +439,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
[]driver.Value{
|
||||
"id",
|
||||
testNow,
|
||||
testNow,
|
||||
"ro",
|
||||
uint64(20211109),
|
||||
testNow,
|
||||
@@ -422,6 +450,7 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
object: &AuthNKey{
|
||||
ID: "id",
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
ResourceOwner: "ro",
|
||||
Sequence: 20211109,
|
||||
Expiration: testNow,
|
||||
@@ -433,13 +462,14 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.id,`+
|
||||
` projections.authn_keys.creation_date,`+
|
||||
` projections.authn_keys.resource_owner,`+
|
||||
` projections.authn_keys.sequence,`+
|
||||
` projections.authn_keys.expiration,`+
|
||||
` projections.authn_keys.type`+
|
||||
` FROM projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.id,`+
|
||||
` projections.authn_keys2.creation_date,`+
|
||||
` projections.authn_keys2.change_date,`+
|
||||
` projections.authn_keys2.resource_owner,`+
|
||||
` projections.authn_keys2.sequence,`+
|
||||
` projections.authn_keys2.expiration,`+
|
||||
` projections.authn_keys2.type`+
|
||||
` FROM projections.authn_keys2`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
@@ -456,8 +486,8 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyPublicKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueries(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.public_key`+
|
||||
` FROM projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.public_key`+
|
||||
` FROM projections.authn_keys2`),
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
@@ -475,8 +505,8 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyPublicKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQuery(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.public_key`+
|
||||
` FROM projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.public_key`+
|
||||
` FROM projections.authn_keys2`),
|
||||
[]string{
|
||||
"public_key",
|
||||
},
|
||||
@@ -492,8 +522,8 @@ func Test_AuthNKeyPrepares(t *testing.T) {
|
||||
prepare: prepareAuthNKeyPublicKeyQuery,
|
||||
want: want{
|
||||
sqlExpectations: mockQueryErr(
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys.public_key`+
|
||||
` FROM projections.authn_keys`),
|
||||
regexp.QuoteMeta(`SELECT projections.authn_keys2.public_key`+
|
||||
` FROM projections.authn_keys2`),
|
||||
sql.ErrConnDone,
|
||||
),
|
||||
err: func(err error) (error, bool) {
|
||||
|
Reference in New Issue
Block a user