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

Add cr remarks

parent d9315938
...@@ -9,66 +9,104 @@ module Gitlab ...@@ -9,66 +9,104 @@ module Gitlab
end end
def perform(start_id, stop_id) def perform(start_id, stop_id)
user_ids = User.where(id: start_id..stop_id).where(require_two_factor_authentication_from_group: true).pluck(:id)
ActiveRecord::Base.connection.execute <<~SQL ActiveRecord::Base.connection.execute <<~SQL
UPDATE users UPDATE
SET require_two_factor_authentication_from_group = false users
WHERE users.id IN (#{user_ids.join(',')}) SET
require_two_factor_authentication_from_group = FALSE
WHERE
users.id BETWEEN #{start_id}
AND #{stop_id}
AND users.require_two_factor_authentication_from_group = TRUE AND users.require_two_factor_authentication_from_group = TRUE
AND users.id NOT IN AND users.id NOT IN ( SELECT DISTINCT
( users_groups_query.user_id
SELECT users_groups_query.user_id
FROM ( FROM (
SELECT users.id AS user_id, SELECT
users.id AS user_id,
members.source_id AS group_ids members.source_id AS group_ids
FROM users FROM
LEFT JOIN members users
ON members.source_type = 'Namespace' LEFT JOIN members ON members.source_type = 'Namespace'
AND members.requested_at IS NULL AND members.requested_at IS NULL
AND members.user_id = users.id AND members.user_id = users.id
AND members.type = 'GroupMember' AND members.type = 'GroupMember'
WHERE users.require_two_factor_authentication_from_group = TRUE WHERE
AND users.id IN (#{user_ids.join(',')}) ) AS users_groups_query users.require_two_factor_authentication_from_group = TRUE
INNER JOIN lateral ( WITH recursive "base_and_ancestors" AS ( AND users.id BETWEEN #{start_id}
AND #{stop_id}) AS users_groups_query
INNER JOIN LATERAL ( WITH RECURSIVE "base_and_ancestors" AS (
( (
SELECT "namespaces".* SELECT
FROM "namespaces" "namespaces"."type",
WHERE "namespaces"."type" = 'Group' "namespaces"."id",
"namespaces"."parent_id",
"namespaces"."require_two_factor_authentication"
FROM
"namespaces"
WHERE
"namespaces"."type" = 'Group'
AND "namespaces"."id" = users_groups_query.group_ids) AND "namespaces"."id" = users_groups_query.group_ids)
UNION UNION (
( SELECT
SELECT "namespaces".* "namespaces"."type",
FROM "namespaces", "namespaces"."id",
"namespaces"."parent_id",
"namespaces"."require_two_factor_authentication"
FROM
"namespaces",
"base_and_ancestors" "base_and_ancestors"
WHERE "namespaces"."type" = 'Group' WHERE
AND "namespaces"."id" = "base_and_ancestors"."parent_id")), "base_and_descendants" AS ( "namespaces"."type" = 'Group'
AND "namespaces"."id" = "base_and_ancestors"."parent_id")),
"base_and_descendants" AS (
( (
SELECT "namespaces".* SELECT
FROM "namespaces" "namespaces"."type",
WHERE "namespaces"."type" = 'Group' "namespaces"."id",
"namespaces"."parent_id",
"namespaces"."require_two_factor_authentication"
FROM
"namespaces"
WHERE
"namespaces"."type" = 'Group'
AND "namespaces"."id" = users_groups_query.group_ids) AND "namespaces"."id" = users_groups_query.group_ids)
UNION UNION (
( SELECT
SELECT "namespaces".* "namespaces"."type",
FROM "namespaces", "namespaces"."id",
"namespaces"."parent_id",
"namespaces"."require_two_factor_authentication"
FROM
"namespaces",
"base_and_descendants" "base_and_descendants"
WHERE "namespaces"."type" = 'Group' WHERE
"namespaces"."type" = 'Group'
AND "namespaces"."parent_id" = "base_and_descendants"."id")) AND "namespaces"."parent_id" = "base_and_descendants"."id"))
SELECT "namespaces".* SELECT
FROM ( "namespaces".*
( FROM ((
SELECT "namespaces".* SELECT
FROM "base_and_ancestors" AS "namespaces" "namespaces"."type",
WHERE "namespaces"."type" = 'Group') "namespaces"."id",
UNION "namespaces"."parent_id",
( "namespaces"."require_two_factor_authentication"
SELECT "namespaces".* FROM
FROM "base_and_descendants" AS "namespaces" "base_and_ancestors" AS "namespaces"
WHERE "namespaces"."type" = 'Group')) namespaces WHERE
WHERE "namespaces"."type" = 'Group' "namespaces"."type" = 'Group')
AND "namespaces".require_two_factor_authentication = TRUE ) AS hierarchy_tree UNION (
ON TRUE); SELECT
"namespaces"."type",
"namespaces"."id",
"namespaces"."parent_id",
"namespaces"."require_two_factor_authentication"
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 SQL
end end
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