Skip to content

Add auto-ban toggle to namespace settings

Hinam Mehra requested to merge 57-auto-ban-namespace-db-api into master

What does this MR do and why?

We already have a functional feature flag auto_ban_user_on_namespace_excessive_projects_download. We want to replace this with a toggle in the UI so admins can toggle this on and off themselves. This MR just adds a boolean column, auto_ban_user_on_excessive_projects_download in the namespace_settings table.

Database Migrations

  1. Output of db:migrate
main: == 20220803004853 AddAutoBanUserToNamespaceSettings: migrating ================
main: -- add_column(:namespace_settings, :auto_ban_user_on_excessive_projects_download, :boolean, {:default=>false, :null=>false})
main:    -> 0.0025s
main: == 20220803004853 AddAutoBanUserToNamespaceSettings: migrated (0.0028s) =======
main: == 20220803235114 AddAutoBanUserToApplicationSettings: migrating ==============
main: -- add_column(:application_settings, :auto_ban_user_on_excessive_projects_download, :boolean, {:default=>false, :null=>false})
main:    -> 0.0041s
main: == 20220803235114 AddAutoBanUserToApplicationSettings: migrated (0.0043s) =====
  1. Output of db:rollback
main: == 20220803004853 AddAutoBanUserToNamespaceSettings: reverting ================
main: -- remove_column(:namespace_settings, :auto_ban_user_on_excessive_projects_download, :boolean, {:default=>false, :null=>false})
main:    -> 0.0022s
main: == 20220803004853 AddAutoBanUserToNamespaceSettings: reverted (0.0028s) =======
  1. db:check-migrations
  2. db:gitlabcom-database-testing results

How to set up and validate locally

  1. Run the migration
bin/rake db:migrate RAILS_ENV=development
  1. Turn on feature flag
bundle exec rails c
> Feature.enable(:limit_unique_project_downloads_per_namespace_user)
  1. Generate a Personal Access Token from http://localhost:3000/-/profile/personal_access_tokens
  2. List the current group settings for a top-level group. You should see auto_ban_user_on_excessive_projects_download: false returned in the response. Recommended top-level group Gitlab Org.
curl --header "PRIVATE-TOKEN: <your_access_token>" "http://localhost:3000/api/v4/groups/<TOP_LEVEL_GROUP_ID>"
  1. Update the value of auto_ban_user_on_excessive_projects_download
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" -d "auto_ban_user_on_excessive_projects_download=true" "http://localhost:3000/api/v4/groups/<TOP_LEVEL_GROUP_ID>"

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Partially resolves https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/57

Edited by Hinam Mehra

Merge request reports