diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-11 21:08:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-11 21:08:40 +0300 |
commit | 33f7ef81fd6bcab7bbdf0bc3f37d337256fb11fb (patch) | |
tree | da5c4d1d60ca6674523ca431a285d78dab2917aa /app | |
parent | ed94a4dd903dc4d20cbc1bce330b9c1b7a5f7fbf (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/main.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/pages/projects/index.js | 2 | ||||
-rw-r--r-- | app/assets/stylesheets/fonts.scss | 23 | ||||
-rw-r--r-- | app/controllers/pwa_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 19 | ||||
-rw-r--r-- | app/models/analytics/cycle_analytics/project_stage.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/analytics/cycle_analytics/stageable.rb (renamed from app/models/concerns/analytics/cycle_analytics/stage.rb) | 56 | ||||
-rw-r--r-- | app/models/concerns/work_item_resource_event.rb | 23 | ||||
-rw-r--r-- | app/models/label_note.rb | 15 | ||||
-rw-r--r-- | app/models/resource_event.rb | 6 | ||||
-rw-r--r-- | app/models/resource_label_event.rb | 5 | ||||
-rw-r--r-- | app/models/resource_milestone_event.rb | 4 | ||||
-rw-r--r-- | app/models/resource_state_event.rb | 5 | ||||
-rw-r--r-- | app/models/resource_timebox_event.rb | 5 | ||||
-rw-r--r-- | app/services/search_service.rb | 19 | ||||
-rw-r--r-- | app/views/layouts/_loading_hints.html.haml | 3 |
16 files changed, 128 insertions, 63 deletions
diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 21d0bda6b5d..fd5c4abe729 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -30,6 +30,7 @@ import initLogoAnimation from './logo'; import initBreadcrumbs from './breadcrumb'; import initPersistentUserCallouts from './persistent_user_callouts'; import { initUserTracking, initDefaultTrackers } from './tracking'; +import { initSidebarTracking } from './pages/shared/nav/sidebar_tracking'; import initServicePingConsent from './service_ping_consent'; import GlFieldErrors from './gl_field_errors'; import initUserPopovers from './user_popovers'; @@ -99,6 +100,7 @@ function deferredInitialisation() { initBroadcastNotifications(); initPersistentUserCallouts(); initDefaultTrackers(); + initSidebarTracking(); initFeatureHighlight(); initCopyCodeButton(); initGitlabVersionCheck(); diff --git a/app/assets/javascripts/pages/projects/index.js b/app/assets/javascripts/pages/projects/index.js index 7380055cbbf..37cf345fe77 100644 --- a/app/assets/javascripts/pages/projects/index.js +++ b/app/assets/javascripts/pages/projects/index.js @@ -1,9 +1,7 @@ import ShortcutsNavigation from '~/behaviors/shortcuts/shortcuts_navigation'; import initTerraformNotification from '~/projects/terraform_notification'; -import { initSidebarTracking } from '../shared/nav/sidebar_tracking'; import Project from './project'; new Project(); // eslint-disable-line no-new new ShortcutsNavigation(); // eslint-disable-line no-new -initSidebarTracking(); initTerraformNotification(); diff --git a/app/assets/stylesheets/fonts.scss b/app/assets/stylesheets/fonts.scss index 7ff05f99e3c..a023b41083d 100644 --- a/app/assets/stylesheets/fonts.scss +++ b/app/assets/stylesheets/fonts.scss @@ -26,6 +26,29 @@ Usage: src: font-url('jetbrains-mono/JetBrainsMono.woff2') format('woff2'); } +@font-face { + font-family: 'JetBrains Mono'; + font-display: optional; + font-weight: bold; + src: font-url('jetbrains-mono/JetBrainsMono-Bold.woff2') format('woff2'); +} + +@font-face { + font-family: 'JetBrains Mono'; + font-display: optional; + font-weight: normal; + font-style: italic; + src: font-url('jetbrains-mono/JetBrainsMono-Italic.woff2') format('woff2'); +} + +@font-face { + font-family: 'JetBrains Mono'; + font-display: optional; + font-weight: bold; + font-style: italic; + src: font-url('jetbrains-mono/JetBrainsMono-BoldItalic.woff2') format('woff2'); +} + :root { --default-mono-font: 'JetBrains Mono', 'Menlo'; --default-regular-font: 'GitLab Sans', -apple-system; diff --git a/app/controllers/pwa_controller.rb b/app/controllers/pwa_controller.rb index 8de1b10e1f1..bb47bdc8050 100644 --- a/app/controllers/pwa_controller.rb +++ b/app/controllers/pwa_controller.rb @@ -6,7 +6,7 @@ class PwaController < ApplicationController # rubocop:disable Gitlab/NamespacedC feature_category :navigation urgency :low - skip_before_action :authenticate_user! + skip_before_action :authenticate_user!, :required_signup_info def manifest end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index ae5c112bcb8..38c773fa31d 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -212,24 +212,7 @@ class SearchController < ApplicationController def check_scope_global_search_enabled return unless search_service.global_search? - search_allowed = case params[:scope] - when 'blobs' - Feature.enabled?(:global_search_code_tab, current_user, type: :ops) - when 'commits' - Feature.enabled?(:global_search_commits_tab, current_user, type: :ops) - when 'issues' - Feature.enabled?(:global_search_issues_tab, current_user, type: :ops) - when 'merge_requests' - Feature.enabled?(:global_search_merge_requests_tab, current_user, type: :ops) - when 'wiki_blobs' - Feature.enabled?(:global_search_wiki_tab, current_user, type: :ops) - when 'users' - Feature.enabled?(:global_search_users_tab, current_user, type: :ops) - else - true - end - - return if search_allowed + return if search_service.global_search_enabled_for_scope? redirect_to search_path, alert: _('Global Search is disabled for this scope') end diff --git a/app/models/analytics/cycle_analytics/project_stage.rb b/app/models/analytics/cycle_analytics/project_stage.rb index 68fe43890bd..8a80514333f 100644 --- a/app/models/analytics/cycle_analytics/project_stage.rb +++ b/app/models/analytics/cycle_analytics/project_stage.rb @@ -3,7 +3,7 @@ module Analytics module CycleAnalytics class ProjectStage < ApplicationRecord - include Analytics::CycleAnalytics::Stage + include Analytics::CycleAnalytics::Stageable belongs_to :project, optional: false belongs_to :value_stream, class_name: 'Analytics::CycleAnalytics::ProjectValueStream', foreign_key: :project_value_stream_id diff --git a/app/models/concerns/analytics/cycle_analytics/stage.rb b/app/models/concerns/analytics/cycle_analytics/stageable.rb index 9293002109b..d1f948d1366 100644 --- a/app/models/concerns/analytics/cycle_analytics/stage.rb +++ b/app/models/concerns/analytics/cycle_analytics/stageable.rb @@ -2,7 +2,7 @@ module Analytics module CycleAnalytics - module Stage + module Stageable extend ActiveSupport::Concern include RelativePositioning include Gitlab::Utils::StrongMemoize @@ -10,7 +10,7 @@ module Analytics included do belongs_to :start_event_label, class_name: 'GroupLabel', optional: true belongs_to :end_event_label, class_name: 'GroupLabel', optional: true - belongs_to :stage_event_hash, class_name: 'Analytics::CycleAnalytics::StageEventHash', foreign_key: :stage_event_hash_id, optional: true + belongs_to :stage_event_hash, class_name: 'Analytics::CycleAnalytics::StageEventHash', optional: true validates :name, presence: true validates :name, exclusion: { in: Gitlab::Analytics::CycleAnalytics::DefaultStages.names }, if: :custom? @@ -21,39 +21,31 @@ module Analytics validate :validate_stage_event_pairs validate :validate_labels - enum start_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents.to_enum, _prefix: :start_event_identifier - enum end_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents.to_enum, _prefix: :end_event_identifier + enum start_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents.to_enum, + _prefix: :start_event_identifier + enum end_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents.to_enum, + _prefix: :end_event_identifier alias_attribute :custom_stage?, :custom scope :default_stages, -> { where(custom: false) } scope :ordered, -> { order(:relative_position, :id) } scope :with_preloaded_labels, -> { includes(:start_event_label, :end_event_label) } scope :for_list, -> { with_preloaded_labels.ordered } - scope :by_value_stream, -> (value_stream) { where(value_stream_id: value_stream.id) } + scope :by_value_stream, ->(value_stream) { where(value_stream_id: value_stream.id) } before_save :ensure_stage_event_hash_id after_commit :cleanup_old_stage_event_hash end - def parent=(_) - raise NotImplementedError - end - - def parent - raise NotImplementedError - end - def start_event - strong_memoize(:start_event) do - Gitlab::Analytics::CycleAnalytics::StageEvents[start_event_identifier].new(params_for_start_event) - end + Gitlab::Analytics::CycleAnalytics::StageEvents[start_event_identifier].new(params_for_start_event) end + strong_memoize_attr :start_event def end_event - strong_memoize(:end_event) do - Gitlab::Analytics::CycleAnalytics::StageEvents[end_event_identifier].new(params_for_end_event) - end + Gitlab::Analytics::CycleAnalytics::StageEvents[end_event_identifier].new(params_for_end_event) end + strong_memoize_attr :end_event def events_hash_code Digest::SHA256.hexdigest("#{start_event.hash_code}-#{end_event.hash_code}") @@ -109,9 +101,9 @@ module Analytics def validate_stage_event_pairs return if start_event_identifier.nil? || end_event_identifier.nil? - unless pairing_rules.fetch(start_event.class, []).include?(end_event.class) - errors.add(:end_event, s_('CycleAnalytics|not allowed for the given start event')) - end + return if pairing_rules.fetch(start_event.class, []).include?(end_event.class) + + errors.add(:end_event, s_('CycleAnalytics|not allowed for the given start event')) end def pairing_rules @@ -126,13 +118,13 @@ module Analytics def validate_label_within_namespace(association_name, label_id) return unless label_id - unless label_available_for_namespace?(label_id) - errors.add(association_name, s_('CycleAnalyticsStage|is not available for the selected group')) - end + return if label_available_for_namespace?(label_id) + + errors.add(association_name, s_('CycleAnalyticsStage|is not available for the selected group')) end def label_available_for_namespace?(label_id) - subject = is_a?(::Analytics::CycleAnalytics::GroupStage) ? namespace : project.group + subject = is_a?(::Analytics::CycleAnalytics::Stage) ? namespace : project.group return unless subject LabelsFinder.new(nil, { group_id: subject.id, include_ancestor_groups: true, only_group_labels: true }) @@ -144,15 +136,15 @@ module Analytics def ensure_stage_event_hash_id previous_stage_event_hash = stage_event_hash&.hash_sha256 - if previous_stage_event_hash.blank? || events_hash_code != previous_stage_event_hash - self.stage_event_hash_id = Analytics::CycleAnalytics::StageEventHash.record_id_by_hash_sha256(events_hash_code) - end + return unless previous_stage_event_hash.blank? || events_hash_code != previous_stage_event_hash + + self.stage_event_hash_id = Analytics::CycleAnalytics::StageEventHash.record_id_by_hash_sha256(events_hash_code) end def cleanup_old_stage_event_hash - if stage_event_hash_id_previously_changed? && stage_event_hash_id_previously_was - Analytics::CycleAnalytics::StageEventHash.cleanup_if_unused(stage_event_hash_id_previously_was) - end + return unless stage_event_hash_id_previously_changed? && stage_event_hash_id_previously_was + + Analytics::CycleAnalytics::StageEventHash.cleanup_if_unused(stage_event_hash_id_previously_was) end end end diff --git a/app/models/concerns/work_item_resource_event.rb b/app/models/concerns/work_item_resource_event.rb new file mode 100644 index 00000000000..d0323feb029 --- /dev/null +++ b/app/models/concerns/work_item_resource_event.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module WorkItemResourceEvent + extend ActiveSupport::Concern + + included do + belongs_to :work_item, foreign_key: 'issue_id' + end + + def work_item_synthetic_system_note(events: nil) + # System notes for label resource events are handled in batches, so that we have single system note for multiple + # label changes. + if is_a?(ResourceLabelEvent) && events.present? + return synthetic_note_class.from_events(events, resource: work_item, resource_parent: work_item.project) + end + + synthetic_note_class.from_event(self, resource: work_item, resource_parent: work_item.project) + end + + def synthetic_note_class + raise NoMethodError, 'must implement `synthetic_note_class` method' + end +end diff --git a/app/models/label_note.rb b/app/models/label_note.rb index 19dede36abd..eda650f2fa2 100644 --- a/app/models/label_note.rb +++ b/app/models/label_note.rb @@ -4,12 +4,19 @@ class LabelNote < SyntheticNote attr_accessor :resource_parent attr_reader :events + def self.from_event(event, resource: nil, resource_parent: nil) + attrs = note_attributes('label', event, resource, resource_parent).merge(events: [event]) + + LabelNote.new(attrs) + end + def self.from_events(events, resource: nil, resource_parent: nil) resource ||= events.first.issuable - attrs = note_attributes('label', events.first, resource, resource_parent).merge(events: events) + label_note = from_event(events.first, resource: resource, resource_parent: resource_parent) + label_note.events = events - LabelNote.new(attrs) + label_note end def events=(events) @@ -37,8 +44,8 @@ class LabelNote < SyntheticNote end def note_text(html: false) - added = labels_str(label_refs_by_action('add', html), prefix: 'added', suffix: added_suffix) - removed = labels_str(label_refs_by_action('remove', html), prefix: removed_prefix) + added = labels_str(label_refs_by_action('add', html).uniq, prefix: 'added', suffix: added_suffix) + removed = labels_str(label_refs_by_action('remove', html).uniq, prefix: removed_prefix) [added, removed].compact.join(' and ') end diff --git a/app/models/resource_event.rb b/app/models/resource_event.rb index 8b82e0f343c..551ea984132 100644 --- a/app/models/resource_event.rb +++ b/app/models/resource_event.rb @@ -3,6 +3,8 @@ class ResourceEvent < ApplicationRecord include Gitlab::Utils::StrongMemoize include Importable + include IssueResourceEvent + include WorkItemResourceEvent self.abstract_class = true @@ -18,6 +20,10 @@ class ResourceEvent < ApplicationRecord end end + def issuable + raise NoMethodError, 'must implement `issuable` method' + end + private def discussion_id_key diff --git a/app/models/resource_label_event.rb b/app/models/resource_label_event.rb index a1426540cf5..efffc1bd6dc 100644 --- a/app/models/resource_label_event.rb +++ b/app/models/resource_label_event.rb @@ -2,7 +2,6 @@ class ResourceLabelEvent < ResourceEvent include CacheMarkdownField - include IssueResourceEvent include MergeRequestResourceEvent cache_markdown_field :reference @@ -39,6 +38,10 @@ class ResourceLabelEvent < ResourceEvent issue || merge_request end + def synthetic_note_class + LabelNote + end + def project issuable.project end diff --git a/app/models/resource_milestone_event.rb b/app/models/resource_milestone_event.rb index 5fd71612de0..def7e91af3f 100644 --- a/app/models/resource_milestone_event.rb +++ b/app/models/resource_milestone_event.rb @@ -19,4 +19,8 @@ class ResourceMilestoneEvent < ResourceTimeboxEvent def milestone_parent milestone&.parent end + + def synthetic_note_class + MilestoneNote + end end diff --git a/app/models/resource_state_event.rb b/app/models/resource_state_event.rb index 6ebb9d5f176..134f71e35ad 100644 --- a/app/models/resource_state_event.rb +++ b/app/models/resource_state_event.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class ResourceStateEvent < ResourceEvent - include IssueResourceEvent include MergeRequestResourceEvent include Importable @@ -26,6 +25,10 @@ class ResourceStateEvent < ResourceEvent issue_id.present? end + def synthetic_note_class + StateNote + end + private def issue_usage_metrics diff --git a/app/models/resource_timebox_event.rb b/app/models/resource_timebox_event.rb index 26bf2a225d4..dddd4d0fe84 100644 --- a/app/models/resource_timebox_event.rb +++ b/app/models/resource_timebox_event.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true class ResourceTimeboxEvent < ResourceEvent - self.abstract_class = true - - include IssueResourceEvent include MergeRequestResourceEvent include Importable + self.abstract_class = true + validate :exactly_one_issuable, unless: :importing? enum action: { diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 403a2f077b0..b4344a009b2 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -112,6 +112,25 @@ class SearchService false end + def global_search_enabled_for_scope? + case params[:scope] + when 'blobs' + Feature.enabled?(:global_search_code_tab, current_user, type: :ops) + when 'commits' + Feature.enabled?(:global_search_commits_tab, current_user, type: :ops) + when 'issues' + Feature.enabled?(:global_search_issues_tab, current_user, type: :ops) + when 'merge_requests' + Feature.enabled?(:global_search_merge_requests_tab, current_user, type: :ops) + when 'wiki_blobs' + Feature.enabled?(:global_search_wiki_tab, current_user, type: :ops) + when 'users' + Feature.enabled?(:global_search_users_tab, current_user, type: :ops) + else + true + end + end + private def page diff --git a/app/views/layouts/_loading_hints.html.haml b/app/views/layouts/_loading_hints.html.haml index b1d1447ae2a..60ab6927fd2 100644 --- a/app/views/layouts/_loading_hints.html.haml +++ b/app/views/layouts/_loading_hints.html.haml @@ -18,4 +18,7 @@ -# See https://github.com/web-platform-tests/wpt/pull/36930 %link{ rel: 'preload', href: font_path('gitlab-sans/GitLabSans.woff2'), as: 'font', crossorigin: css_crossorigin } %link{ rel: 'preload', href: font_path('jetbrains-mono/JetBrainsMono.woff2'), as: 'font', crossorigin: css_crossorigin } + %link{ rel: 'preload', href: font_path('jetbrains-mono/JetBrainsMono-Bold.woff2'), as: 'font', crossorigin: css_crossorigin } + %link{ rel: 'preload', href: font_path('jetbrains-mono/JetBrainsMono-Italic.woff2'), as: 'font', crossorigin: css_crossorigin } + %link{ rel: 'preload', href: font_path('jetbrains-mono/JetBrainsMono-BoldItalic.woff2'), as: 'font', crossorigin: css_crossorigin } = preload_link_tag(path_to_stylesheet('fonts'), crossorigin: css_crossorigin) |