Read about our upcoming Code of Conduct on this issue

Commit a61f5e5a authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent cbb74dc8e9d3
......@@ -31,7 +31,6 @@ rules:
- error
- allowElseIf: true
import/no-cycle: warn
import/no-unresolved: warn
import/no-useless-path-segments: off
import/order: warn
lines-between-class-members: off
......
......@@ -20,11 +20,11 @@ class ApplicationController < ActionController::Base
before_action :authenticate_user!, except: [:route_not_found]
before_action :enforce_terms!, if: :should_enforce_terms?
before_action :validate_user_service_ticket!
before_action :check_password_expiration
before_action :check_password_expiration, if: :html_request?
before_action :ldap_security_check
before_action :sentry_context
before_action :default_headers
before_action :add_gon_variables, unless: [:peek_request?, :json_request?]
before_action :add_gon_variables, if: :html_request?
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :require_email, unless: :devise_controller?
before_action :active_user_check, unless: :devise_controller?
......@@ -455,8 +455,8 @@ def set_page_title_header
response.headers['Page-Title'] = URI.escape(page_title('GitLab'))
end
def peek_request?
request.path.start_with?('/-/peek')
def html_request?
request.format.html?
end
def json_request?
......@@ -466,7 +466,7 @@ def json_request?
def should_enforce_terms?
return false unless Gitlab::CurrentSettings.current_application_settings.enforce_terms
!(peek_request? || devise_controller?)
html_request? && !devise_controller?
end
def set_usage_stats_consent_flag
......
......@@ -4,15 +4,18 @@ module ConfirmEmailWarning
extend ActiveSupport::Concern
included do
before_action :set_confirm_warning, if: -> { Feature.enabled?(:soft_email_confirmation) }
before_action :set_confirm_warning, if: :show_confirm_warning?
end
protected
def show_confirm_warning?
html_request? && request.get? && Feature.enabled?(:soft_email_confirmation)
end
def set_confirm_warning
return unless current_user
return if current_user.confirmed?
return if peek_request? || json_request? || !request.get?
email = current_user.unconfirmed_email || current_user.email
......
......@@ -4,7 +4,7 @@ module SourcegraphGon
extend ActiveSupport::Concern
included do
before_action :push_sourcegraph_gon, unless: :json_request?
before_action :push_sourcegraph_gon, if: :html_request?
end
private
......
# frozen_string_literal: true
module UploadsActions
extend ActiveSupport::Concern
include Gitlab::Utils::StrongMemoize
include SendFileUpload
UPLOAD_MOUNTS = %w(avatar attachment file logo header_logo favicon).freeze
included do
prepend_before_action :set_request_format_from_path_extension
end
def create
uploader = UploadService.new(model, params[:file], uploader_class).execute
......@@ -64,6 +69,20 @@ def authorize
private
# Based on ActionDispatch::Http::MimeNegotiation. We have an
# initializer that monkey-patches this method out (so that repository
# paths don't guess a format based on extension), but we do want this
# behavior when serving uploads.
def set_request_format_from_path_extension
path = request.headers['action_dispatch.original_path'] || request.headers['PATH_INFO']
if match = path&.match(/\.(\w+)\z/)
format = Mime[match.captures.first]
request.format = format.symbol if format
end
end
def uploader_class
raise NotImplementedError
end
......
# frozen_string_literal: true
class InstanceStatistics::ConversationalDevelopmentIndexController < InstanceStatistics::ApplicationController
class InstanceStatistics::DevOpsScoreController < InstanceStatistics::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index
@metric = DevOpsScore::Metric.order(:created_at).last&.present
......
......@@ -46,7 +46,7 @@ def recent
def diverging_commit_counts
respond_to do |format|
format.json do
service = Branches::DivergingCommitCountsService.new(repository)
service = ::Branches::DivergingCommitCountsService.new(repository)
branches = BranchesFinder.new(repository, params.permit(names: [])).execute
Gitlab::GitalyClient.allow_n_plus_1_calls do
......@@ -63,7 +63,7 @@ def create
redirect_to_autodeploy = project.empty_repo? && project.deployment_platform.present?
result = CreateBranchService.new(project, current_user)
result = ::Branches::CreateService.new(project, current_user)
.execute(branch_name, ref)
success = (result[:status] == :success)
......@@ -102,7 +102,7 @@ def create
def destroy
@branch_name = Addressable::URI.unescape(params[:id])
result = DeleteBranchService.new(project, current_user).execute(@branch_name)
result = ::Branches::DeleteService.new(project, current_user).execute(@branch_name)
respond_to do |format|
format.html do
......@@ -118,7 +118,7 @@ def destroy
end
def destroy_all_merged
DeleteMergedBranchesService.new(@project, current_user).async_execute
::Branches::DeleteMergedService.new(@project, current_user).async_execute
redirect_to project_branches_path(@project),
notice: _('Merged branches are being deleted. This can take some time depending on the number of branches. Please refresh the page to see changes.')
......
# frozen_string_literal: true
module Clusters
class KnativeVersionRoleBindingFinder
attr_reader :cluster
def initialize(cluster)
@cluster = cluster
end
def execute
cluster&.kubeclient&.get_cluster_role_bindings&.find do |resource|
resource.metadata.name == Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_BINDING_NAME
end
end
end
end
# frozen_string_literal: true
module Mutations
module Issues
class SetConfidential < Base
graphql_name 'IssueSetConfidential'
argument :confidential,
GraphQL::BOOLEAN_TYPE,
required: true,
description: 'Whether or not to set the issue as a confidential.'
def resolve(project_path:, iid:, confidential:)
issue = authorized_find!(project_path: project_path, iid: iid)
project = issue.project
::Issues::UpdateService.new(project, current_user, confidential: confidential)
.execute(issue)
{
issue: issue,
errors: issue.errors.full_messages
}
end
end
end
end
......@@ -16,22 +16,21 @@ class MarkDone < ::Mutations::Todos::Base
null: false,
description: 'The requested todo'
# rubocop: disable CodeReuse/ActiveRecord
def resolve(id:)
todo = authorized_find!(id: id)
mark_done(Todo.where(id: todo.id)) unless todo.done?
mark_done(todo)
{
todo: todo.reset,
errors: errors_on_object(todo)
}
end
# rubocop: enable CodeReuse/ActiveRecord
private
def mark_done(todo)
TodoService.new.mark_todos_as_done(todo, current_user)
TodoService.new.mark_todo_as_done(todo, current_user)
end
end
end
......
......@@ -9,6 +9,7 @@ class MutationType < BaseObject
mount_mutation Mutations::AwardEmojis::Add
mount_mutation Mutations::AwardEmojis::Remove
mount_mutation Mutations::AwardEmojis::Toggle
mount_mutation Mutations::Issues::SetConfidential
mount_mutation Mutations::Issues::SetDueDate
mount_mutation Mutations::MergeRequests::SetLabels
mount_mutation Mutations::MergeRequests::SetLocked
......
......@@ -425,6 +425,18 @@ def expanded_environment_name
end
end
def expanded_kubernetes_namespace
return unless has_environment?
namespace = options.dig(:environment, :kubernetes, :namespace)
if namespace.present?
strong_memoize(:expanded_kubernetes_namespace) do
ExpandVariables.expand(namespace, -> { simple_variables })
end
end
end
def has_environment?
environment.present?
end
......
......@@ -63,7 +63,7 @@ class Kubernetes < ApplicationRecord
default_value_for :authorization_type, :rbac
def predefined_variables(project:, environment_name:)
def predefined_variables(project:, environment_name:, kubernetes_namespace: nil)
Gitlab::Ci::Variables::Collection.new.tap do |variables|
variables.append(key: 'KUBE_URL', value: api_url)
......@@ -74,15 +74,15 @@ def predefined_variables(project:, environment_name:)
end
if !cluster.managed? || cluster.management_project == project
namespace = Gitlab::Kubernetes::DefaultNamespace.new(cluster, project: project).from_environment_name(environment_name)
namespace = kubernetes_namespace || default_namespace(project, environment_name: environment_name)
variables
.append(key: 'KUBE_TOKEN', value: token, public: false, masked: true)
.append(key: 'KUBE_NAMESPACE', value: namespace)
.append(key: 'KUBECONFIG', value: kubeconfig(namespace), public: false, file: true)
elsif kubernetes_namespace = find_persisted_namespace(project, environment_name: environment_name)
variables.concat(kubernetes_namespace.predefined_variables)
elsif persisted_namespace = find_persisted_namespace(project, environment_name: environment_name)
variables.concat(persisted_namespace.predefined_variables)
end
variables.concat(cluster.predefined_variables)
......@@ -107,6 +107,13 @@ def kubeclient
private
def default_namespace(project, environment_name:)
Gitlab::Kubernetes::DefaultNamespace.new(
cluster,
project: project
).from_environment_name(environment_name)
end
def find_persisted_namespace(project, environment_name:)
Clusters::KubernetesNamespaceFinder.new(
cluster,
......
......@@ -15,7 +15,7 @@ def scoped_variables(environment: expanded_environment_name)
variables.concat(project.predefined_variables)
variables.concat(pipeline.predefined_variables)
variables.concat(runner.predefined_variables) if runnable? && runner
variables.concat(project.deployment_variables(environment: environment)) if environment
variables.concat(deployment_variables(environment: environment))
variables.concat(yaml_variables)
variables.concat(user_variables)
variables.concat(secret_group_variables)
......@@ -72,6 +72,15 @@ def predefined_variables
end
end
def deployment_variables(environment:)
return [] unless environment
project.deployment_variables(
environment: environment,
kubernetes_namespace: expanded_kubernetes_namespace
)
end
def secret_group_variables
return [] unless project.group
......
......@@ -22,4 +22,8 @@ def self.build_collection(groups, params)
def dashboard_milestone?
true
end
def merge_requests_enabled?
true
end
end
......@@ -12,4 +12,8 @@ def initialize(milestone)
def project_milestone?
true
end
def merge_requests_enabled?
project.merge_requests_enabled?
end
end
......@@ -41,4 +41,8 @@ def issues_finder_params
def legacy_group_milestone?
true
end
def merge_requests_enabled?
true
end
end
......@@ -274,6 +274,16 @@ def project_milestone?
project_id.present?
end
def merge_requests_enabled?
if group_milestone?
# Assume that groups have at least one project with merge requests enabled.
# Otherwise, we would need to load all of the projects from the database.
true
elsif project_milestone?
project&.merge_requests_enabled?
end
end
private
# Milestone titles must be unique across project milestones and group milestones
......
......@@ -1986,12 +1986,16 @@ def protected_for?(ref)
end
end
def deployment_variables(environment:)
def deployment_variables(environment:, kubernetes_namespace: nil)
platform = deployment_platform(environment: environment)
return [] unless platform.present?
platform.predefined_variables(project: self, environment_name: environment)
platform.predefined_variables(
project: self,
environment_name: environment,
kubernetes_namespace: kubernetes_namespace
)
end
def auto_devops_variables
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment