Skip to content

Add restricted visibility levels setting to organization

Rutger Wessels requested to merge 394801-option-2-org_settings-json into master

What does this MR do and why?

As part of Cells Architecture. we are adding Organization as a top-level grouping for projects and existing groups. This means also that we will move some settings from GitLab instance level (ApplicationSetting) to Organization level. This MR will add the data storage for these settings.

We decided to try it out with one setting first: restricted_visibility_levels.

This MR is adding the database structure and supporting code. The current ApplicationSetting model is not changed yet.

Related to #394801 (closed)

Implementation

  • organization_settings table, will have 1 record per Organization. Separate model OrganizationSetting
  • Use PostgreSQL jsonb data type. We will move away from creating 1 column for each setting (application_settings now has around 520 columns).
  • Use jsonb_accessor gem. This allows us to easily port validation logic from ApplicationSetting model to OrganizationSetting model because the keys of the json structure are exposed as attributes that can have validations.
# JSON in database:
{"restricted_visibility_levels"=>[0, 10]}

# Can be accessed in Ruby as:
organization.settings.restricted_visibility_levels

The jsonb_accessor gem meets GitLab criteria:

  • Active developer, recent contributions, backed by a company
  • Few open issues, they look like feature requests
  • They use CI using various combinations of versions of ActiveRecord and Ruby, including current GitLab versions
  • License: MIT

Next up

  • Next MR will be integration with Gitlab::CurrentSettings.

How to set up and validate locally

  1. Run migrations (bundle exec rake db:migrate)
  2. Open rails console (gdk rails c)
  3. Create or find default organization: default_org = Organizations::Organization.first_or_create(id: 1, name: 'Default', path: 'default')
  4. Create setting object: settings = default_org.settings || default_org.create_settings
  5. Set restricted_visibility_levels: settings.update!(restricted_visibility_levels: [0,10])
  6. default_org.settings.restricted_visibility_levels should output [0,10]

MR acceptance checklist

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

Edited by Rutger Wessels

Merge request reports