diff options
41 files changed, 427 insertions, 112 deletions
diff --git a/.rubocop_todo/gitlab/strong_memoize_attr.yml b/.rubocop_todo/gitlab/strong_memoize_attr.yml index 5afb7574ff1..d04243974b1 100644 --- a/.rubocop_todo/gitlab/strong_memoize_attr.yml +++ b/.rubocop_todo/gitlab/strong_memoize_attr.yml @@ -41,7 +41,6 @@ Gitlab/StrongMemoizeAttr: - 'app/finders/ci/commit_statuses_finder.rb' - 'app/finders/ci/pipelines_for_merge_request_finder.rb' - 'app/finders/cluster_ancestors_finder.rb' - - 'app/finders/clusters/knative_services_finder.rb' - 'app/finders/concerns/finder_with_group_hierarchy.rb' - 'app/finders/crm/contacts_finder.rb' - 'app/finders/crm/organizations_finder.rb' @@ -88,7 +87,6 @@ Gitlab/StrongMemoizeAttr: - 'app/models/ci/processable.rb' - 'app/models/ci/runner.rb' - 'app/models/clusters/cluster.rb' - - 'app/models/clusters/providers/aws.rb' - 'app/models/commit.rb' - 'app/models/commit_collection.rb' - 'app/models/compare.rb' @@ -96,7 +94,6 @@ Gitlab/StrongMemoizeAttr: - 'app/models/concerns/avatarable.rb' - 'app/models/concerns/cascading_namespace_setting_attribute.rb' - 'app/models/concerns/ci/contextable.rb' - - 'app/models/concerns/ci/partitionable.rb' - 'app/models/concerns/discussion_on_diff.rb' - 'app/models/concerns/has_repository.rb' - 'app/models/concerns/has_wiki.rb' @@ -155,7 +152,6 @@ Gitlab/StrongMemoizeAttr: - 'app/presenters/blobs/unfold_presenter.rb' - 'app/presenters/ci/build_runner_presenter.rb' - 'app/presenters/ci/pipeline_artifacts/code_coverage_presenter.rb' - - 'app/presenters/ci/pipeline_artifacts/code_quality_mr_diff_presenter.rb' - 'app/presenters/ci/pipeline_presenter.rb' - 'app/presenters/clusters/cluster_presenter.rb' - 'app/presenters/merge_request_presenter.rb' @@ -165,11 +161,7 @@ Gitlab/StrongMemoizeAttr: - 'app/presenters/project_presenter.rb' - 'app/presenters/projects/settings/deploy_keys_presenter.rb' - 'app/serializers/ci/pipeline_entity.rb' - - 'app/serializers/concerns/diff_file_conflict_type.rb' - - 'app/serializers/diff_file_base_entity.rb' - - 'app/serializers/integrations/field_entity.rb' - 'app/serializers/linked_project_issue_entity.rb' - - 'app/serializers/suggestion_entity.rb' - 'app/services/alert_management/alerts/update_service.rb' - 'app/services/alert_management/create_alert_issue_service.rb' - 'app/services/alert_management/process_prometheus_alert_service.rb' @@ -179,7 +171,6 @@ Gitlab/StrongMemoizeAttr: - 'app/services/award_emojis/add_service.rb' - 'app/services/base_project_service.rb' - 'app/services/boards/base_items_list_service.rb' - - 'app/services/boards/lists/base_create_service.rb' - 'app/services/ci/create_downstream_pipeline_service.rb' - 'app/services/ci/create_web_ide_terminal_service.rb' - 'app/services/ci/job_artifacts/destroy_batch_service.rb' @@ -194,7 +185,6 @@ Gitlab/StrongMemoizeAttr: - 'app/services/ci/queue/build_queue_service.rb' - 'app/services/ci/update_build_state_service.rb' - 'app/services/clusters/agents/refresh_authorization_service.rb' - - 'app/services/clusters/aws/finalize_creation_service.rb' - 'app/services/clusters/integrations/prometheus_health_check_service.rb' - 'app/services/concerns/alert_management/alert_processing.rb' - 'app/services/concerns/incident_management/settings.rb' @@ -273,7 +263,6 @@ Gitlab/StrongMemoizeAttr: - 'app/services/projects/lfs_pointers/lfs_object_download_list_service.rb' - 'app/services/projects/open_issues_count_service.rb' - 'app/services/projects/record_target_platforms_service.rb' - - 'app/services/projects/update_remote_mirror_service.rb' - 'app/services/projects/update_statistics_service.rb' - 'app/services/prometheus/proxy_service.rb' - 'app/services/quick_actions/interpret_service.rb' @@ -326,14 +315,12 @@ Gitlab/StrongMemoizeAttr: - 'ee/app/finders/ee/issues_finder.rb' - 'ee/app/finders/epics_finder.rb' - 'ee/app/finders/incident_management/oncall_users_finder.rb' - - 'ee/app/finders/requirements_management/requirements_finder.rb' - 'ee/app/finders/security/pipeline_vulnerabilities_finder.rb' - 'ee/app/finders/security/training_providers/base_url_finder.rb' - 'ee/app/graphql/resolvers/epics_resolver.rb' - 'ee/app/graphql/resolvers/vulnerabilities_base_resolver.rb' - 'ee/app/helpers/admin/emails_helper.rb' - 'ee/app/helpers/auditor_user_helper.rb' - - 'ee/app/helpers/billing_plans_helper.rb' - 'ee/app/helpers/ee/ci/runners_helper.rb' - 'ee/app/helpers/ee/preferences_helper.rb' - 'ee/app/helpers/ee/registrations_helper.rb' @@ -352,7 +339,6 @@ Gitlab/StrongMemoizeAttr: - 'ee/app/models/approvals/scan_finding_wrapped_rule_set.rb' - 'ee/app/models/approvals/wrapped_rule_set.rb' - 'ee/app/models/burndown.rb' - - 'ee/app/models/ci/minutes/limit.rb' - 'ee/app/models/concerns/deprecated_approvals_before_merge.rb' - 'ee/app/models/concerns/ee/approvable.rb' - 'ee/app/models/concerns/ee/issue_available_features.rb' @@ -363,7 +349,6 @@ Gitlab/StrongMemoizeAttr: - 'ee/app/models/ee/ci/bridge.rb' - 'ee/app/models/ee/ci/build.rb' - 'ee/app/models/ee/ci/build_dependencies.rb' - - 'ee/app/models/ee/ci/job_artifact.rb' - 'ee/app/models/ee/ci/pipeline.rb' - 'ee/app/models/ee/ci/runner.rb' - 'ee/app/models/ee/deployment.rb' @@ -403,7 +388,6 @@ Gitlab/StrongMemoizeAttr: - 'ee/app/services/deployments/approval_service.rb' - 'ee/app/services/ee/allowed_email_domains/update_service.rb' - 'ee/app/services/ee/auto_merge_service.rb' - - 'ee/app/services/ee/boards/lists/create_service.rb' - 'ee/app/services/ee/ci/retry_pipeline_service.rb' - 'ee/app/services/ee/incident_management/issuable_escalation_statuses/prepare_update_service.rb' - 'ee/app/services/ee/integrations/test/project_service.rb' @@ -440,7 +424,6 @@ Gitlab/StrongMemoizeAttr: - 'ee/app/services/merge_commits/export_csv_service.rb' - 'ee/app/services/merge_requests/update_blocks_service.rb' - 'ee/app/services/projects/restore_service.rb' - - 'ee/app/services/projects/update_mirror_service.rb' - 'ee/app/services/protected_environments/base_service.rb' - 'ee/app/services/security/ingestion/tasks/ingest_vulnerabilities/mark_resolved_as_detected.rb' - 'ee/app/services/security/report_fetch_service.rb' @@ -488,8 +471,6 @@ Gitlab/StrongMemoizeAttr: - 'ee/lib/ee/gitlab/gitaly_client/with_feature_flag_actors.rb' - 'ee/lib/ee/gitlab/import_export/after_export_strategies/custom_template_export_import_strategy.rb' - 'ee/lib/ee/gitlab/issuable_metadata.rb' - - 'ee/lib/ee/gitlab/scim/deprovision_service.rb' - - 'ee/lib/ee/gitlab/scim/provisioning_service.rb' - 'ee/lib/ee/gitlab/security/scan_configuration.rb' - 'ee/lib/ee/gitlab/web_hooks/rate_limiter.rb' - 'ee/lib/ee/sidebars/groups/menus/issues_menu.rb' @@ -558,8 +539,6 @@ Gitlab/StrongMemoizeAttr: - 'lib/banzai/filter/issuable_reference_expansion_filter.rb' - 'lib/banzai/filter/references/reference_cache.rb' - 'lib/banzai/filter/repository_link_filter.rb' - - 'lib/banzai/reference_parser/merge_request_parser.rb' - - 'lib/bulk_imports/clients/http.rb' - 'lib/bulk_imports/pipeline.rb' - 'lib/bulk_imports/users_mapper.rb' - 'lib/container_registry/client.rb' @@ -616,7 +595,6 @@ Gitlab/StrongMemoizeAttr: - 'lib/gitlab/ci/pipeline/chain/seed.rb' - 'lib/gitlab/ci/pipeline/chain/skip.rb' - 'lib/gitlab/ci/pipeline/expression/lexer.rb' - - 'lib/gitlab/ci/pipeline/logger.rb' - 'lib/gitlab/ci/pipeline/metrics.rb' - 'lib/gitlab/ci/pipeline/quota/deployments.rb' - 'lib/gitlab/ci/pipeline/seed/processable/resource_group.rb' @@ -687,7 +665,6 @@ Gitlab/StrongMemoizeAttr: - 'lib/gitlab/gitaly_client/with_feature_flag_actors.rb' - 'lib/gitlab/github_import/client.rb' - 'lib/gitlab/github_import/importer/repository_importer.rb' - - 'lib/gitlab/github_import/representation/diff_note.rb' - 'lib/gitlab/github_import/representation/diff_notes/suggestion_formatter.rb' - 'lib/gitlab/gl_repository/identifier.rb' - 'lib/gitlab/gpg/commit.rb' @@ -727,7 +704,6 @@ Gitlab/StrongMemoizeAttr: - 'lib/gitlab/relative_positioning/starting_from.rb' - 'lib/gitlab/request_context.rb' - 'lib/gitlab/search/found_blob.rb' - - 'lib/gitlab/search/parsed_query.rb' - 'lib/gitlab/serverless/service.rb' - 'lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb' - 'lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/deduplicates_when_scheduling.rb' diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index 959ef1e95cc..87042ced5cb 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -3db1fe837972b9baf49406c4903bbd990840768e +e6d2a47e8a20415d6ecc1e77407ee09f051518a0 diff --git a/app/assets/javascripts/repository/utils/ref_switcher_utils.js b/app/assets/javascripts/repository/utils/ref_switcher_utils.js index ceb80d85f74..f296b5e9b4a 100644 --- a/app/assets/javascripts/repository/utils/ref_switcher_utils.js +++ b/app/assets/javascripts/repository/utils/ref_switcher_utils.js @@ -17,6 +17,7 @@ const NAMESPACE_TARGET_REGEX = /(\/-\/(blob|tree))\/.*?\/(.*)/; */ export function generateRefDestinationPath(projectRootPath, selectedRef) { const currentPath = window.location.pathname; + const encodedHash = '%23'; let namespace = '/-/tree'; let target; const match = NAMESPACE_TARGET_REGEX.exec(currentPath); @@ -27,7 +28,7 @@ export function generateRefDestinationPath(projectRootPath, selectedRef) { const destinationPath = joinPaths( projectRootPath, namespace, - encodeURIComponent(selectedRef), + encodeURI(selectedRef).replace(/#/g, encodedHash), target, ); diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index f8cb57461cb..abefbe28f35 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -358,6 +358,7 @@ class Admin::UsersController < Admin::ApplicationController :username, :website_url, :note, + :private_profile, credit_card_validation_attributes: [:credit_card_validated_at] ] end diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 7a434bd8ecf..84328ca7cb9 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -390,13 +390,13 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo end format.patch do - break render_404 unless @merge_request.diff_refs + next render_404 unless @merge_request.diff_refs send_git_patch @project.repository, @merge_request.diff_refs end format.diff do - break render_404 unless @merge_request.diff_refs + next render_404 unless @merge_request.diff_refs send_git_diff @project.repository, @merge_request.diff_refs end diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 914120684d3..16ccf8ad78a 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -448,7 +448,8 @@ module ApplicationSettingsHelper :invitation_flow_enforcement, :can_create_group, :bulk_import_enabled, - :allow_runner_registration_token + :allow_runner_registration_token, + :user_defaults_to_private_profile ].tap do |settings| next if Gitlab.com? diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index fb62271e19b..4bc6d531beb 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -413,7 +413,7 @@ class ApplicationSetting < ApplicationRecord validates :invisible_captcha_enabled, inclusion: { in: [true, false], message: N_('must be a boolean value') } - validates :invitation_flow_enforcement, :can_create_group, + validates :invitation_flow_enforcement, :can_create_group, :user_defaults_to_private_profile, allow_nil: false, inclusion: { in: [true, false], message: N_('must be a boolean value') } diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb index ab035bfab0b..8ef7e9a92a8 100644 --- a/app/models/application_setting_implementation.rb +++ b/app/models/application_setting_implementation.rb @@ -246,7 +246,8 @@ module ApplicationSettingImplementation users_get_by_id_limit_allowlist: [], can_create_group: true, bulk_import_enabled: false, - allow_runner_registration_token: true + allow_runner_registration_token: true, + user_defaults_to_private_profile: false } end diff --git a/app/models/user.rb b/app/models/user.rb index 45561137fcb..ab0900d296f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -63,6 +63,7 @@ class User < ApplicationRecord attribute :admin, default: false attribute :external, default: -> { Gitlab::CurrentSettings.user_default_external } attribute :can_create_group, default: -> { Gitlab::CurrentSettings.can_create_group } + attribute :private_profile, default: -> { Gitlab::CurrentSettings.user_defaults_to_private_profile } attribute :can_create_team, default: false attribute :hide_no_ssh_key, default: false attribute :hide_no_password, default: false @@ -309,7 +310,6 @@ class User < ApplicationRecord before_validation :sanitize_attrs before_validation :ensure_namespace_correct after_validation :set_username_errors - before_save :default_private_profile_to_false before_save :ensure_incoming_email_token before_save :ensure_user_rights_and_limits, if: ->(user) { user.new_record? || user.external_changed? } before_save :skip_reconfirmation!, if: ->(user) { user.email_changed? && user.read_only_attribute?(:email) } @@ -2296,12 +2296,6 @@ class User < ApplicationRecord ]) end - def default_private_profile_to_false - return unless private_profile_changed? && private_profile.nil? - - self.private_profile = false - end - def has_current_license? false end diff --git a/app/views/admin/application_settings/_user_restrictions.html.haml b/app/views/admin/application_settings/_user_restrictions.html.haml index 82f5e6def9f..c35056383fa 100644 --- a/app/views/admin/application_settings/_user_restrictions.html.haml +++ b/app/views/admin/application_settings/_user_restrictions.html.haml @@ -4,3 +4,4 @@ = label_tag _('User restrictions') = render_if_exists 'admin/application_settings/updating_name_disabled_for_users', form: form = form.gitlab_ui_checkbox_component :can_create_group, _("Allow new users to create top-level groups") + = form.gitlab_ui_checkbox_component :user_defaults_to_private_profile, _("Make new users' profiles private by default") diff --git a/app/views/admin/users/_access_levels.html.haml b/app/views/admin/users/_access_levels.html.haml index b255354f2c1..472ba2f84a0 100644 --- a/app/views/admin/users/_access_levels.html.haml +++ b/app/views/admin/users/_access_levels.html.haml @@ -10,6 +10,7 @@ .form-group.gl-form-group{ role: 'group' } = f.gitlab_ui_checkbox_component :can_create_group, s_('AdminUsers|Can create group') + = f.gitlab_ui_checkbox_component :private_profile, s_('AdminUsers|Private profile') %fieldset.form-group.gl-form-group %legend.col-form-label.col-form-label diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 7edea81a123..f7d4121e6e0 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -76,6 +76,10 @@ %strong = @user.can_create_group ? _('Yes') : _('No') %li + %span.light= _('Private profile:') + %strong + = @user.private_profile ? _('Yes') : _('No') + %li %span.light= _('Personal projects limit:') %strong = @user.projects_limit diff --git a/data/deprecations/15-8-pull-through-cache-container-registry.yml b/data/deprecations/15-8-pull-through-cache-container-registry.yml new file mode 100644 index 00000000000..c5561e72887 --- /dev/null +++ b/data/deprecations/15-8-pull-through-cache-container-registry.yml @@ -0,0 +1,11 @@ +- title: "Container Registry pull-through cache" # (required) Actionable title. e.g., The `confidential` field for a `Note` is deprecated. Use `internal` instead. + announcement_milestone: "15.8" # (required) The milestone when this feature was first announced as deprecated. + announcement_date: "2023-01-22" # (required) The date of the milestone release when this feature was first announced as deprecated. This should almost always be the 22nd of a month (YYYY-MM-22), unless you did an out of band blog post. + removal_milestone: "16.0" # (required) The milestone when this feature is planned to be removed + removal_date: "2023-05-22" # (required) The date of the milestone release when this feature is planned to be removed. This should almost always be the 22nd of a month (YYYY-MM-22), unless you did an out of band blog post. + breaking_change: true # (required) If this deprecation is a breaking change, set this value to true + reporter: trizzi # (required) GitLab username of the person reporting the deprecation + stage: Package # (required) String value of the stage that the feature was created in. e.g., Growth + issue_url: https://gitlab.com/gitlab-org/container-registry/-/issues/842 # (required) Link to the deprecation issue in GitLab + body: | # (required) Do not modify this line, instead modify the lines below. + The Container Registry pull-through cache is deprecated in GitLab 15.8 and will be removed in GitLab 16.0. While the Container Registry pull-through cache functionality is useful, we have not made significant changes to this feature. You can use the upstream version of the container registry to achieve the same functionality. Removing the pull-through cache allows us also to remove the upstream client code without sacrificing functionality. diff --git a/data/deprecations/15-8-third-party-registries.yml b/data/deprecations/15-8-third-party-registries.yml new file mode 100644 index 00000000000..6aceafaa229 --- /dev/null +++ b/data/deprecations/15-8-third-party-registries.yml @@ -0,0 +1,15 @@ +- title: "Support for third party registries" # (required) Actionable title. e.g., The `confidential` field for a `Note` is deprecated. Use `internal` instead. + announcement_milestone: "15.8" # (required) The milestone when this feature was first announced as deprecated. + announcement_date: "2023-01-22" # (required) The date of the milestone release when this feature was first announced as deprecated. This should almost always be the 22nd of a month (YYYY-MM-22), unless you did an out of band blog post. + removal_milestone: "16.0" # (required) The milestone when this feature is planned to be removed + removal_date: "2023-05-22" # (required) The date of the milestone release when this feature is planned to be removed. This should almost always be the 22nd of a month (YYYY-MM-22), unless you did an out of band blog post. + breaking_change: true # (required) If this deprecation is a breaking change, set this value to true + reporter: trizzi # (required) GitLab username of the person reporting the deprecation + stage: Package # (required) String value of the stage that the feature was created in. e.g., Growth + issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/376216 # (required) Link to the deprecation issue in GitLab + body: | # (required) Do not modify this line, instead modify the lines below. + Support for third-party container registries is deprecated in GitLab 15.8 and will be [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/376217) in GitLab 16.0. Supporting both GitLab's Container Registry and third-party container registries is challenging for maintenance, code quality, and backward compatibility. This hinders our ability to stay [efficient](https://about.gitlab.com/handbook/values/#efficiency). + + Since we released the new [GitLab Container Registry](https://gitlab.com/groups/gitlab-org/-/epics/5523) version for GitLab.com, we've started to implement additional features that are not available in third-party container registries. These new features have allowed us to achieve significant performance improvements, such as [cleanup policies](https://gitlab.com/groups/gitlab-org/-/epics/8379). We are focusing on delivering [new features](https://gitlab.com/groups/gitlab-org/-/epics/5136), most of which will require functionalities only available on the GitLab Container Registry. This deprecation allows us to reduce fragmentation and user frustration in the long term by focusing on delivering a more robust integrated registry experience and feature set. + + Moving forward, we'll continue to invest in developing and releasing new features that will only be available in the GitLab Container Registry. diff --git a/db/migrate/20221219135535_add_user_defaults_to_private_profile_to_application_settings.rb b/db/migrate/20221219135535_add_user_defaults_to_private_profile_to_application_settings.rb new file mode 100644 index 00000000000..2770456c46f --- /dev/null +++ b/db/migrate/20221219135535_add_user_defaults_to_private_profile_to_application_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddUserDefaultsToPrivateProfileToApplicationSettings < Gitlab::Database::Migration[2.1] + def change + add_column(:application_settings, :user_defaults_to_private_profile, :boolean, default: false, null: false) + end +end diff --git a/db/post_migrate/20221220131020_bump_default_partition_id_value_for_ci_tables.rb b/db/post_migrate/20221220131020_bump_default_partition_id_value_for_ci_tables.rb new file mode 100644 index 00000000000..3d06f02a6d6 --- /dev/null +++ b/db/post_migrate/20221220131020_bump_default_partition_id_value_for_ci_tables.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +class BumpDefaultPartitionIdValueForCiTables < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + TABLES = { + ci_build_needs: [:partition_id], + ci_build_pending_states: [:partition_id], + ci_build_report_results: [:partition_id], + ci_build_trace_chunks: [:partition_id], + ci_build_trace_metadata: [:partition_id], + ci_builds: [:partition_id], + ci_builds_runner_session: [:partition_id], + ci_job_artifacts: [:partition_id], + ci_job_variables: [:partition_id], + ci_pending_builds: [:partition_id], + ci_pipeline_variables: [:partition_id], + ci_pipelines: [:partition_id], + ci_running_builds: [:partition_id], + ci_sources_pipelines: [:partition_id, :source_partition_id], + ci_stages: [:partition_id], + ci_unit_test_failures: [:partition_id], + p_ci_builds_metadata: [:partition_id] + } + + def up + change_partitions_default_value(from: 100, to: 101) + end + + def down + change_partitions_default_value(from: 101, to: 100) + end + + private + + def change_partitions_default_value(from:, to:) + return unless Gitlab.com? + + TABLES.each do |table_name, columns| + next if columns.all? { |column_name| default_value_for(table_name, column_name) == to } + + with_lock_retries do + columns.each do |column_name| # rubocop:disable Migration/WithLockRetriesDisallowedMethod + change_column_default(table_name, column_name, from: from, to: to) + end + end + end + end + + def default_value_for(table_name, column_name) + connection + .columns(table_name) + .find { |column| column.name == column_name.to_s } + .default&.to_i + end +end diff --git a/db/schema_migrations/20221219135535 b/db/schema_migrations/20221219135535 new file mode 100644 index 00000000000..8d46309bc59 --- /dev/null +++ b/db/schema_migrations/20221219135535 @@ -0,0 +1 @@ +7e9b0184762992556f6c97353f76a45851476ba30667e8afc4946c2aed6d762d
\ No newline at end of file diff --git a/db/schema_migrations/20221220131020 b/db/schema_migrations/20221220131020 new file mode 100644 index 00000000000..36c041b1a33 --- /dev/null +++ b/db/schema_migrations/20221220131020 @@ -0,0 +1 @@ +8adf517eb859b5c945f70fbdeb911d398cf0a25c75b39b5991280390b70d1adf
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index a9148140fdd..baa9c6c75e8 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -11574,6 +11574,7 @@ CREATE TABLE application_settings ( max_terraform_state_size_bytes integer DEFAULT 0 NOT NULL, bulk_import_enabled boolean DEFAULT false NOT NULL, allow_runner_registration_token boolean DEFAULT true NOT NULL, + user_defaults_to_private_profile boolean DEFAULT false NOT NULL, CONSTRAINT app_settings_container_reg_cleanup_tags_max_list_size_positive CHECK ((container_registry_cleanup_tags_service_max_list_size >= 0)), CONSTRAINT app_settings_container_registry_pre_import_tags_rate_positive CHECK ((container_registry_pre_import_tags_rate >= (0)::numeric)), CONSTRAINT app_settings_dep_proxy_ttl_policies_worker_capacity_positive CHECK ((dependency_proxy_ttl_group_policy_worker_capacity >= 0)), diff --git a/doc/.vale/gitlab/spelling-exceptions.txt b/doc/.vale/gitlab/spelling-exceptions.txt index 5203cf6a112..5403b80141e 100644 --- a/doc/.vale/gitlab/spelling-exceptions.txt +++ b/doc/.vale/gitlab/spelling-exceptions.txt @@ -377,6 +377,7 @@ Getter Getters gettext GIDs +gists Git Gitaly Gitea diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md index 62a047a5035..49cb3123ee6 100644 --- a/doc/api/graphql/reference/index.md +++ b/doc/api/graphql/reference/index.md @@ -13271,11 +13271,7 @@ four standard [pagination arguments](#connection-pagination-arguments): ##### `GeoNode.dependencyProxyManifestRegistries` -Find Dependency Proxy Manifest registries on this Geo node. Ignored if `geo_dependency_proxy_manifest_replication` feature flag is disabled. - -WARNING: -**Introduced** in 15.6. -This feature is in Alpha. It can be changed or removed at any time. +Find Dependency Proxy Manifest registries on this Geo node. Returns [`DependencyProxyManifestRegistryConnection`](#dependencyproxymanifestregistryconnection). diff --git a/doc/api/settings.md b/doc/api/settings.md index bee97a2a1d4..77f425fa13f 100644 --- a/doc/api/settings.md +++ b/doc/api/settings.md @@ -226,7 +226,8 @@ Example response: "external_pipeline_validation_service_url": null, "can_create_group": false, "jira_connect_application_key": "123", - "jira_connect_proxy_url": "http://gitlab.example.com" + "jira_connect_proxy_url": "http://gitlab.example.com", + "user_defaults_to_private_profile": true } ``` @@ -512,6 +513,7 @@ listed in the descriptions of the relevant settings. | `user_deactivation_emails_enabled` | boolean | no | Send an email to users upon account deactivation. | | `user_default_external` | boolean | no | Newly registered users are external by default. | | `user_default_internal_regex` | string | no | Specify an email address regex pattern to identify default internal users. | +| `user_defaults_to_private_profile` | boolean | no | Newly created users have private profile by default. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/231301) in GitLab 15.8. Defaults to `false`. | | `user_oauth_applications` | boolean | no | Allow users to register any application to use GitLab as an OAuth provider. | | `user_show_add_ssh_key_message` | boolean | no | When set to `false` disable the `You won't be able to pull or push project code via SSH` warning shown to users with no uploaded SSH key. | | `version_check_enabled` | boolean | no | Let GitLab inform you when an update is available. | diff --git a/doc/api/users.md b/doc/api/users.md index 3578d319774..621049fc1d6 100644 --- a/doc/api/users.md +++ b/doc/api/users.md @@ -468,6 +468,7 @@ over `password`. In addition, `reset_password` and NOTE: From [GitLab 12.1](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/29888/), `private_profile` defaults to `false`. +From [GitLab 15.8](https://gitlab.com/gitlab-org/gitlab/-/issues/231301), `private_profile` defaults to the value determined by [this](../user/admin_area/settings/account_and_limit_settings.md#set-profiles-of-new-users-to-private-by-default) setting. NOTE: From [GitLab 13.2](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/35604), `bio` defaults to `""` instead of `null`. @@ -498,7 +499,7 @@ Parameters: | `note` | No | Administrator notes for this user | | `organization` | No | Organization name | | `password` | No | Password | -| `private_profile` | No | User's profile is private - true, false (default), or null (is converted to false) | +| `private_profile` | No | User's profile is private - true or false. The default value is determined by [this](../user/admin_area/settings/account_and_limit_settings.md#set-profiles-of-new-users-to-private-by-default) setting. | | `projects_limit` | No | Number of projects user can create | | `provider` | No | External provider name | | `reset_password` | No | Send user password reset link - true or false(default) | @@ -547,7 +548,7 @@ Parameters: | `note` | No | Administration notes for this user | | `organization` | No | Organization name | | `password` | No | Password | -| `private_profile` | No | User's profile is private - true, false (default), or null (is converted to false) | +| `private_profile` | No | User's profile is private - true or false. | | `projects_limit` | No | Limit projects each user can create | | `pronouns` | No | Pronouns | | `provider` | No | External provider name | diff --git a/doc/update/deprecations.md b/doc/update/deprecations.md index ed49a4ade09..678f967b88f 100644 --- a/doc/update/deprecations.md +++ b/doc/update/deprecations.md @@ -48,6 +48,43 @@ sole discretion of GitLab Inc. <div class="announcement-milestone"> +## Announced in 15.8 + +<div class="deprecation removal-160 breaking-change"> + +### Container Registry pull-through cache + +Planned removal: GitLab <span class="removal-milestone">16.0</span> (2023-05-22) + +WARNING: +This is a [breaking change](https://docs.gitlab.com/ee/development/deprecation_guidelines/). +Review the details carefully before upgrading. + +The Container Registry pull-through cache is deprecated in GitLab 15.8 and will be removed in GitLab 16.0. While the Container Registry pull-through cache functionality is useful, we have not made significant changes to this feature. You can use the upstream version of the container registry to achieve the same functionality. Removing the pull-through cache allows us also to remove the upstream client code without sacrificing functionality. + +</div> + +<div class="deprecation removal-160 breaking-change"> + +### Support for third party registries + +Planned removal: GitLab <span class="removal-milestone">16.0</span> (2023-05-22) + +WARNING: +This is a [breaking change](https://docs.gitlab.com/ee/development/deprecation_guidelines/). +Review the details carefully before upgrading. + +Support for third-party container registries is deprecated in GitLab 15.8 and will be [removed](https://gitlab.com/gitlab-org/gitlab/-/issues/376217) in GitLab 16.0. Supporting both GitLab's Container Registry and third-party container registries is challenging for maintenance, code quality, and backward compatibility. This hinders our ability to stay [efficient](https://about.gitlab.com/handbook/values/#efficiency). + +Since we released the new [GitLab Container Registry](https://gitlab.com/groups/gitlab-org/-/epics/5523) version for GitLab.com, we've started to implement additional features that are not available in third-party container registries. These new features have allowed us to achieve significant performance improvements, such as [cleanup policies](https://gitlab.com/groups/gitlab-org/-/epics/8379). We are focusing on delivering [new features](https://gitlab.com/groups/gitlab-org/-/epics/5136), most of which will require functionalities only available on the GitLab Container Registry. This deprecation allows us to reduce fragmentation and user frustration in the long term by focusing on delivering a more robust integrated registry experience and feature set. + +Moving forward, we'll continue to invest in developing and releasing new features that will only be available in the GitLab Container Registry. + +</div> +</div> + +<div class="announcement-milestone"> + ## Announced in 15.7 <div class="deprecation removal-160 breaking-change"> diff --git a/doc/user/admin_area/settings/account_and_limit_settings.md b/doc/user/admin_area/settings/account_and_limit_settings.md index b235b812416..7c1616394a2 100644 --- a/doc/user/admin_area/settings/account_and_limit_settings.md +++ b/doc/user/admin_area/settings/account_and_limit_settings.md @@ -291,6 +291,16 @@ By default, new users can create top-level groups. GitLab administrators can pre 1. On the left sidebar, select **Settings > General**, then expand **Account and limit**. 1. Clear the **Allow new users to create top-level groups** checkbox. +## Set profiles of new users to private by default + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/231301) in GitLab 15.8. + +By default, newly created users have a public profile. GitLab administrators can set new users to have a private profile by default: + +1. On the top bar, select **Main menu > Admin**. +1. On the left sidebar, select **Settings > General**, then expand **Account and limit**. +1. Select the **Make new users' profiles private by default** checkbox. + ## Troubleshooting ### 413 Request Entity Too Large diff --git a/doc/user/group/compliance_frameworks.md b/doc/user/group/compliance_frameworks.md index 7c66b442fab..9f40f9e84bf 100644 --- a/doc/user/group/compliance_frameworks.md +++ b/doc/user/group/compliance_frameworks.md @@ -25,9 +25,9 @@ Group owners can create, edit, and delete compliance frameworks: > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/375036) in GitLab 15.6. -Group owners can set a default compliance framework. The default framework is applied to all the new projects -that are created within that group. It does not affect the framework applied to the existing projects. The default -framework cannot be deleted. +Group owners can set a default compliance framework. The default framework is applied to all the new and imported +projects that are created within that group. It does not affect the framework applied to the existing projects. The +default framework cannot be deleted. A compliance framework that is set to default has a **default** label. diff --git a/lib/api/users.rb b/lib/api/users.rb index 7b4c9104cd8..a714bbbbd5a 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -62,6 +62,7 @@ module API optional :avatar, type: ::API::Validations::Types::WorkhorseFile, desc: 'Avatar image for user', documentation: { type: 'file' } optional :theme_id, type: Integer, desc: 'The GitLab theme for the user' optional :color_scheme_id, type: Integer, desc: 'The color scheme for the file viewer' + # TODO: Add `allow_blank: false` in 16.0. Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/387005 optional :private_profile, type: Boolean, desc: 'Flag indicating the user has a private profile' optional :note, type: String, desc: 'Admin note for this user' optional :view_diffs_file_by_file, type: Boolean, desc: 'Flag indicating the user sees only one file diff per page' @@ -294,6 +295,12 @@ module API authenticated_as_admin! params = declared_params(include_missing: false) + + # TODO: Remove in 16.0. Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/387005 + if params.key?(:private_profile) && params[:private_profile].nil? + params[:private_profile] = Gitlab::CurrentSettings.user_defaults_to_private_profile + end + user = ::Users::AuthorizedCreateService.new(current_user, params).execute if user.persisted? @@ -341,6 +348,12 @@ module API .where.not(id: user.id).exists? user_params = declared_params(include_missing: false) + + # TODO: Remove in 16.0. Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/387005 + if user_params.key?(:private_profile) && user_params[:private_profile].nil? + user_params[:private_profile] = Gitlab::CurrentSettings.user_defaults_to_private_profile + end + admin_making_changes_for_another_user = (current_user != user) if user_params[:password].present? diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 3ae6b90bd03..e625da65557 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -3352,6 +3352,9 @@ msgstr "" msgid "AdminUsers|Personal projects, group and user history will be left intact" msgstr "" +msgid "AdminUsers|Private profile" +msgstr "" + msgid "AdminUsers|Quota of CI/CD minutes" msgstr "" @@ -25247,6 +25250,9 @@ msgstr "" msgid "Make everyone on your team more productive regardless of their location. GitLab Geo creates read-only mirrors of your GitLab instance so you can reduce the time it takes to clone and fetch large repos." msgstr "" +msgid "Make new users' profiles private by default" +msgstr "" + msgid "Make sure you choose a strong, unique password." msgstr "" @@ -31635,6 +31641,9 @@ msgstr "" msgid "Private profile" msgstr "" +msgid "Private profile:" +msgstr "" + msgid "Private projects Minutes cost factor" msgstr "" diff --git a/rubocop/cop/gitlab/strong_memoize_attr.rb b/rubocop/cop/gitlab/strong_memoize_attr.rb index 6bae3960854..8ef0f95e75b 100644 --- a/rubocop/cop/gitlab/strong_memoize_attr.rb +++ b/rubocop/cop/gitlab/strong_memoize_attr.rb @@ -34,7 +34,7 @@ module RuboCop class StrongMemoizeAttr < RuboCop::Cop::Base extend RuboCop::Cop::AutoCorrector - MSG = 'Use `strong_memoize_attr`, instead of using `strong_memoize` directly' + MSG = 'Use `strong_memoize_attr`, instead of using `strong_memoize` directly.' def_node_matcher :strong_memoize?, <<~PATTERN (block @@ -50,6 +50,9 @@ module RuboCop send_node, body = strong_memoize?(node) return unless send_node + # Don't flag methods with parameters. + return if send_node.each_ancestor(:def).first&.arguments&.any? + corrector = autocorrect_pure_definitions(node.parent, body) if node.parent.def_type? add_offense(send_node, &corrector) diff --git a/spec/controllers/admin/application_settings_controller_spec.rb b/spec/controllers/admin/application_settings_controller_spec.rb index 49c40ecee8b..6d3f4d9d1cf 100644 --- a/spec/controllers/admin/application_settings_controller_spec.rb +++ b/spec/controllers/admin/application_settings_controller_spec.rb @@ -120,13 +120,6 @@ RSpec.describe Admin::ApplicationSettingsController, :do_not_mock_admin_mode_set sign_in(admin) end - it 'updates the require_admin_approval_after_user_signup setting' do - put :update, params: { application_setting: { require_admin_approval_after_user_signup: true } } - - expect(response).to redirect_to(general_admin_application_settings_path) - expect(ApplicationSetting.current.require_admin_approval_after_user_signup).to eq(true) - end - it 'updates the password_authentication_enabled_for_git setting' do put :update, params: { application_setting: { password_authentication_enabled_for_git: "0" } } @@ -204,13 +197,6 @@ RSpec.describe Admin::ApplicationSettingsController, :do_not_mock_admin_mode_set expect(ApplicationSetting.current.default_branch_name).to eq("example_branch_name") end - it "updates admin_mode setting" do - put :update, params: { application_setting: { admin_mode: true } } - - expect(response).to redirect_to(general_admin_application_settings_path) - expect(ApplicationSetting.current.admin_mode).to be(true) - end - it 'updates valid_runner_registrars setting' do put :update, params: { application_setting: { valid_runner_registrars: ['project', ''] } } @@ -218,11 +204,23 @@ RSpec.describe Admin::ApplicationSettingsController, :do_not_mock_admin_mode_set expect(ApplicationSetting.current.valid_runner_registrars).to eq(['project']) end - it 'updates can_create_group setting' do - put :update, params: { application_setting: { can_create_group: false } } + context 'boolean attributes' do + shared_examples_for 'updates booolean attribute' do |attribute| + specify do + existing_value = ApplicationSetting.current.public_send(attribute) + new_value = !existing_value - expect(response).to redirect_to(general_admin_application_settings_path) - expect(ApplicationSetting.current.can_create_group).to eq(false) + put :update, params: { application_setting: { attribute => new_value } } + + expect(response).to redirect_to(general_admin_application_settings_path) + expect(ApplicationSetting.current.public_send(attribute)).to eq(new_value) + end + end + + it_behaves_like 'updates booolean attribute', :user_defaults_to_private_profile + it_behaves_like 'updates booolean attribute', :can_create_group + it_behaves_like 'updates booolean attribute', :admin_mode + it_behaves_like 'updates booolean attribute', :require_admin_approval_after_user_signup end context "personal access token prefix settings" do diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index cb74faac1ce..b347c03e5cf 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -229,6 +229,16 @@ RSpec.describe Projects::MergeRequestsController, feature_category: :code_review expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-diff:") end + + context 'when there is no diff' do + it 'renders 404' do + merge_request.merge_request_diff.destroy! + + go(format: :diff) + + expect(response).to have_gitlab_http_status(:not_found) + end + end end describe "as patch" do @@ -237,6 +247,16 @@ RSpec.describe Projects::MergeRequestsController, feature_category: :code_review expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-format-patch:") end + + context 'when there is no diff' do + it 'renders 404' do + merge_request.merge_request_diff.destroy! + + go(format: :patch) + + expect(response).to have_gitlab_http_status(:not_found) + end + end end end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 699052fe37a..d0439a18158 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -137,6 +137,21 @@ RSpec.describe RegistrationsController do end end + context 'private profile' do + context 'when the `user_defaults_to_private_profile` setting is turned on' do + before do + stub_application_setting(user_defaults_to_private_profile: true) + end + + it 'creates new user with profile set to private' do + subject + user = User.find_by(email: base_user_params[:email], private_profile: true) + + expect(user).to be_present + end + end + end + context 'email confirmation' do before do stub_feature_flags(identity_verification: false) diff --git a/spec/features/admin/users/users_spec.rb b/spec/features/admin/users/users_spec.rb index 4da86821862..975af84969d 100644 --- a/spec/features/admin/users/users_spec.rb +++ b/spec/features/admin/users/users_spec.rb @@ -367,6 +367,8 @@ RSpec.describe 'Admin::Users', feature_category: :user_management do .to eq(Gitlab.config.gitlab.default_projects_limit) expect(user.can_create_group) .to eq(Gitlab::CurrentSettings.can_create_group) + expect(user.private_profile) + .to eq(Gitlab::CurrentSettings.user_defaults_to_private_profile) end it 'creates user with valid data' do @@ -564,6 +566,7 @@ RSpec.describe 'Admin::Users', feature_category: :user_management do fill_in 'user_password', with: 'AValidPassword1' fill_in 'user_password_confirmation', with: 'AValidPassword1' choose 'user_access_level_admin' + check 'Private profile' click_button 'Save changes' end @@ -577,6 +580,7 @@ RSpec.describe 'Admin::Users', feature_category: :user_management do expect(user.name).to eq('Big Bang') expect(user.admin?).to be_truthy expect(user.password_expires_at).to be <= Time.zone.now + expect(user.private_profile).to eq(true) end end diff --git a/spec/frontend/repository/commits_service_spec.js b/spec/frontend/repository/commits_service_spec.js index b7343bf3a7e..2ff2f4f6eb5 100644 --- a/spec/frontend/repository/commits_service_spec.js +++ b/spec/frontend/repository/commits_service_spec.js @@ -4,7 +4,7 @@ import { loadCommits, isRequested, resetRequestedCommits } from '~/repository/co import httpStatus from '~/lib/utils/http_status'; import { createAlert } from '~/flash'; import { I18N_COMMIT_DATA_FETCH_ERROR } from '~/repository/constants'; -import { refWithSpecialCharMock, encodedRefWithSpecialCharMock } from './mock_data'; +import { refWithSpecialCharMock } from './mock_data'; jest.mock('~/flash'); @@ -41,7 +41,8 @@ describe('commits service', () => { }); it('encodes the path and ref', async () => { - const encodedUrl = `/some-project/-/refs/${encodedRefWithSpecialCharMock}/logs_tree/with%20%24peci%40l%20ch%40rs%2F`; + const encodedRef = encodeURIComponent(refWithSpecialCharMock); + const encodedUrl = `/some-project/-/refs/${encodedRef}/logs_tree/with%20%24peci%40l%20ch%40rs%2F`; await requestCommits(1, 'some-project', 'with $peci@l ch@rs/', refWithSpecialCharMock); diff --git a/spec/frontend/repository/mock_data.js b/spec/frontend/repository/mock_data.js index 28dd19c29e6..63b62c80e30 100644 --- a/spec/frontend/repository/mock_data.js +++ b/spec/frontend/repository/mock_data.js @@ -87,8 +87,8 @@ export const applicationInfoMock = { gitpodEnabled: true }; export const propsMock = { path: 'some_file.js', projectPath: 'some/path' }; export const refMock = 'default-ref'; -export const refWithSpecialCharMock = 'selected-#-ref'; -export const encodedRefWithSpecialCharMock = encodeURIComponent(refWithSpecialCharMock); +export const refWithSpecialCharMock = 'feat/selected-#-ref-#'; +export const encodedRefWithSpecialCharMock = 'feat/selected-%23-ref-%23'; export const blobControlsDataMock = { id: '1234', diff --git a/spec/migrations/20221220131020_bump_default_partition_id_value_for_ci_tables_spec.rb b/spec/migrations/20221220131020_bump_default_partition_id_value_for_ci_tables_spec.rb new file mode 100644 index 00000000000..1a2300eb4af --- /dev/null +++ b/spec/migrations/20221220131020_bump_default_partition_id_value_for_ci_tables_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe BumpDefaultPartitionIdValueForCiTables, :migration, feature_category: :continuous_integration_scaling do + context 'when on sass' do + before do + allow(Gitlab).to receive(:com?).and_return(true) + end + + it 'changes default values' do + reversible_migration do |migration| + migration.before -> { + expect(default_values).not_to include(101) + } + + migration.after -> { + expect(default_values).to match_array([101]) + } + end + end + + context 'with tables already changed' do + before do + active_record_base.connection.execute(<<~SQL) + ALTER TABLE ci_builds ALTER COLUMN partition_id SET DEFAULT 101 + SQL + end + + after do + schema_migrate_down! + end + + let(:alter_query) do + /ALTER TABLE "ci_builds" ALTER COLUMN "partition_id" SET DEFAULT 101/ + end + + it 'skips updating already changed tables' do + recorder = ActiveRecord::QueryRecorder.new { migrate! } + + expect(recorder.log.any?(alter_query)).to be_falsey + expect(default_values).to match_array([101]) + end + end + end + + context 'when self-managed' do + before do + allow(Gitlab).to receive(:com?).and_return(false) + end + + it 'does not change default values' do + reversible_migration do |migration| + migration.before -> { + expect(default_values).not_to include(101) + } + + migration.after -> { + expect(default_values).not_to include(101) + } + end + end + end + + def default_values + values = described_class::TABLES.flat_map do |table_name, columns| + active_record_base + .connection + .columns(table_name) + .select { |column| columns.include?(column.name.to_sym) } + .map { |column| column.default&.to_i } + end + + values.uniq + end +end diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index f6aae7b6d91..a35a903a13b 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -128,6 +128,10 @@ RSpec.describe ApplicationSetting, feature_category: :not_owned, type: :model do it { is_expected.to validate_presence_of(:max_terraform_state_size_bytes) } it { is_expected.to validate_numericality_of(:max_terraform_state_size_bytes).only_integer.is_greater_than_or_equal_to(0) } + it { is_expected.to allow_value(true).for(:user_defaults_to_private_profile) } + it { is_expected.to allow_value(false).for(:user_defaults_to_private_profile) } + it { is_expected.not_to allow_value(nil).for(:user_defaults_to_private_profile) } + it 'ensures max_pages_size is an integer greater than 0 (or equal to 0 to indicate unlimited/maximum)' do is_expected.to validate_numericality_of(:max_pages_size).only_integer.is_greater_than_or_equal_to(0) .is_less_than(::Gitlab::Pages::MAX_SIZE / 1.megabyte) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0bbf7d86b28..5b6f15176be 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1252,17 +1252,6 @@ RSpec.describe User do end describe 'before save hook' do - describe '#default_private_profile_to_false' do - let(:user) { create(:user, private_profile: true) } - - it 'converts nil to false' do - user.private_profile = nil - user.save! - - expect(user.private_profile).to eq false - end - end - context 'when saving an external user' do let(:user) { create(:user) } let(:external_user) { create(:user, external: true) } @@ -2697,7 +2686,7 @@ RSpec.describe User do expect(user.can_create_group).to eq(Gitlab::CurrentSettings.can_create_group) expect(user.theme_id).to eq(Gitlab.config.gitlab.default_theme) expect(user.external).to be_falsey - expect(user.private_profile).to eq(false) + expect(user.private_profile).to eq(Gitlab::CurrentSettings.user_defaults_to_private_profile) end end diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb index 1e8c06bd77a..e89988893c2 100644 --- a/spec/requests/api/settings_spec.rb +++ b/spec/requests/api/settings_spec.rb @@ -65,6 +65,7 @@ RSpec.describe API::Settings, 'Settings', :do_not_mock_admin_mode_setting, featu expect(json_response['can_create_group']).to eq(true) expect(json_response['jira_connect_application_key']).to eq(nil) expect(json_response['jira_connect_proxy_url']).to eq(nil) + expect(json_response['user_defaults_to_private_profile']).to eq(false) end end @@ -167,7 +168,8 @@ RSpec.describe API::Settings, 'Settings', :do_not_mock_admin_mode_setting, featu jira_connect_application_key: '123', jira_connect_proxy_url: 'http://example.com', bulk_import_enabled: false, - allow_runner_registration_token: true + allow_runner_registration_token: true, + user_defaults_to_private_profile: true } expect(response).to have_gitlab_http_status(:ok) @@ -234,6 +236,7 @@ RSpec.describe API::Settings, 'Settings', :do_not_mock_admin_mode_setting, featu expect(json_response['jira_connect_proxy_url']).to eq('http://example.com') expect(json_response['bulk_import_enabled']).to be(false) expect(json_response['allow_runner_registration_token']).to be(true) + expect(json_response['user_defaults_to_private_profile']).to be(true) end end diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 0808b8b3a19..3499e20b27c 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -1454,6 +1454,46 @@ RSpec.describe API::Users, feature_category: :users do include_examples 'does not allow the "read_user" scope' end + + context "`private_profile` attribute" do + context "based on the application setting" do + before do + stub_application_setting(user_defaults_to_private_profile: true) + end + + let(:params) { attributes_for(:user) } + + shared_examples_for 'creates the user with the value of `private_profile` based on the application setting' do + specify do + post api("/users", admin), params: params + + expect(response).to have_gitlab_http_status(:created) + user = User.find_by(id: json_response['id'], private_profile: true) + expect(user).to be_present + end + end + + context 'when the attribute is not overridden in params' do + it_behaves_like 'creates the user with the value of `private_profile` based on the application setting' + end + + context 'when the attribute is overridden in params' do + it 'creates the user with the value of `private_profile` same as the value of the overridden param' do + post api("/users", admin), params: params.merge(private_profile: false) + + expect(response).to have_gitlab_http_status(:created) + user = User.find_by(id: json_response['id'], private_profile: false) + expect(user).to be_present + end + + context 'overridden as `nil`' do + let(:params) { attributes_for(:user, private_profile: nil) } + + it_behaves_like 'creates the user with the value of `private_profile` based on the application setting' + end + end + end + end end describe "PUT /users/:id" do @@ -1634,12 +1674,6 @@ RSpec.describe API::Users, feature_category: :users do expect(user.reload.external?).to be_truthy end - it "private profile is false by default" do - put api("/users/#{user.id}", admin), params: {} - - expect(user.reload.private_profile).to eq(false) - end - it "does have default values for theme and color-scheme ID" do put api("/users/#{user.id}", admin), params: {} @@ -1647,13 +1681,6 @@ RSpec.describe API::Users, feature_category: :users do expect(user.reload.color_scheme_id).to eq(Gitlab::ColorSchemes.default.id) end - it "updates private profile" do - put api("/users/#{user.id}", admin), params: { private_profile: true } - - expect(response).to have_gitlab_http_status(:ok) - expect(user.reload.private_profile).to eq(true) - end - it "updates viewing diffs file by file" do put api("/users/#{user.id}", admin), params: { view_diffs_file_by_file: true } @@ -1661,22 +1688,40 @@ RSpec.describe API::Users, feature_category: :users do expect(user.reload.user_preference.view_diffs_file_by_file?).to eq(true) end - it "updates private profile to false when nil is given" do - user.update!(private_profile: true) + context 'updating `private_profile`' do + it "updates private profile" do + current_value = user.private_profile + new_value = !current_value - put api("/users/#{user.id}", admin), params: { private_profile: nil } + put api("/users/#{user.id}", admin), params: { private_profile: new_value } - expect(response).to have_gitlab_http_status(:ok) - expect(user.reload.private_profile).to eq(false) - end + expect(response).to have_gitlab_http_status(:ok) + expect(user.reload.private_profile).to eq(new_value) + end - it "does not modify private profile when field is not provided" do - user.update!(private_profile: true) + context 'when `private_profile` is set to `nil`' do + before do + stub_application_setting(user_defaults_to_private_profile: true) + end - put api("/users/#{user.id}", admin), params: {} + it "updates private_profile to value of the application setting" do + user.update!(private_profile: false) - expect(response).to have_gitlab_http_status(:ok) - expect(user.reload.private_profile).to eq(true) + put api("/users/#{user.id}", admin), params: { private_profile: nil } + + expect(response).to have_gitlab_http_status(:ok) + expect(user.reload.private_profile).to eq(true) + end + end + + it "does not modify private profile when field is not provided" do + user.update!(private_profile: true) + + put api("/users/#{user.id}", admin), params: {} + + expect(response).to have_gitlab_http_status(:ok) + expect(user.reload.private_profile).to eq(true) + end end it "does not modify theme or color-scheme ID when field is not provided" do diff --git a/spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb b/spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb index 0ca9a489257..3b90872a09b 100644 --- a/spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb +++ b/spec/rubocop/cop/gitlab/strong_memoize_attr_spec.rb @@ -11,7 +11,7 @@ RSpec.describe RuboCop::Cop::Gitlab::StrongMemoizeAttr do class Foo def memoized_method strong_memoize(:memoized_method) do - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly. 'This is a memoized method' end end @@ -35,7 +35,7 @@ RSpec.describe RuboCop::Cop::Gitlab::StrongMemoizeAttr do class Foo def enabled? strong_memoize(:enabled) do - ^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly + ^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly. true end end @@ -62,7 +62,7 @@ RSpec.describe RuboCop::Cop::Gitlab::StrongMemoizeAttr do msg = 'This is a memoized method' strong_memoize(:memoized_method) do - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `strong_memoize_attr`, instead of using `strong_memoize` directly. msg end end @@ -72,4 +72,18 @@ RSpec.describe RuboCop::Cop::Gitlab::StrongMemoizeAttr do expect_no_corrections end end + + context 'when strong_memoize() is used in a method with parameters' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + class Foo + def memoized_method(param) + strong_memoize(:memoized_method) do + param.to_s + end + end + end + RUBY + end + end end |