Add restricted visibility levels setting to organization
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 modelOrganizationSetting
- 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 toOrganizationSetting
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
- Run migrations (
bundle exec rake db:migrate
) - Open rails console (
gdk rails c
) - Create or find default organization:
default_org = Organizations::Organization.first_or_create(id: 1, name: 'Default', path: 'default')
- Create setting object:
settings = default_org.settings || default_org.create_settings
- Set
restricted_visibility_levels
:settings.update!(restricted_visibility_levels: [0,10])
-
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.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Rutger Wessels