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

Add latest changes from gitlab-org/gitlab@master

parent e4bf776a
No related branches found
No related tags found
No related merge requests found
Showing
with 155 additions and 39 deletions
Loading
Loading
@@ -64,6 +64,7 @@ export default {
this.groupId,
term,
{
search_namespaces: true,
with_issues_enabled: true,
with_shared: false,
include_subgroups: true,
Loading
Loading
Loading
Loading
@@ -54,6 +54,7 @@ const projectSelect = () => {
this.groupId,
query.term,
{
search_namespaces: true,
with_issues_enabled: this.withIssuesEnabled,
with_merge_requests_enabled: this.withMergeRequestsEnabled,
with_shared: this.withShared,
Loading
Loading
Loading
Loading
@@ -134,7 +134,9 @@ export default {
},
{
attrs: {
href: `${this.newBlobPath}/${this.currentPath ? escape(this.currentPath) : ''}`,
href: `${this.newBlobPath}/${
this.currentPath ? encodeURIComponent(this.currentPath) : ''
}`,
class: 'qa-new-file-option',
},
text: __('New file'),
Loading
Loading
Loading
Loading
@@ -25,10 +25,10 @@ export default {
const splitArray = this.path.split('/');
splitArray.pop();
 
return splitArray.join('/');
return splitArray.map(p => encodeURIComponent(p)).join('/');
},
parentRoute() {
return { path: `/-/tree/${escape(this.commitRef)}/${escape(this.parentPath)}` };
return { path: `/-/tree/${escape(this.commitRef)}/${this.parentPath}` };
},
},
methods: {
Loading
Loading
Loading
Loading
@@ -25,7 +25,7 @@ module Autocomplete
def execute
current_user
.projects_where_can_admin_issues
.optionally_search(search)
.optionally_search(search, include_namespace: true)
.excluding_project(project_id)
.eager_load_namespace_and_owner
.sorted_by_name_asc_limited(LIMIT)
Loading
Loading
Loading
Loading
@@ -17,6 +17,7 @@
# tags: string[]
# personal: boolean
# search: string
# search_namespaces: boolean
# non_archived: boolean
# archived: 'only' or boolean
# min_access_level: integer
Loading
Loading
@@ -171,7 +172,7 @@ class ProjectsFinder < UnionFinder
 
def by_search(items)
params[:search] ||= params[:name]
params[:search].present? ? items.search(params[:search]) : items
items.optionally_search(params[:search], include_namespace: params[:search_namespaces].present?)
end
 
def by_deleted_status(items)
Loading
Loading
# frozen_string_literal: true
module AlertEventLifecycle
extend ActiveSupport::Concern
included do
validates :started_at, presence: true
validates :status, presence: true
state_machine :status, initial: :none do
state :none, value: nil
state :firing, value: 0 do
validates :payload_key, presence: true
validates :ended_at, absence: true
end
state :resolved, value: 1 do
validates :ended_at, presence: true
end
event :fire do
transition none: :firing
end
event :resolve do
transition firing: :resolved
end
before_transition to: :firing do |alert_event, transition|
started_at = transition.args.first
alert_event.started_at = started_at
end
before_transition to: :resolved do |alert_event, transition|
ended_at = transition.args.first
alert_event.ended_at = ended_at || Time.current
end
end
scope :firing, -> { where(status: status_value_for(:firing)) }
scope :resolved, -> { where(status: status_value_for(:resolved)) }
scope :count_by_project_id, -> { group(:project_id).count }
def self.status_value_for(name)
state_machines[:status].states[name].value
end
end
end
Loading
Loading
@@ -12,8 +12,8 @@ module OptionallySearch
end
 
# Optionally limits a result set to those matching the given search query.
def optionally_search(query = nil)
query.present? ? search(query) : all
def optionally_search(query = nil, **options)
query.present? ? search(query, **options) : all
end
end
end
Loading
Loading
@@ -19,7 +19,6 @@ module ProtectedRefAccess
end
 
included do
scope :master, -> { maintainer } # @deprecated
scope :maintainer, -> { where(access_level: Gitlab::Access::MAINTAINER) }
scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
scope :by_user, -> (user) { where(user_id: user ) }
Loading
Loading
Loading
Loading
@@ -11,8 +11,5 @@ module SelectForProjectAuthorization
def select_as_maintainer_for_project_authorization
select(["projects.id AS project_id", "#{Gitlab::Access::MAINTAINER} AS access_level"])
end
# @deprecated
alias_method :select_as_master_for_project_authorization, :select_as_maintainer_for_project_authorization
end
end
Loading
Loading
@@ -14,6 +14,7 @@ class Environment < ApplicationRecord
has_many :successful_deployments, -> { success }, class_name: 'Deployment'
has_many :active_deployments, -> { active }, class_name: 'Deployment'
has_many :prometheus_alerts, inverse_of: :environment
has_many :self_managed_prometheus_alert_events, inverse_of: :environment
 
has_one :last_deployment, -> { success.order('deployments.id DESC') }, class_name: 'Deployment'
has_one :last_deployable, through: :last_deployment, source: 'deployable', source_type: 'CommitStatus'
Loading
Loading
Loading
Loading
@@ -245,9 +245,6 @@ class Group < Namespace
add_user(user, :maintainer, current_user: current_user)
end
 
# @deprecated
alias_method :add_master, :add_maintainer
def add_owner(user, current_user = nil)
add_user(user, :owner, current_user: current_user)
end
Loading
Loading
@@ -274,9 +271,6 @@ class Group < Namespace
::ContainerRepository.for_group_and_its_subgroups(self).exists?
end
 
# @deprecated
alias_method :has_master?, :has_maintainer?
# Check if user is a last owner of the group.
def last_owner?(user)
has_owner?(user) && members_with_parents.owners.size == 1
Loading
Loading
# frozen_string_literal: true
 
class LfsObjectsProject < ApplicationRecord
include ::EachBatch
belongs_to :project
belongs_to :lfs_object
 
Loading
Loading
Loading
Loading
@@ -76,10 +76,8 @@ class Member < ApplicationRecord
scope :developers, -> { active.where(access_level: DEVELOPER) }
scope :maintainers, -> { active.where(access_level: MAINTAINER) }
scope :non_guests, -> { where('members.access_level > ?', GUEST) }
scope :masters, -> { maintainers } # @deprecated
scope :owners, -> { active.where(access_level: OWNER) }
scope :owners, -> { active.where(access_level: OWNER) }
scope :owners_and_maintainers, -> { active.where(access_level: [OWNER, MAINTAINER]) }
scope :owners_and_masters, -> { owners_and_maintainers } # @deprecated
scope :with_user, -> (user) { where(user: user) }
 
scope :with_source_id, ->(source_id) { where(source_id: source_id) }
Loading
Loading
Loading
Loading
@@ -255,6 +255,8 @@ class Project < ApplicationRecord
 
has_many :prometheus_metrics
has_many :prometheus_alerts, inverse_of: :project
has_many :prometheus_alert_events, inverse_of: :project
has_many :self_managed_prometheus_alert_events, inverse_of: :project
 
# Container repositories need to remove data from the container registry,
# which is not managed by the DB. Hence we're still using dependent: :destroy
Loading
Loading
@@ -349,7 +351,6 @@ class Project < ApplicationRecord
delegate :members, to: :team, prefix: true
delegate :add_user, :add_users, to: :team
delegate :add_guest, :add_reporter, :add_developer, :add_maintainer, :add_role, to: :team
delegate :add_master, to: :team # @deprecated
delegate :group_runners_enabled, :group_runners_enabled=, :group_runners_enabled?, to: :ci_cd_settings
delegate :root_ancestor, to: :namespace, allow_nil: true
delegate :last_pipeline, to: :commit, allow_nil: true
Loading
Loading
@@ -591,9 +592,9 @@ class Project < ApplicationRecord
# case-insensitive.
#
# query - The search query as a String.
def search(query)
if Feature.enabled?(:project_search_by_full_path, default_enabled: true)
joins(:route).fuzzy_search(query, [Route.arel_table[:path], :name, :description])
def search(query, include_namespace: false)
if include_namespace && Feature.enabled?(:project_search_by_full_path, default_enabled: true)
joins(:route).fuzzy_search(query, [Route.arel_table[:path], Route.arel_table[:name], :description])
else
fuzzy_search(query, [:path, :name, :description])
end
Loading
Loading
Loading
Loading
@@ -7,7 +7,6 @@ class ProjectGroupLink < ApplicationRecord
REPORTER = 20
DEVELOPER = 30
MAINTAINER = 40
MASTER = MAINTAINER # @deprecated
 
belongs_to :project
belongs_to :group
Loading
Loading
Loading
Loading
@@ -25,9 +25,6 @@ class ProjectTeam
add_user(user, :maintainer, current_user: current_user)
end
 
# @deprecated
alias_method :add_master, :add_maintainer
def add_role(user, role, current_user: nil)
public_send(:"add_#{role}", user, current_user: current_user) # rubocop:disable GitlabSecurity/PublicSend
end
Loading
Loading
@@ -98,9 +95,6 @@ class ProjectTeam
@maintainers ||= fetch_members(Gitlab::Access::MAINTAINER)
end
 
# @deprecated
alias_method :masters, :maintainers
def owners
@owners ||=
if group
Loading
Loading
@@ -156,9 +150,6 @@ class ProjectTeam
max_member_access(user.id) == Gitlab::Access::MAINTAINER
end
 
# @deprecated
alias_method :master?, :maintainer?
# Checks if `user` is authorized for this project, with at least the
# `min_access_level` (if given).
def member?(user, min_access_level = Gitlab::Access::GUEST)
Loading
Loading
# frozen_string_literal: true
class PrometheusAlertEvent < ApplicationRecord
include AlertEventLifecycle
belongs_to :project, optional: false, validate: true, inverse_of: :prometheus_alert_events
belongs_to :prometheus_alert, optional: false, validate: true, inverse_of: :prometheus_alert_events
has_and_belongs_to_many :related_issues, class_name: 'Issue', join_table: :issues_prometheus_alert_events # rubocop:disable Rails/HasAndBelongsToMany
validates :payload_key, uniqueness: { scope: :prometheus_alert_id }
validates :started_at, presence: true
delegate :title, :prometheus_metric_id, to: :prometheus_alert
scope :for_environment, -> (environment) do
joins(:prometheus_alert).where(prometheus_alerts: { environment_id: environment })
end
scope :with_prometheus_alert, -> { includes(:prometheus_alert) }
def self.last_by_project_id
ids = select(arel_table[:id].maximum.as('id')).group(:project_id).map(&:id)
with_prometheus_alert.find(ids)
end
def self.find_or_initialize_by_payload_key(project, alert, payload_key)
find_or_initialize_by(project: project, prometheus_alert: alert, payload_key: payload_key)
end
def self.find_by_payload_key(payload_key)
find_by(payload_key: payload_key)
end
def self.status_value_for(name)
state_machines[:status].states[name].value
end
def self.payload_key_for(gitlab_alert_id, started_at)
plain = [gitlab_alert_id, started_at].join('/')
Digest::SHA1.hexdigest(plain)
end
end
# frozen_string_literal: true
class SelfManagedPrometheusAlertEvent < ApplicationRecord
include AlertEventLifecycle
belongs_to :project, validate: true, inverse_of: :self_managed_prometheus_alert_events
belongs_to :environment, validate: true, inverse_of: :self_managed_prometheus_alert_events
has_and_belongs_to_many :related_issues, class_name: 'Issue', join_table: :issues_self_managed_prometheus_alert_events # rubocop:disable Rails/HasAndBelongsToMany
validates :started_at, presence: true
validates :payload_key, uniqueness: { scope: :project_id }
def self.find_or_initialize_by_payload_key(project, payload_key)
find_or_initialize_by(project: project, payload_key: payload_key) do |event|
yield event if block_given?
end
end
def self.payload_key_for(started_at, alert_name, query_expression)
plain = [started_at, alert_name, query_expression].join('/')
Digest::SHA1.hexdigest(plain)
end
end
Loading
Loading
@@ -48,15 +48,27 @@ class SnippetRepository < ApplicationRecord
next_index = get_last_empty_file_index + 1
 
files.each do |file_entry|
file_entry[:file_path] = file_path_for(file_entry, next_index) { next_index += 1 }
file_entry[:action] = infer_action(file_entry) unless file_entry[:action]
if file_entry[:file_path].blank?
file_entry[:file_path] = build_empty_file_name(next_index)
next_index += 1
end
end
end
 
def file_path_for(file_entry, next_index)
return file_entry[:file_path] if file_entry[:file_path].present?
return file_entry[:previous_path] if reuse_previous_path?(file_entry)
build_empty_file_name(next_index).tap { yield }
end
# If the user removed the file_path and the previous_path
# matches the EMPTY_FILE_PATTERN, we don't need to
# rename the file and build a new empty file name,
# we can just reuse the existing file name
def reuse_previous_path?(file_entry)
file_entry[:file_path].blank? &&
EMPTY_FILE_PATTERN.match?(file_entry[:previous_path])
end
def infer_action(file_entry)
return :create if file_entry[:previous_path].blank?
 
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