diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-15 15:08:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-15 15:08:47 +0300 |
commit | 717436a767395d0ed850a16d07f19cd51c3d4551 (patch) | |
tree | 5c2d69721710081da88c8dcf097813e2f40c062c /app | |
parent | 5a14a0fe63ac7dace9821be554ad3b3951529708 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/content_editor/services/serialization_helpers.js | 1 | ||||
-rw-r--r-- | app/controllers/projects/autocomplete_sources_controller.rb | 2 | ||||
-rw-r--r-- | app/finders/releases_finder.rb | 7 | ||||
-rw-r--r-- | app/models/ci/catalog/resource.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 104 | ||||
-rw-r--r-- | app/models/release.rb | 32 | ||||
-rw-r--r-- | app/services/projects/participants_service.rb | 2 |
7 files changed, 95 insertions, 55 deletions
diff --git a/app/assets/javascripts/content_editor/services/serialization_helpers.js b/app/assets/javascripts/content_editor/services/serialization_helpers.js index 9f3c61f2a0d..b2cbc9c3fed 100644 --- a/app/assets/javascripts/content_editor/services/serialization_helpers.js +++ b/app/assets/javascripts/content_editor/services/serialization_helpers.js @@ -158,6 +158,7 @@ function setIsInBlockTable(table, value) { } function ensureSpace(state) { + state.flushClose(); if (!state.atBlank() && !state.out.endsWith(' ')) state.write(' '); } diff --git a/app/controllers/projects/autocomplete_sources_controller.rb b/app/controllers/projects/autocomplete_sources_controller.rb index ffe6071ab3c..480e3408023 100644 --- a/app/controllers/projects/autocomplete_sources_controller.rb +++ b/app/controllers/projects/autocomplete_sources_controller.rb @@ -6,7 +6,7 @@ class Projects::AutocompleteSourcesController < Projects::ApplicationController feature_category :team_planning, [:issues, :labels, :milestones, :commands, :contacts] feature_category :code_review_workflow, [:merge_requests] - feature_category :user_profile, [:members] + feature_category :groups_and_projects, [:members] feature_category :source_code_management, [:snippets] urgency :low, [:merge_requests, :members] diff --git a/app/finders/releases_finder.rb b/app/finders/releases_finder.rb index 16d3f46e1af..c7d35f62673 100644 --- a/app/finders/releases_finder.rb +++ b/app/finders/releases_finder.rb @@ -11,13 +11,14 @@ class ReleasesFinder @params = params params[:order_by] ||= 'released_at' + params[:order_by_for_latest] ||= 'released_at' params[:sort] ||= 'desc' end def execute(preload: true) return Release.none if authorized_projects.empty? - releases = get_releases + releases = params[:latest] ? get_latest_releases : get_releases releases = by_tag(releases) releases = releases.preloaded if preload order_releases(releases) @@ -29,6 +30,10 @@ class ReleasesFinder Release.where(project_id: authorized_projects).where.not(tag: nil) # rubocop: disable CodeReuse/ActiveRecord end + def get_latest_releases + Release.latest_for_projects(authorized_projects, order_by: params[:order_by_for_latest]).where.not(tag: nil) # rubocop: disable CodeReuse/ActiveRecord + end + def authorized_projects # Preload policy for all projects to avoid N+1 queries projects = Project.id_in(parent.map(&:id)).include_project_feature diff --git a/app/models/ci/catalog/resource.rb b/app/models/ci/catalog/resource.rb index f5bcc3867ec..77cfe91ddd6 100644 --- a/app/models/ci/catalog/resource.rb +++ b/app/models/ci/catalog/resource.rb @@ -24,7 +24,7 @@ module Ci end def latest_version - versions.first + project.releases.latest end end end diff --git a/app/models/project.rb b/app/models/project.rb index 7edc5970b5b..452a5c8973c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -475,61 +475,63 @@ class Project < ApplicationRecord accepts_nested_attributes_for :prometheus_integration, update_only: true accepts_nested_attributes_for :alerting_setting, update_only: true - delegate :merge_requests_access_level, :forking_access_level, :issues_access_level, - :wiki_access_level, :snippets_access_level, :builds_access_level, - :repository_access_level, :package_registry_access_level, :pages_access_level, - :metrics_dashboard_access_level, :analytics_access_level, - :operations_access_level, :security_and_compliance_access_level, - :container_registry_access_level, :environments_access_level, :feature_flags_access_level, - :monitor_access_level, :releases_access_level, :infrastructure_access_level, - :model_experiments_access_level, - to: :project_feature, allow_nil: true - - delegate :show_default_award_emojis, :show_default_award_emojis=, - :enforce_auth_checks_on_uploads, :enforce_auth_checks_on_uploads=, - :warn_about_potentially_unwanted_characters, :warn_about_potentially_unwanted_characters=, - to: :project_setting, allow_nil: true - - delegate :show_diff_preview_in_email, :show_diff_preview_in_email=, :show_diff_preview_in_email?, - :runner_registration_enabled, :runner_registration_enabled?, :runner_registration_enabled=, - to: :project_setting - - delegate :squash_always?, :squash_never?, :squash_enabled_by_default?, :squash_readonly?, to: :project_setting - delegate :squash_option, :squash_option=, to: :project_setting - delegate :mr_default_target_self, :mr_default_target_self=, to: :project_setting - delegate :previous_default_branch, :previous_default_branch=, to: :project_setting + delegate :merge_requests_access_level, :forking_access_level, :issues_access_level, :wiki_access_level, :snippets_access_level, :builds_access_level, :repository_access_level, :package_registry_access_level, :pages_access_level, :metrics_dashboard_access_level, :analytics_access_level, :operations_access_level, :security_and_compliance_access_level, :container_registry_access_level, :environments_access_level, :feature_flags_access_level, :monitor_access_level, :releases_access_level, :infrastructure_access_level, :model_experiments_access_level, to: :project_feature, allow_nil: true delegate :name, to: :owner, allow_nil: true, prefix: true - delegate :members, to: :team, prefix: true - delegate :add_member, :add_members, :member?, to: :team - delegate :add_guest, :add_reporter, :add_developer, :add_maintainer, :add_owner, :add_role, to: :team - delegate :group_runners_enabled, :group_runners_enabled=, to: :ci_cd_settings, allow_nil: true - delegate :root_ancestor, to: :namespace, allow_nil: true + delegate :log_jira_dvcs_integration_usage, :jira_dvcs_server_last_sync_at, :jira_dvcs_cloud_last_sync_at, to: :feature_usage delegate :last_pipeline, to: :commit, allow_nil: true - delegate :external_dashboard_url, to: :metrics_setting, allow_nil: true, prefix: true - delegate :dashboard_timezone, to: :metrics_setting, allow_nil: true, prefix: true - delegate :default_git_depth, :default_git_depth=, to: :ci_cd_settings, prefix: :ci, allow_nil: true - delegate :forward_deployment_enabled, :forward_deployment_enabled=, to: :ci_cd_settings, prefix: :ci, allow_nil: true - delegate :job_token_scope_enabled, :job_token_scope_enabled=, to: :ci_cd_settings, prefix: :ci_outbound, allow_nil: true - delegate :inbound_job_token_scope_enabled, :inbound_job_token_scope_enabled=, to: :ci_cd_settings, prefix: :ci, allow_nil: true - delegate :keep_latest_artifact, :keep_latest_artifact=, to: :ci_cd_settings, allow_nil: true - delegate :allow_fork_pipelines_to_run_in_parent_project, :allow_fork_pipelines_to_run_in_parent_project=, to: :ci_cd_settings, prefix: :ci, allow_nil: true - delegate :restrict_user_defined_variables, :restrict_user_defined_variables=, to: :ci_cd_settings, allow_nil: true - delegate :separated_caches, :separated_caches=, to: :ci_cd_settings, prefix: :ci, allow_nil: true - delegate :runner_token_expiration_interval, :runner_token_expiration_interval=, :runner_token_expiration_interval_human_readable, :runner_token_expiration_interval_human_readable=, to: :ci_cd_settings, allow_nil: true - delegate :actual_limits, :actual_plan_name, :actual_plan, to: :namespace, allow_nil: true - delegate :allow_merge_on_skipped_pipeline, :allow_merge_on_skipped_pipeline?, - :allow_merge_on_skipped_pipeline=, :has_confluence?, :has_shimo?, - to: :project_setting - delegate :merge_commit_template, :merge_commit_template=, to: :project_setting, allow_nil: true - delegate :squash_commit_template, :squash_commit_template=, to: :project_setting, allow_nil: true - delegate :issue_branch_template, :issue_branch_template=, to: :project_setting, allow_nil: true - delegate :log_jira_dvcs_integration_usage, :jira_dvcs_server_last_sync_at, :jira_dvcs_cloud_last_sync_at, to: :feature_usage + with_options to: :team do + delegate :members, prefix: true + delegate :add_member, :add_members, :member? + delegate :add_guest, :add_reporter, :add_developer, :add_maintainer, :add_owner, :add_role + end + + with_options to: :metrics_setting, allow_nil: true, prefix: true do + delegate :external_dashboard_url + delegate :dashboard_timezone + end + + with_options to: :namespace do + delegate :actual_limits, :actual_plan_name, :actual_plan, :root_ancestor, allow_nil: true + delegate :maven_package_requests_forwarding, :pypi_package_requests_forwarding, :npm_package_requests_forwarding + end - delegate :maven_package_requests_forwarding, - :pypi_package_requests_forwarding, - :npm_package_requests_forwarding, - to: :namespace + with_options to: :ci_cd_settings, allow_nil: true do + delegate :group_runners_enabled, :group_runners_enabled= + delegate :keep_latest_artifact, :keep_latest_artifact= + delegate :restrict_user_defined_variables, :restrict_user_defined_variables= + delegate :runner_token_expiration_interval, :runner_token_expiration_interval=, :runner_token_expiration_interval_human_readable, :runner_token_expiration_interval_human_readable= + delegate :job_token_scope_enabled, :job_token_scope_enabled=, prefix: :ci_outbound + + with_options prefix: :ci do + delegate :default_git_depth, :default_git_depth= + delegate :forward_deployment_enabled, :forward_deployment_enabled= + delegate :inbound_job_token_scope_enabled, :inbound_job_token_scope_enabled= + delegate :allow_fork_pipelines_to_run_in_parent_project, :allow_fork_pipelines_to_run_in_parent_project= + delegate :separated_caches, :separated_caches= + end + end + + with_options to: :project_setting do + delegate :allow_merge_on_skipped_pipeline, :allow_merge_on_skipped_pipeline?, :allow_merge_on_skipped_pipeline= + delegate :has_confluence? + delegate :has_shimo? + delegate :show_diff_preview_in_email, :show_diff_preview_in_email=, :show_diff_preview_in_email? + delegate :runner_registration_enabled, :runner_registration_enabled=, :runner_registration_enabled? + delegate :squash_always?, :squash_never?, :squash_enabled_by_default?, :squash_readonly? + delegate :mr_default_target_self, :mr_default_target_self= + delegate :previous_default_branch, :previous_default_branch= + delegate :squash_option, :squash_option= + + with_options allow_nil: true do + delegate :merge_commit_template, :merge_commit_template= + delegate :squash_commit_template, :squash_commit_template= + delegate :issue_branch_template, :issue_branch_template= + delegate :show_default_award_emojis, :show_default_award_emojis= + delegate :enforce_auth_checks_on_uploads, :enforce_auth_checks_on_uploads= + delegate :warn_about_potentially_unwanted_characters, :warn_about_potentially_unwanted_characters= + end + end # Validations validates :creator, presence: true, on: :create diff --git a/app/models/release.rb b/app/models/release.rb index 10eb022b08b..7f74872cf67 100644 --- a/app/models/release.rb +++ b/app/models/release.rb @@ -56,6 +56,38 @@ class Release < ApplicationRecord MAX_NUMBER_TO_DISPLAY = 3 + class << self + # In the future, we should support `order_by=semver`; + # see https://gitlab.com/gitlab-org/gitlab/-/issues/352945 + def latest(order_by: 'released_at') + sort_by_attribute("#{order_by}_desc").first + end + + # This query uses LATERAL JOIN to find the latest release for each project. To avoid + # joining the `releases` table, we build an in-memory table using the project ids. + # Example: + # SELECT ... + # FROM (VALUES (PROJECT_ID_1),(PROJECT_ID_2)) project_ids (id) + # INNER JOIN LATERAL (...) + def latest_for_projects(projects, order_by: 'released_at') + return Release.none if projects.empty? + + projects_table = Project.arel_table + releases_table = Release.arel_table + + join_query = Release + .where(projects_table[:id].eq(releases_table[:project_id])) + .sort_by_attribute("#{order_by}_desc") + .limit(1) + + project_ids_list = projects.map { |project| "(#{project.id})" }.join(',') + + Release + .from("(VALUES #{project_ids_list}) projects (id)") + .joins("INNER JOIN LATERAL (#{join_query.to_sql}) #{Release.table_name} ON TRUE") + end + end + def to_param tag end diff --git a/app/services/projects/participants_service.rb b/app/services/projects/participants_service.rb index c29770d0c5f..8c807e0016b 100644 --- a/app/services/projects/participants_service.rb +++ b/app/services/projects/participants_service.rb @@ -45,7 +45,7 @@ module Projects def visible_groups visible_groups = project.invited_groups - unless project.team.owner?(current_user) + unless project.team.member?(current_user) visible_groups = visible_groups.public_or_visible_to_user(current_user) end |