Add models attributes for Duo Code Review depth cascading settings
What does this MR do and why?
The Duo Code Review depth settings need model support before the settings pages, API and services can use them. This MR adds that support on top of the columns from !263955 (merged).
Both settings cascade from the instance to groups, subgroups and projects:
duo_code_review_depth_allowed: whether depths other than Standard, such as Deep, are allowed.duo_code_review_default_depth: the default depth,standardordeep. The instance always has one, and the default is Standard. Deep requires deep reviews to be allowed: when a save turns off deep reviews, a Deep default, own or inherited, is reset to Standard.
The settings do not use their lock_ columns, so a group cannot enforce a value on the levels below it. We agreed to keep the settings simple for the beta in !262996 (comment 4109666703). The columns stay in the database, unused, so we can add enforcement later without a migration. Instead, a change at instance or group level will be written to the groups and projects below it, which comes with the services MR.
Nothing in the UI, API or review flow reads these settings yet.
References
- gitlab-org#23598
- !262996 (comment 4109666703) (decision to drop enforcement for now)
Screenshots or screen recordings
Not applicable. This MR has no UI changes.
How to set up and validate locally
The settings pages and API come in later MRs, so for now the only way to see the behavior is the Rails console. Do the setup, then do the scenarios in order in the same console.
Setup
user = User.find_by_username('root')
group = Group.find_by_full_path('gitlab-duo')
subgroup = Groups::CreateService.new(user, name: 'depth-check', path: 'depth-check', parent_id: group.id, organization_id: group.organization_id).execute.payload[:group]
project = Project.find_by_full_path('gitlab-duo/test')Scenario 1: a subgroup inherits duo_code_review_depth_allowed
Steps
-
Turn off deep reviews on the group:
group.namespace_settings.update!(duo_code_review_depth_allowed: false) -
Check what the subgroup and project see. The subgroup stores no value of its own and inherits
false. The project keeps its own stored value, because writing the value down to projects comes with the services MR:subgroup.reload.namespace_settings.duo_code_review_depth_allowed # => false subgroup.namespace_settings.read_attribute(:duo_code_review_depth_allowed) # => nil project.reload.project_setting.duo_code_review_depth_allowed # => true
Scenario 2: a subgroup inherits duo_code_review_default_depth
Steps
-
Allow deep reviews on the group and default it to Deep:
group.reload.namespace_settings.update!(duo_code_review_depth_allowed: true, duo_code_review_default_depth: 'deep') -
Check what the subgroup and project see:
subgroup.reload.namespace_settings.duo_code_review_default_depth # => "deep" project.reload.project_setting.duo_code_review_default_depth # => "standard"
Scenario 3: a subgroup overrides the group
Steps
-
Set Standard on the subgroup while the group defaults to Deep:
subgroup.reload.namespace_settings.update!(duo_code_review_default_depth: 'standard') -
The subgroup keeps its own value, and the group is unchanged:
subgroup.reload.namespace_settings.duo_code_review_default_depth # => "standard" group.reload.namespace_settings.duo_code_review_default_depth # => "deep"
Scenario 4: Deep is reset when deep reviews are not allowed
Steps
-
Clear the subgroup value so that it inherits Deep from the group again:
subgroup.reload.namespace_settings.update!(duo_code_review_default_depth: nil) subgroup.reload.namespace_settings.read_attribute(:duo_code_review_default_depth) # => nil subgroup.namespace_settings.duo_code_review_default_depth # => "deep" -
Turn off deep reviews on the subgroup. The inherited Deep is reset to Standard, and the group keeps Deep:
subgroup.reload.namespace_settings.update!(duo_code_review_depth_allowed: false) subgroup.reload.namespace_settings.duo_code_review_default_depth # => "standard" group.reload.namespace_settings.duo_code_review_default_depth # => "deep" -
Turn off deep reviews on the group. Its own Deep is reset to Standard:
group.reload.namespace_settings.update!(duo_code_review_depth_allowed: false) group.reload.namespace_settings.duo_code_review_default_depth # => "standard"
Scenario 5: Deep is reset on a project
Steps
-
Default the project to Deep:
project.reload.project_setting.update!(duo_code_review_depth_allowed: true, duo_code_review_default_depth: 'deep') project.reload.project_setting.duo_code_review_default_depth # => "deep" -
Turn off deep reviews on the project. Its Deep is reset to Standard:
project.reload.project_setting.update!(duo_code_review_depth_allowed: false) project.reload.project_setting.duo_code_review_default_depth # => "standard"
Scenario 6: the instance setting
Steps
-
Default the instance to Deep, then turn off deep reviews. Deep is reset to Standard:
ApplicationSetting.current_without_cache.update!(duo_code_review_default_depth: 'deep') ApplicationSetting.current_without_cache.update!(duo_code_review_depth_allowed: false) ApplicationSetting.current_without_cache.duo_code_review_default_depth # => "standard" -
The instance always needs a default depth:
setting = ApplicationSetting.current_without_cache setting.duo_code_review_default_depth = nil setting.valid? # => false setting.errors.full_messages # => ["Duo code review default depth can't be blank"]
Clean up
group.reload.namespace_settings.update!(duo_code_review_depth_allowed: true, duo_code_review_default_depth: 'standard')
project.reload.project_setting.update!(duo_code_review_depth_allowed: true, duo_code_review_default_depth: 'standard')
ApplicationSetting.current_without_cache.update!(duo_code_review_depth_allowed: true, duo_code_review_default_depth: 'standard')
Groups::DestroyService.new(subgroup, user).executeMR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.