mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:57:31 +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:
@@ -17,45 +17,47 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
userQuery = `SELECT projections.users5.id,` +
|
||||
` projections.users5.creation_date,` +
|
||||
` projections.users5.change_date,` +
|
||||
` projections.users5.resource_owner,` +
|
||||
` projections.users5.sequence,` +
|
||||
` projections.users5.state,` +
|
||||
` projections.users5.type,` +
|
||||
` projections.users5.username,` +
|
||||
loginNamesQuery = `SELECT login_names.user_id, ARRAY_AGG(login_names.login_name)::TEXT[] AS loginnames, login_names.instance_id, login_names.user_owner_removed, login_names.policy_owner_removed, login_names.domain_owner_removed` +
|
||||
` FROM projections.login_names2 AS login_names` +
|
||||
` GROUP BY login_names.user_id, login_names.instance_id, login_names.user_owner_removed, login_names.policy_owner_removed, login_names.domain_owner_removed`
|
||||
preferredLoginNameQuery = `SELECT preferred_login_name.user_id, preferred_login_name.login_name, preferred_login_name.instance_id, preferred_login_name.user_owner_removed, preferred_login_name.policy_owner_removed, preferred_login_name.domain_owner_removed` +
|
||||
` FROM projections.login_names2 AS preferred_login_name` +
|
||||
` WHERE preferred_login_name.is_primary = $1`
|
||||
userQuery = `SELECT projections.users6.id,` +
|
||||
` projections.users6.creation_date,` +
|
||||
` projections.users6.change_date,` +
|
||||
` projections.users6.resource_owner,` +
|
||||
` projections.users6.sequence,` +
|
||||
` projections.users6.state,` +
|
||||
` projections.users6.type,` +
|
||||
` projections.users6.username,` +
|
||||
` login_names.loginnames,` +
|
||||
` preferred_login_name.login_name,` +
|
||||
` projections.users5_humans.user_id,` +
|
||||
` projections.users5_humans.first_name,` +
|
||||
` projections.users5_humans.last_name,` +
|
||||
` projections.users5_humans.nick_name,` +
|
||||
` projections.users5_humans.display_name,` +
|
||||
` projections.users5_humans.preferred_language,` +
|
||||
` projections.users5_humans.gender,` +
|
||||
` projections.users5_humans.avatar_key,` +
|
||||
` projections.users5_humans.email,` +
|
||||
` projections.users5_humans.is_email_verified,` +
|
||||
` projections.users5_humans.phone,` +
|
||||
` projections.users5_humans.is_phone_verified,` +
|
||||
` projections.users5_machines.user_id,` +
|
||||
` projections.users5_machines.name,` +
|
||||
` projections.users5_machines.description,` +
|
||||
` projections.users6_humans.user_id,` +
|
||||
` projections.users6_humans.first_name,` +
|
||||
` projections.users6_humans.last_name,` +
|
||||
` projections.users6_humans.nick_name,` +
|
||||
` projections.users6_humans.display_name,` +
|
||||
` projections.users6_humans.preferred_language,` +
|
||||
` projections.users6_humans.gender,` +
|
||||
` projections.users6_humans.avatar_key,` +
|
||||
` projections.users6_humans.email,` +
|
||||
` projections.users6_humans.is_email_verified,` +
|
||||
` projections.users6_humans.phone,` +
|
||||
` projections.users6_humans.is_phone_verified,` +
|
||||
` projections.users6_machines.user_id,` +
|
||||
` projections.users6_machines.name,` +
|
||||
` projections.users6_machines.description,` +
|
||||
` COUNT(*) OVER ()` +
|
||||
` FROM projections.users5` +
|
||||
` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` +
|
||||
` LEFT JOIN projections.users5_machines ON projections.users5.id = projections.users5_machines.user_id AND projections.users5.instance_id = projections.users5_machines.instance_id` +
|
||||
` FROM projections.users6` +
|
||||
` LEFT JOIN projections.users6_humans ON projections.users6.id = projections.users6_humans.user_id AND projections.users6.instance_id = projections.users6_humans.instance_id` +
|
||||
` LEFT JOIN projections.users6_machines ON projections.users6.id = projections.users6_machines.user_id AND projections.users6.instance_id = projections.users6_machines.instance_id` +
|
||||
` LEFT JOIN` +
|
||||
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) AS loginnames, login_names.instance_id` +
|
||||
` FROM projections.login_names AS login_names` +
|
||||
` GROUP BY login_names.user_id, login_names.instance_id) AS login_names` +
|
||||
` ON login_names.user_id = projections.users5.id AND login_names.instance_id = projections.users5.instance_id` +
|
||||
` (` + loginNamesQuery + `) AS login_names` +
|
||||
` ON login_names.user_id = projections.users6.id AND login_names.instance_id = projections.users6.instance_id` +
|
||||
` LEFT JOIN` +
|
||||
` (SELECT preferred_login_name.user_id, preferred_login_name.login_name, preferred_login_name.instance_id` +
|
||||
` FROM projections.login_names AS preferred_login_name` +
|
||||
` WHERE preferred_login_name.is_primary = $1) AS preferred_login_name` +
|
||||
` ON preferred_login_name.user_id = projections.users5.id AND preferred_login_name.instance_id = projections.users5.instance_id`
|
||||
` (` + preferredLoginNameQuery + `) AS preferred_login_name` +
|
||||
` ON preferred_login_name.user_id = projections.users6.id AND preferred_login_name.instance_id = projections.users6.instance_id`
|
||||
userCols = []string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -86,21 +88,21 @@ var (
|
||||
"description",
|
||||
"count",
|
||||
}
|
||||
profileQuery = `SELECT projections.users5.id,` +
|
||||
` projections.users5.creation_date,` +
|
||||
` projections.users5.change_date,` +
|
||||
` projections.users5.resource_owner,` +
|
||||
` projections.users5.sequence,` +
|
||||
` projections.users5_humans.user_id,` +
|
||||
` projections.users5_humans.first_name,` +
|
||||
` projections.users5_humans.last_name,` +
|
||||
` projections.users5_humans.nick_name,` +
|
||||
` projections.users5_humans.display_name,` +
|
||||
` projections.users5_humans.preferred_language,` +
|
||||
` projections.users5_humans.gender,` +
|
||||
` projections.users5_humans.avatar_key` +
|
||||
` FROM projections.users5` +
|
||||
` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id`
|
||||
profileQuery = `SELECT projections.users6.id,` +
|
||||
` projections.users6.creation_date,` +
|
||||
` projections.users6.change_date,` +
|
||||
` projections.users6.resource_owner,` +
|
||||
` projections.users6.sequence,` +
|
||||
` projections.users6_humans.user_id,` +
|
||||
` projections.users6_humans.first_name,` +
|
||||
` projections.users6_humans.last_name,` +
|
||||
` projections.users6_humans.nick_name,` +
|
||||
` projections.users6_humans.display_name,` +
|
||||
` projections.users6_humans.preferred_language,` +
|
||||
` projections.users6_humans.gender,` +
|
||||
` projections.users6_humans.avatar_key` +
|
||||
` FROM projections.users6` +
|
||||
` LEFT JOIN projections.users6_humans ON projections.users6.id = projections.users6_humans.user_id AND projections.users6.instance_id = projections.users6_humans.instance_id`
|
||||
profileCols = []string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -116,16 +118,16 @@ var (
|
||||
"gender",
|
||||
"avatar_key",
|
||||
}
|
||||
emailQuery = `SELECT projections.users5.id,` +
|
||||
` projections.users5.creation_date,` +
|
||||
` projections.users5.change_date,` +
|
||||
` projections.users5.resource_owner,` +
|
||||
` projections.users5.sequence,` +
|
||||
` projections.users5_humans.user_id,` +
|
||||
` projections.users5_humans.email,` +
|
||||
` projections.users5_humans.is_email_verified` +
|
||||
` FROM projections.users5` +
|
||||
` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id`
|
||||
emailQuery = `SELECT projections.users6.id,` +
|
||||
` projections.users6.creation_date,` +
|
||||
` projections.users6.change_date,` +
|
||||
` projections.users6.resource_owner,` +
|
||||
` projections.users6.sequence,` +
|
||||
` projections.users6_humans.user_id,` +
|
||||
` projections.users6_humans.email,` +
|
||||
` projections.users6_humans.is_email_verified` +
|
||||
` FROM projections.users6` +
|
||||
` LEFT JOIN projections.users6_humans ON projections.users6.id = projections.users6_humans.user_id AND projections.users6.instance_id = projections.users6_humans.instance_id`
|
||||
emailCols = []string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -136,16 +138,16 @@ var (
|
||||
"email",
|
||||
"is_email_verified",
|
||||
}
|
||||
phoneQuery = `SELECT projections.users5.id,` +
|
||||
` projections.users5.creation_date,` +
|
||||
` projections.users5.change_date,` +
|
||||
` projections.users5.resource_owner,` +
|
||||
` projections.users5.sequence,` +
|
||||
` projections.users5_humans.user_id,` +
|
||||
` projections.users5_humans.phone,` +
|
||||
` projections.users5_humans.is_phone_verified` +
|
||||
` FROM projections.users5` +
|
||||
` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id`
|
||||
phoneQuery = `SELECT projections.users6.id,` +
|
||||
` projections.users6.creation_date,` +
|
||||
` projections.users6.change_date,` +
|
||||
` projections.users6.resource_owner,` +
|
||||
` projections.users6.sequence,` +
|
||||
` projections.users6_humans.user_id,` +
|
||||
` projections.users6_humans.phone,` +
|
||||
` projections.users6_humans.is_phone_verified` +
|
||||
` FROM projections.users6` +
|
||||
` LEFT JOIN projections.users6_humans ON projections.users6.id = projections.users6_humans.user_id AND projections.users6.instance_id = projections.users6_humans.instance_id`
|
||||
phoneCols = []string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -156,14 +158,14 @@ var (
|
||||
"phone",
|
||||
"is_phone_verified",
|
||||
}
|
||||
userUniqueQuery = `SELECT projections.users5.id,` +
|
||||
` projections.users5.state,` +
|
||||
` projections.users5.username,` +
|
||||
` projections.users5_humans.user_id,` +
|
||||
` projections.users5_humans.email,` +
|
||||
` projections.users5_humans.is_email_verified` +
|
||||
` FROM projections.users5` +
|
||||
` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id`
|
||||
userUniqueQuery = `SELECT projections.users6.id,` +
|
||||
` projections.users6.state,` +
|
||||
` projections.users6.username,` +
|
||||
` projections.users6_humans.user_id,` +
|
||||
` projections.users6_humans.email,` +
|
||||
` projections.users6_humans.is_email_verified` +
|
||||
` FROM projections.users6` +
|
||||
` LEFT JOIN projections.users6_humans ON projections.users6.id = projections.users6_humans.user_id AND projections.users6.instance_id = projections.users6_humans.instance_id`
|
||||
userUniqueCols = []string{
|
||||
"id",
|
||||
"state",
|
||||
@@ -172,44 +174,40 @@ var (
|
||||
"email",
|
||||
"is_email_verified",
|
||||
}
|
||||
notifyUserQuery = `SELECT projections.users5.id,` +
|
||||
` projections.users5.creation_date,` +
|
||||
` projections.users5.change_date,` +
|
||||
` projections.users5.resource_owner,` +
|
||||
` projections.users5.sequence,` +
|
||||
` projections.users5.state,` +
|
||||
` projections.users5.type,` +
|
||||
` projections.users5.username,` +
|
||||
notifyUserQuery = `SELECT projections.users6.id,` +
|
||||
` projections.users6.creation_date,` +
|
||||
` projections.users6.change_date,` +
|
||||
` projections.users6.resource_owner,` +
|
||||
` projections.users6.sequence,` +
|
||||
` projections.users6.state,` +
|
||||
` projections.users6.type,` +
|
||||
` projections.users6.username,` +
|
||||
` login_names.loginnames,` +
|
||||
` preferred_login_name.login_name,` +
|
||||
` projections.users5_humans.user_id,` +
|
||||
` projections.users5_humans.first_name,` +
|
||||
` projections.users5_humans.last_name,` +
|
||||
` projections.users5_humans.nick_name,` +
|
||||
` projections.users5_humans.display_name,` +
|
||||
` projections.users5_humans.preferred_language,` +
|
||||
` projections.users5_humans.gender,` +
|
||||
` projections.users5_humans.avatar_key,` +
|
||||
` projections.users5_notifications.user_id,` +
|
||||
` projections.users5_notifications.last_email,` +
|
||||
` projections.users5_notifications.verified_email,` +
|
||||
` projections.users5_notifications.last_phone,` +
|
||||
` projections.users5_notifications.verified_phone,` +
|
||||
` projections.users5_notifications.password_set,` +
|
||||
` projections.users6_humans.user_id,` +
|
||||
` projections.users6_humans.first_name,` +
|
||||
` projections.users6_humans.last_name,` +
|
||||
` projections.users6_humans.nick_name,` +
|
||||
` projections.users6_humans.display_name,` +
|
||||
` projections.users6_humans.preferred_language,` +
|
||||
` projections.users6_humans.gender,` +
|
||||
` projections.users6_humans.avatar_key,` +
|
||||
` projections.users6_notifications.user_id,` +
|
||||
` projections.users6_notifications.last_email,` +
|
||||
` projections.users6_notifications.verified_email,` +
|
||||
` projections.users6_notifications.last_phone,` +
|
||||
` projections.users6_notifications.verified_phone,` +
|
||||
` projections.users6_notifications.password_set,` +
|
||||
` COUNT(*) OVER ()` +
|
||||
` FROM projections.users5` +
|
||||
` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` +
|
||||
` LEFT JOIN projections.users5_notifications ON projections.users5.id = projections.users5_notifications.user_id AND projections.users5.instance_id = projections.users5_notifications.instance_id` +
|
||||
` FROM projections.users6` +
|
||||
` LEFT JOIN projections.users6_humans ON projections.users6.id = projections.users6_humans.user_id AND projections.users6.instance_id = projections.users6_humans.instance_id` +
|
||||
` LEFT JOIN projections.users6_notifications ON projections.users6.id = projections.users6_notifications.user_id AND projections.users6.instance_id = projections.users6_notifications.instance_id` +
|
||||
` LEFT JOIN` +
|
||||
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) AS loginnames, login_names.instance_id` +
|
||||
` FROM projections.login_names AS login_names` +
|
||||
` GROUP BY login_names.user_id, login_names.instance_id) AS login_names` +
|
||||
` ON login_names.user_id = projections.users5.id AND login_names.instance_id = projections.users5.instance_id` +
|
||||
` (` + loginNamesQuery + `) AS login_names` +
|
||||
` ON login_names.user_id = projections.users6.id AND login_names.instance_id = projections.users6.instance_id` +
|
||||
` LEFT JOIN` +
|
||||
` (SELECT preferred_login_name.user_id, preferred_login_name.login_name, preferred_login_name.instance_id` +
|
||||
` FROM projections.login_names AS preferred_login_name` +
|
||||
` WHERE preferred_login_name.is_primary = $1) AS preferred_login_name` +
|
||||
` ON preferred_login_name.user_id = projections.users5.id AND preferred_login_name.instance_id = projections.users5.instance_id`
|
||||
` (` + preferredLoginNameQuery + `) AS preferred_login_name` +
|
||||
` ON preferred_login_name.user_id = projections.users6.id AND preferred_login_name.instance_id = projections.users6.instance_id`
|
||||
notifyUserCols = []string{
|
||||
"id",
|
||||
"creation_date",
|
||||
@@ -239,45 +237,41 @@ var (
|
||||
"password_set",
|
||||
"count",
|
||||
}
|
||||
usersQuery = `SELECT projections.users5.id,` +
|
||||
` projections.users5.creation_date,` +
|
||||
` projections.users5.change_date,` +
|
||||
` projections.users5.resource_owner,` +
|
||||
` projections.users5.sequence,` +
|
||||
` projections.users5.state,` +
|
||||
` projections.users5.type,` +
|
||||
` projections.users5.username,` +
|
||||
usersQuery = `SELECT projections.users6.id,` +
|
||||
` projections.users6.creation_date,` +
|
||||
` projections.users6.change_date,` +
|
||||
` projections.users6.resource_owner,` +
|
||||
` projections.users6.sequence,` +
|
||||
` projections.users6.state,` +
|
||||
` projections.users6.type,` +
|
||||
` projections.users6.username,` +
|
||||
` login_names.loginnames,` +
|
||||
` preferred_login_name.login_name,` +
|
||||
` projections.users5_humans.user_id,` +
|
||||
` projections.users5_humans.first_name,` +
|
||||
` projections.users5_humans.last_name,` +
|
||||
` projections.users5_humans.nick_name,` +
|
||||
` projections.users5_humans.display_name,` +
|
||||
` projections.users5_humans.preferred_language,` +
|
||||
` projections.users5_humans.gender,` +
|
||||
` projections.users5_humans.avatar_key,` +
|
||||
` projections.users5_humans.email,` +
|
||||
` projections.users5_humans.is_email_verified,` +
|
||||
` projections.users5_humans.phone,` +
|
||||
` projections.users5_humans.is_phone_verified,` +
|
||||
` projections.users5_machines.user_id,` +
|
||||
` projections.users5_machines.name,` +
|
||||
` projections.users5_machines.description,` +
|
||||
` projections.users6_humans.user_id,` +
|
||||
` projections.users6_humans.first_name,` +
|
||||
` projections.users6_humans.last_name,` +
|
||||
` projections.users6_humans.nick_name,` +
|
||||
` projections.users6_humans.display_name,` +
|
||||
` projections.users6_humans.preferred_language,` +
|
||||
` projections.users6_humans.gender,` +
|
||||
` projections.users6_humans.avatar_key,` +
|
||||
` projections.users6_humans.email,` +
|
||||
` projections.users6_humans.is_email_verified,` +
|
||||
` projections.users6_humans.phone,` +
|
||||
` projections.users6_humans.is_phone_verified,` +
|
||||
` projections.users6_machines.user_id,` +
|
||||
` projections.users6_machines.name,` +
|
||||
` projections.users6_machines.description,` +
|
||||
` COUNT(*) OVER ()` +
|
||||
` FROM projections.users5` +
|
||||
` LEFT JOIN projections.users5_humans ON projections.users5.id = projections.users5_humans.user_id AND projections.users5.instance_id = projections.users5_humans.instance_id` +
|
||||
` LEFT JOIN projections.users5_machines ON projections.users5.id = projections.users5_machines.user_id AND projections.users5.instance_id = projections.users5_machines.instance_id` +
|
||||
` FROM projections.users6` +
|
||||
` LEFT JOIN projections.users6_humans ON projections.users6.id = projections.users6_humans.user_id AND projections.users6.instance_id = projections.users6_humans.instance_id` +
|
||||
` LEFT JOIN projections.users6_machines ON projections.users6.id = projections.users6_machines.user_id AND projections.users6.instance_id = projections.users6_machines.instance_id` +
|
||||
` LEFT JOIN` +
|
||||
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) AS loginnames, login_names.instance_id` +
|
||||
` FROM projections.login_names AS login_names` +
|
||||
` GROUP BY login_names.user_id, login_names.instance_id) AS login_names` +
|
||||
` ON login_names.user_id = projections.users5.id AND login_names.instance_id = projections.users5.instance_id` +
|
||||
` (` + loginNamesQuery + `) AS login_names` +
|
||||
` ON login_names.user_id = projections.users6.id AND login_names.instance_id = projections.users6.instance_id` +
|
||||
` LEFT JOIN` +
|
||||
` (SELECT preferred_login_name.user_id, preferred_login_name.login_name, preferred_login_name.instance_id` +
|
||||
` FROM projections.login_names AS preferred_login_name` +
|
||||
` WHERE preferred_login_name.is_primary = $1) AS preferred_login_name` +
|
||||
` ON preferred_login_name.user_id = projections.users5.id AND preferred_login_name.instance_id = projections.users5.instance_id`
|
||||
` (` + preferredLoginNameQuery + `) AS preferred_login_name` +
|
||||
` ON preferred_login_name.user_id = projections.users6.id AND preferred_login_name.instance_id = projections.users6.instance_id`
|
||||
usersCols = []string{
|
||||
"id",
|
||||
"creation_date",
|
||||
|
Reference in New Issue
Block a user