Commit d9315938 authored by Małgorzata Ksionek's avatar Małgorzata Ksionek

Change formatting of sql

Fix formatting
parent 3f7c25e9
......@@ -13,26 +13,62 @@ module Gitlab
ActiveRecord::Base.connection.execute <<~SQL
UPDATE users
SET require_two_factor_authentication_from_group = FALSE
WHERE users.id IN (#{user_ids.join(',')})
AND users.require_two_factor_authentication_from_group = TRUE
AND users.id NOT IN (
SELECT users_groups_query.user_id FROM (SELECT users.id as user_id, members.source_id as group_ids FROM users
LEFT JOIN members ON members.source_type = 'Namespace'
AND members.requested_at IS NULL AND members.user_id = users.id
AND members.type = 'GroupMember'
WHERE users.require_two_factor_authentication_from_group = TRUE
AND users.id IN (#{user_ids.join(',')})
) AS users_groups_query
INNER JOIN LATERAL (
WITH RECURSIVE "base_and_ancestors" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = users_groups_query.group_ids)
UNION
(SELECT "namespaces".* FROM "namespaces", "base_and_ancestors" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = "base_and_ancestors"."parent_id")), "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = users_groups_query.group_ids)
UNION
(SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "namespaces".* FROM ((SELECT "namespaces".* FROM "base_and_ancestors" AS "namespaces" WHERE "namespaces"."type" = 'Group')
UNION
(SELECT "namespaces".* FROM "base_and_descendants" AS "namespaces" WHERE "namespaces"."type" = 'Group')) namespaces WHERE "namespaces"."type" = 'Group' and "namespaces".require_two_factor_authentication = true
) as hierarchy_tree ON TRUE);
SET require_two_factor_authentication_from_group = false
WHERE users.id IN (#{user_ids.join(',')})
AND users.require_two_factor_authentication_from_group = TRUE
AND users.id NOT IN
(
SELECT users_groups_query.user_id
FROM (
SELECT users.id AS user_id,
members.source_id AS group_ids
FROM users
LEFT JOIN members
ON members.source_type = 'Namespace'
AND members.requested_at IS NULL
AND members.user_id = users.id
AND members.type = 'GroupMember'
WHERE users.require_two_factor_authentication_from_group = TRUE
AND users.id IN (#{user_ids.join(',')}) ) AS users_groups_query
INNER JOIN lateral ( WITH recursive "base_and_ancestors" AS (
(
SELECT "namespaces".*
FROM "namespaces"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" = users_groups_query.group_ids)
UNION
(
SELECT "namespaces".*
FROM "namespaces",
"base_and_ancestors"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" = "base_and_ancestors"."parent_id")), "base_and_descendants" AS (
(
SELECT "namespaces".*
FROM "namespaces"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" = users_groups_query.group_ids)
UNION
(
SELECT "namespaces".*
FROM "namespaces",
"base_and_descendants"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."parent_id" = "base_and_descendants"."id"))
SELECT "namespaces".*
FROM (
(
SELECT "namespaces".*
FROM "base_and_ancestors" AS "namespaces"
WHERE "namespaces"."type" = 'Group')
UNION
(
SELECT "namespaces".*
FROM "base_and_descendants" AS "namespaces"
WHERE "namespaces"."type" = 'Group')) namespaces
WHERE "namespaces"."type" = 'Group'
AND "namespaces".require_two_factor_authentication = TRUE ) AS hierarchy_tree
ON TRUE);
SQL
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment