Only admins can search blocked, banned and unconfirmed users
What does this MR do and why?
Closes https://gitlab.com/gitlab-org/gitlab/-/issues/346086
This excludes blocked, banned, and unconfirmed users from searches by non-admin users.
SQL query for User.without_forbidden_states scope
[13] pry(main)> puts User.without_forbidden_states.to_sql
SELECT "users".* FROM "users" WHERE "users"."confirmed_at" IS NOT NULL AND "users"."state" NOT IN ('blocked', 'banned', 'ldap_blocked')
Migration output
== 20220404183350 AddForbiddenStateIndexToUsers: migrating ====================
-- execute("SET statement_timeout TO 0")
-> 0.0004s
-- execute(" CREATE INDEX CONCURRENTLY users_forbidden_state_idx ON users\n USING btree (state)\n WHERE (state <> ANY (ARRAY['blocked', 'banned', 'ldap_blocked']));\n")
-> 0.0039s
-- execute("RESET statement_timeout")
-> 0.0004s
== 20220404183350 AddForbiddenStateIndexToUsers: migrated (0.0056s) ===========
Rollback output
❯ rails db:rollback
== 20220404183350 AddForbiddenStateIndexToUsers: reverting ====================
-- transaction_open?()
-> 0.0000s
-- index_exists?(:users, :state, {:name=>"users_forbidden_state_idx", :algorithm=>:concurrently})
-> 0.0112s
== 20220404183350 AddForbiddenStateIndexToUsers: reverted (0.0120s) ===========
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by John Mason