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

Add latest changes from gitlab-org/gitlab@master

parent 5ad0cf26
No related branches found
No related tags found
No related merge requests found
Showing
with 91 additions and 99 deletions
Loading
Loading
@@ -172,12 +172,6 @@ Lint/DuplicateMethods:
- 'lib/gitlab/git/tree.rb'
- 'lib/gitlab/git/wiki_page.rb'
 
# Offense count: 3
Lint/InterpolationCheck:
Exclude:
- 'spec/features/issues/filtered_search/filter_issues_spec.rb'
- 'spec/services/quick_actions/interpret_service_spec.rb'
# Offense count: 122
# Configuration parameters: MaximumRangeSize.
Lint/MissingCopEnableDirective:
Loading
Loading
@@ -275,13 +269,6 @@ RSpec/ItBehavesLike:
- 'spec/lib/gitlab/git/repository_spec.rb'
- 'spec/services/notification_service_spec.rb'
 
# Offense count: 3
RSpec/IteratedExpectation:
Exclude:
- 'spec/features/admin/admin_settings_spec.rb'
- 'spec/lib/gitlab/gitlab_import/client_spec.rb'
- 'spec/lib/gitlab/legacy_github_import/client_spec.rb'
# Offense count: 68
# Cop supports --auto-correct.
RSpec/LetBeforeExamples:
Loading
Loading
@@ -303,13 +290,6 @@ RSpec/MultipleSubjects:
Exclude:
- 'spec/services/merge_requests/create_from_issue_service_spec.rb'
 
# Offense count: 3
RSpec/OverwritingSetup:
Exclude:
- 'spec/models/email_spec.rb'
- 'spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb'
- 'spec/services/notes/quick_actions_service_spec.rb'
# Offense count: 2018
# Cop supports --auto-correct.
# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
Loading
Loading
@@ -556,13 +536,6 @@ Style/IfUnlessModifier:
Style/Lambda:
Enabled: false
 
# Offense count: 3
# Cop supports --auto-correct.
Style/LineEndConcatenation:
Exclude:
- 'spec/lib/gitlab/gfm/reference_rewriter_spec.rb'
- 'spec/lib/gitlab/incoming_email_spec.rb'
# Offense count: 17
Style/MethodMissingSuper:
Enabled: false
Loading
Loading
@@ -659,14 +632,6 @@ Style/PerlBackrefs:
Style/RaiseArgs:
Enabled: false
 
# Offense count: 3
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'app/models/merge_request.rb'
- 'app/services/projects/import_service.rb'
- 'lib/gitlab/health_checks/base_abstract_check.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantConditional:
Loading
Loading
@@ -771,14 +736,6 @@ Style/TernaryParentheses:
- 'spec/requests/api/pipeline_schedules_spec.rb'
- 'spec/support/capybara.rb'
 
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInArguments:
Exclude:
- 'spec/features/markdown/copy_as_gfm_spec.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline.
Loading
Loading
Loading
Loading
@@ -302,7 +302,7 @@ gem 'sentry-raven', '~> 2.9'
gem 'premailer-rails', '~> 1.10.3'
 
# LabKit: Tracing and Correlation
gem 'gitlab-labkit', '0.8.0'
gem 'gitlab-labkit', '0.9.1'
 
# I18n
gem 'ruby_parser', '~> 3.8', require: false
Loading
Loading
Loading
Loading
@@ -367,7 +367,7 @@ GEM
github-markup (1.7.0)
gitlab-chronic (0.10.5)
numerizer (~> 0.2)
gitlab-labkit (0.8.0)
gitlab-labkit (0.9.1)
actionpack (>= 5.0.0, < 6.1.0)
activesupport (>= 5.0.0, < 6.1.0)
grpc (~> 1.19)
Loading
Loading
@@ -1215,7 +1215,7 @@ DEPENDENCIES
gitaly (~> 1.81.0)
github-markup (~> 1.7.0)
gitlab-chronic (~> 0.10.5)
gitlab-labkit (= 0.8.0)
gitlab-labkit (= 0.9.1)
gitlab-license (~> 1.0)
gitlab-markup (~> 1.7.0)
gitlab-net-dns (~> 0.9.1)
Loading
Loading
Loading
Loading
@@ -454,6 +454,7 @@ class ApplicationController < ActionController::Base
user: -> { auth_user },
project: -> { @project },
namespace: -> { @group },
caller_id: full_action_name,
&block)
end
 
Loading
Loading
@@ -551,6 +552,10 @@ class ApplicationController < ActionController::Base
end
end
 
def full_action_name
"#{self.class.name}##{action_name}"
end
# A user requires a role and have the setup_for_company attribute set when they are part of the experimental signup
# flow (executed by the Growth team). Users are redirected to the welcome page when their role is required and the
# experiment is enabled for the current user.
Loading
Loading
Loading
Loading
@@ -821,7 +821,7 @@ class MergeRequest < ApplicationRecord
end
 
def check_mergeability(async: false)
return if Feature.enabled?(:merge_requests_conditional_mergeability_check, default_enabled: true) && !recheck_merge_status?
return unless recheck_merge_status?
 
check_service = MergeRequests::MergeabilityCheckService.new(self)
 
Loading
Loading
@@ -1201,12 +1201,10 @@ class MergeRequest < ApplicationRecord
end
 
def in_locked_state
begin
lock_mr
yield
ensure
unlock_mr
end
lock_mr
yield
ensure
unlock_mr
end
 
def diverged_commits_count
Loading
Loading
Loading
Loading
@@ -12,4 +12,8 @@ class SpamLog < ApplicationRecord
def text
[title, description].join("\n")
end
def self.verify_recaptcha!(id:, user_id:)
find_by(id: id, user_id: user_id)&.update!(recaptcha_verified: true)
end
end
Loading
Loading
@@ -22,14 +22,15 @@ module SpamCheckMethods
# a dirty instance, which means it should be already assigned with the new
# attribute values.
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def spam_check(spammable, user)
spam_service = SpamService.new(spammable: spammable, request: @request)
spam_service.when_recaptcha_verified(@recaptcha_verified, @api) do
user.spam_logs.find_by(id: @spam_log_id)&.update!(recaptcha_verified: true)
end
SpamCheckService.new(
spammable: spammable,
request: @request
).execute(
api: @api,
recaptcha_verified: @recaptcha_verified,
spam_log_id: @spam_log_id,
user_id: user.id)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables
end
Loading
Loading
@@ -66,23 +66,21 @@ module Projects
end
 
def import_repository
begin
refmap = importer_class.try(:refmap) if has_importer?
if refmap
project.ensure_repository
project.repository.fetch_as_mirror(project.import_url, refmap: refmap)
else
gitlab_shell.import_project_repository(project)
end
rescue Gitlab::Shell::Error => e
# Expire cache to prevent scenarios such as:
# 1. First import failed, but the repo was imported successfully, so +exists?+ returns true
# 2. Retried import, repo is broken or not imported but +exists?+ still returns true
project.repository.expire_content_cache if project.repository_exists?
refmap = importer_class.try(:refmap) if has_importer?
 
raise Error, e.message
if refmap
project.ensure_repository
project.repository.fetch_as_mirror(project.import_url, refmap: refmap)
else
gitlab_shell.import_project_repository(project)
end
rescue Gitlab::Shell::Error => e
# Expire cache to prevent scenarios such as:
# 1. First import failed, but the repo was imported successfully, so +exists?+ returns true
# 2. Retried import, repo is broken or not imported but +exists?+ still returns true
project.repository.expire_content_cache if project.repository_exists?
raise Error, e.message
end
 
def download_lfs_objects
Loading
Loading
# frozen_string_literal: true
 
class SpamService
class SpamCheckService
include AkismetMethods
 
attr_accessor :spammable, :request, :options
Loading
Loading
@@ -21,14 +21,14 @@ class SpamService
end
end
 
def when_recaptcha_verified(recaptcha_verified, api = false)
# In case it's a request which is already verified through recaptcha, yield
# block.
def execute(api: false, recaptcha_verified:, spam_log_id:, user_id:)
if recaptcha_verified
yield
# If it's a request which is already verified through recaptcha,
# update the spam log accordingly.
SpamLog.verify_recaptcha!(user_id: user_id, id: spam_log_id)
else
# Otherwise, it goes to Akismet and check if it's a spam. If that's the
# case, it assigns spammable record as "spam" and create a SpamLog record.
# Otherwise, it goes to Akismet for spam check.
# If so, it assigns spammable object as "spam" and creates a SpamLog record.
possible_spam = check(api)
spammable.spam = possible_spam unless spammable.allow_possible_spam?
spammable.spam_log = spam_log
Loading
Loading
@@ -38,9 +38,9 @@ class SpamService
private
 
def check(api)
return false unless request && check_for_spam?
return false unless akismet.spam?
return unless request
return unless check_for_spam?
return unless akismet.spam?
 
create_spam_log(api)
true
Loading
Loading
---
title: Add extra fields to the application context
merge_request: 22792
author:
type: added
Loading
Loading
@@ -542,6 +542,20 @@ group = Group.find_by_full_path 'group'
user.max_member_access_for_group group.id
```
 
### Change user password
```ruby
password = "your password"
user = User.find_by_username('your username')
password_attributes = {
password: password,
password_confirmation: password,
password_automatically_set: false
}
result = Users::UpdateService.new(user, password_attributes.merge(user: user)).execute
```
## Groups
 
### Count unique users in a group and sub-groups
Loading
Loading
Loading
Loading
@@ -47,7 +47,8 @@ module API
Gitlab::ApplicationContext.push(
user: -> { current_user },
project: -> { @project },
namespace: -> { @group }
namespace: -> { @group },
caller_id: route.origin
)
end
 
Loading
Loading
Loading
Loading
@@ -9,7 +9,8 @@ module API
before do
Gitlab::ApplicationContext.push(
user: -> { actor&.user },
project: -> { project }
project: -> { project },
caller_id: route.origin
)
end
 
Loading
Loading
Loading
Loading
@@ -33,6 +33,7 @@ module DeclarativePolicy
attr_reader :steps
def initialize(steps)
@steps = steps
@state = nil
end
 
# We make sure only to run any given Runner once,
Loading
Loading
Loading
Loading
@@ -11,6 +11,7 @@ class Feature
inforef_uploadpack_cache
get_tag_messages_go
filter_shas_with_signatures_go
commit_without_batch_check
].freeze
 
DEFAULT_ON_FLAGS = Set.new([]).freeze
Loading
Loading
Loading
Loading
@@ -5,12 +5,13 @@ module Gitlab
class ApplicationContext
include Gitlab::Utils::LazyAttributes
 
Attribute = Struct.new(:name, :type)
Attribute = Struct.new(:name, :type, :evaluation)
 
APPLICATION_ATTRIBUTES = [
Attribute.new(:project, Project),
Attribute.new(:namespace, Namespace),
Attribute.new(:user, User)
Attribute.new(:user, User),
Attribute.new(:caller_id, String)
].freeze
 
def self.with_context(args, &block)
Loading
Loading
@@ -37,6 +38,7 @@ module Gitlab
hash[:user] = -> { username } if set_values.include?(:user)
hash[:project] = -> { project_path } if set_values.include?(:project)
hash[:root_namespace] = -> { root_namespace_path } if include_namespace?
hash[:caller_id] = caller_id if set_values.include?(:caller_id)
end
end
 
Loading
Loading
@@ -75,3 +77,5 @@ module Gitlab
end
end
end
Gitlab::ApplicationContext.prepend_if_ee('EE::Gitlab::ApplicationContext')
Loading
Loading
@@ -32,11 +32,9 @@ module Gitlab
end
 
def catch_timeout(seconds, &block)
begin
Timeout.timeout(seconds.to_i, &block)
rescue Timeout::Error => ex
ex
end
Timeout.timeout(seconds.to_i, &block)
rescue Timeout::Error => ex
ex
end
end
end
Loading
Loading
Loading
Loading
@@ -2,6 +2,8 @@
 
module Gitlab
module Marginalia
cattr_accessor :enabled, default: false
MARGINALIA_FEATURE_FLAG = :marginalia
 
def self.set_application_name
Loading
Loading
@@ -15,14 +17,14 @@ module Gitlab
end
 
def self.cached_feature_enabled?
!!@enabled
enabled
end
 
def self.set_feature_cache
# During db:create and db:bootstrap skip feature query as DB is not available yet.
return false unless ActiveRecord::Base.connected? && Gitlab::Database.cached_table_exists?('features')
 
@enabled = Feature.enabled?(MARGINALIA_FEATURE_FLAG)
self.enabled = Feature.enabled?(MARGINALIA_FEATURE_FLAG)
end
end
end
Loading
Loading
@@ -9,8 +9,10 @@ module Gitlab
@metrics = init_metrics
end
 
def call(worker, _job, queue, _redis_pool)
labels = create_labels(worker.class, queue)
def call(worker_class, _job, queue, _redis_pool)
# worker_class can either be the string or class of the worker being enqueued.
worker_class = worker_class.safe_constantize if worker_class.respond_to?(:safe_constantize)
labels = create_labels(worker_class, queue)
 
@metrics.fetch(ENQUEUED).increment(labels, 1)
 
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ module Gitlab
 
def create_labels(worker_class, queue)
labels = { queue: queue.to_s, latency_sensitive: FALSE_LABEL, external_dependencies: FALSE_LABEL, feature_category: "", boundary: "" }
return labels unless worker_class.include? WorkerAttributes
return labels unless worker_class && worker_class.include?(WorkerAttributes)
 
labels[:latency_sensitive] = bool_as_label(worker_class.latency_sensitive_worker?)
labels[:external_dependencies] = bool_as_label(worker_class.worker_has_external_dependencies?)
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