diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/visibility_level_helper.rb | 38 | ||||
-rw-r--r-- | app/views/projects/_new_project_fields.html.haml | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/app/helpers/visibility_level_helper.rb b/app/helpers/visibility_level_helper.rb index 9deb783d289..70e60bfba8d 100644 --- a/app/helpers/visibility_level_helper.rb +++ b/app/helpers/visibility_level_helper.rb @@ -165,8 +165,46 @@ module VisibilityLevelHelper !form_model.visibility_level_allowed?(level) end + # Visibility level can be restricted in two ways: + # + # 1. The group permissions (e.g. a subgroup is private, which requires + # all projects to be private) + # 2. The global allowed visibility settinngs, set by the admin + def selected_visibility_level(form_model, requested_level) + requested_level = + if requested_level.present? + requested_level.to_i + else + default_project_visibility + end + + [requested_level, max_allowed_visibility_level(form_model)].min + end + private + def max_allowed_visibility_level(form_model) + # First obtain the maximum visibility for the project or group + current_level = max_allowed_visibility_level_by_model(form_model) + + # Now limit this by the global setting + Gitlab::VisibilityLevel.closest_allowed_level(current_level) + end + + def max_allowed_visibility_level_by_model(form_model) + current_level = Gitlab::VisibilityLevel::PRIVATE + + Gitlab::VisibilityLevel.values.sort.each do |value| + if disallowed_visibility_level?(form_model, value) + break + else + current_level = value + end + end + + current_level + end + def visibility_level_errors_for_group(group, level_name) group_name = link_to group.name, group_path(group) change_visiblity = link_to 'change the visibility', edit_group_path(group) diff --git a/app/views/projects/_new_project_fields.html.haml b/app/views/projects/_new_project_fields.html.haml index 9ae84a909a5..e423631ec99 100644 --- a/app/views/projects/_new_project_fields.html.haml +++ b/app/views/projects/_new_project_fields.html.haml @@ -1,4 +1,4 @@ -- visibility_level = params.dig(:project, :visibility_level) || default_project_visibility +- visibility_level = selected_visibility_level(@project, params.dig(:project, :visibility_level)) - ci_cd_only = local_assigns.fetch(:ci_cd_only, false) - hide_init_with_readme = local_assigns.fetch(:hide_init_with_readme, false) - track_label = local_assigns.fetch(:track_label, 'blank_project') |