Skip to content
Snippets Groups Projects
Commit 27d91a62 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 5e11c9b7
No related branches found
No related tags found
No related merge requests found
Showing
with 230 additions and 34 deletions
Loading
Loading
@@ -100,9 +100,6 @@ export default {
hasOnlyOneJob(stage) {
return stage.groups.length === 1;
},
hasDownstream(index, length) {
return index === length - 1 && this.hasTriggered;
},
hasUpstream(index) {
return index === 0 && this.hasTriggeredBy;
},
Loading
Loading
@@ -160,7 +157,6 @@ export default {
:key="stage.name"
:class="{
'has-upstream prepend-left-64': hasUpstream(index),
'has-downstream': hasDownstream(index, graph.length),
'has-only-one-job': hasOnlyOneJob(stage),
'append-right-46': shouldAddRightMargin(index),
}"
Loading
Loading
<script>
import LinkedPipeline from './linked_pipeline.vue';
import { __ } from '~/locale';
 
export default {
components: {
Loading
Loading
@@ -27,6 +28,9 @@ export default {
};
return `graph-position-${this.graphPosition} ${positionValues[this.graphPosition]}`;
},
isUpstream() {
return this.columnTitle === __('Upstream');
},
},
};
</script>
Loading
Loading
@@ -34,13 +38,12 @@ export default {
<template>
<div :class="columnClass" class="stage-column linked-pipelines-column">
<div class="stage-name linked-pipelines-column-title">{{ columnTitle }}</div>
<div class="cross-project-triangle"></div>
<div v-if="isUpstream" class="cross-project-triangle"></div>
<ul>
<linked-pipeline
v-for="(pipeline, index) in linkedPipelines"
:key="pipeline.id"
:class="{
'flat-connector-before': index === 0 && graphPosition === 'right',
active: pipeline.isExpanded,
'left-connector': pipeline.isExpanded && graphPosition === 'left',
}"
Loading
Loading
Loading
Loading
@@ -473,6 +473,7 @@ table.code {
text-align: right;
width: 50px;
position: relative;
white-space: nowrap;
 
a {
transition: none;
Loading
Loading
Loading
Loading
@@ -61,6 +61,7 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController
message
starts_at
target_path
broadcast_type
))
end
end
Loading
Loading
@@ -9,6 +9,7 @@ class BroadcastMessage < ApplicationRecord
validates :message, presence: true
validates :starts_at, presence: true
validates :ends_at, presence: true
validates :broadcast_type, presence: true
 
validates :color, allow_blank: true, color: true
validates :font, allow_blank: true, color: true
Loading
Loading
@@ -17,35 +18,62 @@ class BroadcastMessage < ApplicationRecord
default_value_for :font, '#FFFFFF'
 
CACHE_KEY = 'broadcast_message_current_json'
BANNER_CACHE_KEY = 'broadcast_message_current_banner_json'
NOTIFICATION_CACHE_KEY = 'broadcast_message_current_notification_json'
 
after_commit :flush_redis_cache
 
def self.current(current_path = nil)
messages = cache.fetch(CACHE_KEY, as: BroadcastMessage, expires_in: cache_expires_in) do
current_and_future_messages
enum broadcast_type: {
banner: 1,
notification: 2
}
class << self
def current_banner_messages(current_path = nil)
fetch_messages BANNER_CACHE_KEY, current_path do
current_and_future_messages.banner
end
end
 
return [] unless messages&.present?
def current_notification_messages(current_path = nil)
fetch_messages NOTIFICATION_CACHE_KEY, current_path do
current_and_future_messages.notification
end
end
 
now_or_future = messages.select(&:now_or_future?)
def current(current_path = nil)
fetch_messages CACHE_KEY, current_path do
current_and_future_messages
end
end
 
# If there are cached entries but none are to be displayed we'll purge the
# cache so we don't keep running this code all the time.
cache.expire(CACHE_KEY) if now_or_future.empty?
def current_and_future_messages
where('ends_at > :now', now: Time.current).order_id_asc
end
 
now_or_future.select(&:now?).select { |message| message.matches_current_path(current_path) }
end
def cache
Gitlab::JsonCache.new(cache_key_with_version: false)
end
 
def self.current_and_future_messages
where('ends_at > :now', now: Time.zone.now).order_id_asc
end
def cache_expires_in
2.weeks
end
 
def self.cache
Gitlab::JsonCache.new(cache_key_with_version: false)
end
private
def fetch_messages(cache_key, current_path)
messages = cache.fetch(cache_key, as: BroadcastMessage, expires_in: cache_expires_in) do
yield
end
now_or_future = messages.select(&:now_or_future?)
 
def self.cache_expires_in
2.weeks
# If there are cached entries but none are to be displayed we'll purge the
# cache so we don't keep running this code all the time.
cache.expire(cache_key) if now_or_future.empty?
now_or_future.select(&:now?).select { |message| message.matches_current_path(current_path) }
end
end
 
def active?
Loading
Loading
@@ -53,19 +81,19 @@ class BroadcastMessage < ApplicationRecord
end
 
def started?
Time.zone.now >= starts_at
Time.current >= starts_at
end
 
def ended?
ends_at < Time.zone.now
ends_at < Time.current
end
 
def now?
(starts_at..ends_at).cover?(Time.zone.now)
(starts_at..ends_at).cover?(Time.current)
end
 
def future?
starts_at > Time.zone.now
starts_at > Time.current
end
 
def now_or_future?
Loading
Loading
@@ -79,7 +107,9 @@ class BroadcastMessage < ApplicationRecord
end
 
def flush_redis_cache
self.class.cache.expire(CACHE_KEY)
[CACHE_KEY, BANNER_CACHE_KEY, NOTIFICATION_CACHE_KEY].each do |key|
self.class.cache.expire(key)
end
end
end
 
Loading
Loading
Loading
Loading
@@ -281,6 +281,10 @@ class Commit
project.notes.for_commit_id(self.id)
end
 
def user_mentions
CommitUserMention.where(commit_id: self.id)
end
def discussion_notes
notes.non_diff_notes
end
Loading
Loading
# frozen_string_literal: true
class CommitUserMention < UserMention
belongs_to :note
end
Loading
Loading
@@ -80,6 +80,66 @@ module Mentionable
all_references(current_user).users
end
 
def store_mentions!
# if store_mentioned_users_to_db feature flag is not enabled then consider storing operation as succeeded
# because we wrap this method in transaction with with_transaction_returning_status, and we need the status to be
# successful if mentionable.save is successful.
#
# This line will get removed when we remove the feature flag.
return true unless store_mentioned_users_to_db_enabled?
refs = all_references(self.author)
references = {}
references[:mentioned_users_ids] = refs.mentioned_users&.pluck(:id).presence
references[:mentioned_groups_ids] = refs.mentioned_groups&.pluck(:id).presence
references[:mentioned_projects_ids] = refs.mentioned_projects&.pluck(:id).presence
# One retry should be enough as next time `model_user_mention` should return the existing mention record, that
# threw the `ActiveRecord::RecordNotUnique` exception in first place.
self.class.safe_ensure_unique(retries: 1) do
user_mention = model_user_mention
user_mention.mentioned_users_ids = references[:mentioned_users_ids]
user_mention.mentioned_groups_ids = references[:mentioned_groups_ids]
user_mention.mentioned_projects_ids = references[:mentioned_projects_ids]
if user_mention.has_mentions?
user_mention.save!
elsif user_mention.persisted?
user_mention.destroy!
end
true
end
end
def referenced_users
User.where(id: user_mentions.select("unnest(mentioned_users_ids)"))
end
def referenced_projects(current_user = nil)
Project.where(id: user_mentions.select("unnest(mentioned_projects_ids)")).public_or_visible_to_user(current_user)
end
def referenced_project_users(current_user = nil)
User.joins(:project_members).where(members: { source_id: referenced_projects(current_user) }).distinct
end
def referenced_groups(current_user = nil)
# TODO: IMPORTANT: Revisit before using it.
# Check DB data for max mentioned groups per mentionable:
#
# select issue_id, count(mentions_count.men_gr_id) gr_count from
# (select DISTINCT unnest(mentioned_groups_ids) as men_gr_id, issue_id
# from issue_user_mentions group by issue_id, mentioned_groups_ids) as mentions_count
# group by mentions_count.issue_id order by gr_count desc limit 10
Group.where(id: user_mentions.select("unnest(mentioned_groups_ids)")).public_or_visible_to_user(current_user)
end
def referenced_group_users(current_user = nil)
User.joins(:group_members).where(members: { source_id: referenced_groups }).distinct
end
def directly_addressed_users(current_user = nil)
all_references(current_user).directly_addressed_users
end
Loading
Loading
@@ -171,6 +231,26 @@ module Mentionable
def mentionable_params
{}
end
# User mention that is parsed from model description rather then its related notes.
# Models that have a descriprion attribute like Issue, MergeRequest, Epic, Snippet may have such a user mention.
# Other mentionable models like Commit, DesignManagement::Design, will never have such record as those do not have
# a description attribute.
#
# Using this method followed by a call to *save* may result in *ActiveRecord::RecordNotUnique* exception
# in a multithreaded environment. Make sure to use it within a *safe_ensure_unique* block.
def model_user_mention
user_mentions.where(note_id: nil).first_or_initialize
end
# We need this method to be checking that store_mentioned_users_to_db feature flag is enabled at the group level
# and not the project level as epics are defined at group level and we want to have epics store user mentions as well
# for the test period.
# During the test period the flag should be enabled at the group level.
def store_mentioned_users_to_db_enabled?
return Feature.enabled?(:store_mentioned_users_to_db, self.project&.group) if self.respond_to?(:project)
return Feature.enabled?(:store_mentioned_users_to_db, self.group) if self.respond_to?(:group)
end
end
 
Mentionable.prepend_if_ee('EE::Mentionable')
Loading
Loading
@@ -42,6 +42,7 @@ class Issue < ApplicationRecord
has_many :issue_assignees
has_many :assignees, class_name: "User", through: :issue_assignees
has_many :zoom_meetings
has_many :user_mentions, class_name: "IssueUserMention"
has_one :sentry_issue
 
validates :project, presence: true
Loading
Loading
# frozen_string_literal: true
class IssueUserMention < UserMention
belongs_to :issue
belongs_to :note
end
Loading
Loading
@@ -71,6 +71,7 @@ class MergeRequest < ApplicationRecord
 
has_many :merge_request_assignees
has_many :assignees, class_name: "User", through: :merge_request_assignees
has_many :user_mentions, class_name: "MergeRequestUserMention"
 
has_many :deployment_merge_requests
 
Loading
Loading
# frozen_string_literal: true
class MergeRequestUserMention < UserMention
belongs_to :merge_request
belongs_to :note
end
Loading
Loading
@@ -499,8 +499,18 @@ class Note < ApplicationRecord
project
end
 
def user_mentions
noteable.user_mentions.where(note: self)
end
private
 
# Using this method followed by a call to `save` may result in ActiveRecord::RecordNotUnique exception
# in a multithreaded environment. Make sure to use it within a `safe_ensure_unique` block.
def model_user_mention
user_mentions.first_or_initialize
end
def system_note_viewable_by?(user)
return true unless system_note_metadata
 
Loading
Loading
Loading
Loading
@@ -37,6 +37,7 @@ class Snippet < ApplicationRecord
belongs_to :project
 
has_many :notes, as: :noteable, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :user_mentions, class_name: "SnippetUserMention"
 
delegate :name, :email, to: :author, prefix: true, allow_nil: true
 
Loading
Loading
@@ -69,6 +70,8 @@ class Snippet < ApplicationRecord
scope :inc_author, -> { includes(:author) }
scope :inc_relations_for_view, -> { includes(author: :status) }
 
attr_mentionable :description
participant :author
participant :notes_with_associations
 
Loading
Loading
# frozen_string_literal: true
class SnippetUserMention < UserMention
belongs_to :snippet
belongs_to :note
end
# frozen_string_literal: true
class UserMention < ApplicationRecord
self.abstract_class = true
def has_mentions?
mentioned_users_ids.present? || mentioned_groups_ids.present? || mentioned_projects_ids.present?
end
private
def mentioned_users
User.where(id: mentioned_users_ids)
end
def mentioned_groups
Group.where(id: mentioned_groups_ids)
end
def mentioned_projects
Project.where(id: mentioned_projects_ids)
end
end
Loading
Loading
@@ -21,7 +21,11 @@ class CreateSnippetService < BaseService
 
spam_check(snippet, current_user)
 
if snippet.save
snippet_saved = snippet.with_transaction_returning_status do
snippet.save && snippet.store_mentions!
end
if snippet_saved
UserAgentDetailService.new(snippet, @request).create
Gitlab::UsageDataCounters::SnippetCounter.count(:create)
end
Loading
Loading
Loading
Loading
@@ -163,7 +163,11 @@ class IssuableBaseService < BaseService
 
before_create(issuable)
 
if issuable.save
issuable_saved = issuable.with_transaction_returning_status do
issuable.save && issuable.store_mentions!
end
if issuable_saved
Issuable::CommonSystemNotesService.new(project, current_user).execute(issuable, is_update: false)
 
after_create(issuable)
Loading
Loading
@@ -224,7 +228,11 @@ class IssuableBaseService < BaseService
update_project_counters = issuable.project && update_project_counter_caches?(issuable)
ensure_milestone_available(issuable)
 
if issuable.with_transaction_returning_status { issuable.save(touch: should_touch) }
issuable_saved = issuable.with_transaction_returning_status do
issuable.save(touch: should_touch) && issuable.store_mentions!
end
if issuable_saved
Issuable::CommonSystemNotesService.new(project, current_user).execute(issuable, old_labels: old_associations[:labels])
 
handle_changes(issuable, old_associations: old_associations)
Loading
Loading
Loading
Loading
@@ -33,7 +33,11 @@ module Notes
NewNoteWorker.perform_async(note.id)
end
 
if !only_commands && note.save
note_saved = note.with_transaction_returning_status do
!only_commands && note.save && note.store_mentions!
end
if note_saved
if note.part_of_discussion? && note.discussion.can_convert_to_discussion?
note.discussion.convert_to_discussion!(save: true)
end
Loading
Loading
Loading
Loading
@@ -7,7 +7,11 @@ module Notes
 
old_mentioned_users = note.mentioned_users(current_user).to_a
 
note.update(params.merge(updated_by: current_user))
note.assign_attributes(params.merge(updated_by: current_user))
note.with_transaction_returning_status do
note.save && note.store_mentions!
end
 
only_commands = false
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment