Skip to content
Snippets Groups Projects
Unverified Commit 56e2a291 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce

parents 104b9e8b c384315a
No related branches found
No related tags found
No related merge requests found
Showing
with 265 additions and 41 deletions
Loading
Loading
@@ -60,6 +60,7 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController
font
message
starts_at
target_path
))
end
end
Loading
Loading
@@ -28,7 +28,8 @@ class Admin::IdentitiesController < Admin::ApplicationController
 
def update
if @identity.update(identity_params)
RepairLdapBlockedUserService.new(@user).execute
::Users::RepairLdapBlockedService.new(@user).execute
redirect_to admin_user_identities_path(@user), notice: _('User identity was successfully updated.')
else
render :edit
Loading
Loading
@@ -37,7 +38,8 @@ class Admin::IdentitiesController < Admin::ApplicationController
 
def destroy
if @identity.destroy
RepairLdapBlockedUserService.new(@user).execute
::Users::RepairLdapBlockedService.new(@user).execute
redirect_to admin_user_identities_path(@user), status: :found, notice: _('User identity was successfully removed.')
else
redirect_to admin_user_identities_path(@user), status: :found, alert: _('Failed to remove user identity.')
Loading
Loading
Loading
Loading
@@ -40,10 +40,20 @@ class AutocompleteController < ApplicationController
end
 
def merge_request_target_branches
merge_requests = MergeRequestsFinder.new(current_user, params).execute
target_branches = merge_requests.recent_target_branches
if target_branch_params.present?
merge_requests = MergeRequestsFinder.new(current_user, target_branch_params).execute
target_branches = merge_requests.recent_target_branches
render json: target_branches.map { |target_branch| { title: target_branch } }
else
render json: { error: _('At least one of group_id or project_id must be specified') }, status: :bad_request
end
end
private
 
render json: target_branches.map { |target_branch| { title: target_branch } }
def target_branch_params
params.permit(:group_id, :project_id)
end
end
 
Loading
Loading
Loading
Loading
@@ -121,7 +121,7 @@ module IssuableActions
end
 
def bulk_update
result = Issuable::BulkUpdateService.new(current_user, bulk_update_params).execute(resource_name)
result = Issuable::BulkUpdateService.new(parent, current_user, bulk_update_params).execute(resource_name)
quantity = result[:count]
 
render json: { notice: "#{quantity} #{resource_name.pluralize(quantity)} updated" }
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@
class InstanceStatistics::ConversationalDevelopmentIndexController < InstanceStatistics::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index
@metric = ConversationalDevelopmentIndex::Metric.order(:created_at).last&.present
@metric = DevOpsScore::Metric.order(:created_at).last&.present
end
# rubocop: enable CodeReuse/ActiveRecord
end
Loading
Loading
@@ -133,8 +133,6 @@ class Projects::BranchesController < Projects::ApplicationController
# frontend could omit this set. To prevent excessive I/O, we require
# that a list of names be specified.
def limit_diverging_commit_counts!
return unless Feature.enabled?(:limit_diverging_commit_counts, default_enabled: true)
limit = Kaminari.config.default_per_page
 
# If we don't have many branches in the repository, then go ahead.
Loading
Loading
Loading
Loading
@@ -55,6 +55,7 @@ class Projects::ErrorTrackingController < Projects::ApplicationController
 
render json: {
errors: serialize_errors(result[:issues]),
pagination: result[:pagination],
external_url: service.external_url
}
end
Loading
Loading
@@ -111,7 +112,7 @@ class Projects::ErrorTrackingController < Projects::ApplicationController
end
 
def list_issues_params
params.permit([:search_term, :sort])
params.permit(:search_term, :sort, :cursor)
end
 
def list_projects_params
Loading
Loading
Loading
Loading
@@ -218,11 +218,16 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
end
 
def ci_environments_status
environments = if ci_environments_status_on_merge_result?
EnvironmentStatus.after_merge_request(@merge_request, current_user)
else
EnvironmentStatus.for_merge_request(@merge_request, current_user)
end
environments =
if ci_environments_status_on_merge_result?
if Feature.enabled?(:deployment_merge_requests_widget, @project)
EnvironmentStatus.for_deployed_merge_request(@merge_request, current_user)
else
EnvironmentStatus.after_merge_request(@merge_request, current_user)
end
else
EnvironmentStatus.for_merge_request(@merge_request, current_user)
end
 
render json: EnvironmentStatusSerializer.new(current_user: current_user).represent(environments)
end
Loading
Loading
Loading
Loading
@@ -15,13 +15,9 @@ class SnippetsController < ApplicationController
 
before_action :snippet, only: [:show, :edit, :destroy, :update, :raw]
 
# Allow read snippet
before_action :authorize_create_snippet!, only: [:new, :create]
before_action :authorize_read_snippet!, only: [:show, :raw]
# Allow modify snippet
before_action :authorize_update_snippet!, only: [:edit, :update]
# Allow destroy snippet
before_action :authorize_admin_snippet!, only: [:destroy]
 
skip_before_action :authenticate_user!, only: [:index, :show, :raw]
Loading
Loading
@@ -140,6 +136,10 @@ class SnippetsController < ApplicationController
return render_404 unless can?(current_user, :admin_personal_snippet, @snippet)
end
 
def authorize_create_snippet!
return render_404 unless can?(current_user, :create_personal_snippet)
end
def snippet_params
params.require(:personal_snippet).permit(:title, :content, :file_name, :private, :visibility_level, :description)
end
Loading
Loading
Loading
Loading
@@ -20,7 +20,6 @@ class UploadsController < ApplicationController
 
skip_before_action :authenticate_user!
before_action :upload_mount_satisfied?
before_action :find_model
before_action :authorize_access!, only: [:show]
before_action :authorize_create_access!, only: [:create, :authorize]
before_action :verify_workhorse_api!, only: [:authorize]
Loading
Loading
# frozen_string_literal: true
class DeploymentsFinder
attr_reader :project, :params
ALLOWED_SORT_VALUES = %w[id iid created_at updated_at ref].freeze
DEFAULT_SORT_VALUE = 'id'.freeze
ALLOWED_SORT_DIRECTIONS = %w[asc desc].freeze
DEFAULT_SORT_DIRECTION = 'asc'.freeze
def initialize(project, params = {})
@project = project
@params = params
end
def execute
items = init_collection
items = by_updated_at(items)
sort(items)
end
private
def init_collection
project.deployments
end
# rubocop: disable CodeReuse/ActiveRecord
def sort(items)
items.order(sort_params)
end
# rubocop: enable CodeReuse/ActiveRecord
def by_updated_at(items)
items = items.updated_before(params[:updated_before]) if params[:updated_before].present?
items = items.updated_after(params[:updated_after]) if params[:updated_after].present?
items
end
def sort_params
order_by = ALLOWED_SORT_VALUES.include?(params[:order_by]) ? params[:order_by] : DEFAULT_SORT_VALUE
order_direction = ALLOWED_SORT_DIRECTIONS.include?(params[:sort]) ? params[:sort] : DEFAULT_SORT_DIRECTION
{ order_by => order_direction }
end
end
Loading
Loading
@@ -40,15 +40,14 @@
# Any other value will be ignored.
class SnippetsFinder < UnionFinder
include FinderMethods
include Gitlab::Utils::StrongMemoize
 
attr_accessor :current_user, :project, :author, :scope, :explore
attr_accessor :current_user, :params
delegate :explore, :only_personal, :only_project, :scope, to: :params
 
def initialize(current_user = nil, params = {})
@current_user = current_user
@project = params[:project]
@author = params[:author]
@scope = params[:scope].to_s
@explore = params[:explore]
@params = OpenStruct.new(params)
 
if project && author
raise(
Loading
Loading
@@ -60,8 +59,15 @@ class SnippetsFinder < UnionFinder
end
 
def execute
base = init_collection
base.with_optional_visibility(visibility_from_scope).fresh
# The snippet query can be expensive, therefore if the
# author or project params have been passed and they don't
# exist, it's better to return
return Snippet.none if author.nil? && params[:author].present?
return Snippet.none if project.nil? && params[:project].present?
items = init_collection
items = by_ids(items)
items.with_optional_visibility(visibility_from_scope).fresh
end
 
private
Loading
Loading
@@ -69,10 +75,12 @@ class SnippetsFinder < UnionFinder
def init_collection
if explore
snippets_for_explore
elsif only_personal
personal_snippets
elsif project
snippets_for_a_single_project
else
snippets_for_multiple_projects
snippets_for_personal_and_multiple_projects
end
end
 
Loading
Loading
@@ -96,8 +104,9 @@ class SnippetsFinder < UnionFinder
#
# Each collection is constructed in isolation, allowing for greater control
# over the resulting SQL query.
def snippets_for_multiple_projects
queries = [personal_snippets]
def snippets_for_personal_and_multiple_projects
queries = []
queries << personal_snippets unless only_project
 
if Ability.allowed?(current_user, :read_cross_project)
queries << snippets_of_visible_projects
Loading
Loading
@@ -158,7 +167,7 @@ class SnippetsFinder < UnionFinder
end
 
def visibility_from_scope
case scope
case scope.to_s
when 'are_private'
Snippet::PRIVATE
when 'are_internal'
Loading
Loading
@@ -169,6 +178,28 @@ class SnippetsFinder < UnionFinder
nil
end
end
def by_ids(items)
return items unless params[:ids].present?
items.id_in(params[:ids])
end
def author
strong_memoize(:author) do
next unless params[:author].present?
params[:author].is_a?(User) ? params[:author] : User.find_by_id(params[:author])
end
end
def project
strong_memoize(:project) do
next unless params[:project].present?
params[:project].is_a?(Project) ? params[:project] : Project.find_by_id(params[:project])
end
end
end
 
SnippetsFinder.prepend_if_ee('EE::SnippetsFinder')
Loading
Loading
@@ -94,6 +94,25 @@ module ApplicationHelper
sanitize(str, tags: %w(a span))
end
 
def body_data
{
page: body_data_page,
page_type_id: controller.params[:id],
find_file: find_file_path,
group: "#{@group&.path}"
}.merge(project_data)
end
def project_data
return {} unless @project
{
project_id: @project.id,
project: @project.path,
namespace_id: @project.namespace&.id
}
end
def body_data_page
[*controller.controller_path.split('/'), controller.action_name].compact.join(':')
end
Loading
Loading
Loading
Loading
@@ -301,7 +301,8 @@ module ApplicationSettingsHelper
:snowplow_iglu_registry_url,
:push_event_hooks_limit,
:push_event_activities_limit,
:custom_http_clone_url_root
:custom_http_clone_url_root,
:snippet_size_limit
]
end
 
Loading
Loading
Loading
Loading
@@ -141,7 +141,7 @@ module BlobHelper
if @build && @entry
raw_project_job_artifacts_url(@project, @build, path: @entry.path, **kwargs)
elsif @snippet
reliable_raw_snippet_url(@snippet)
raw_snippet_url(@snippet)
elsif @blob
project_raw_url(@project, @id, **kwargs)
end
Loading
Loading
# frozen_string_literal: true
 
module BroadcastMessagesHelper
def current_broadcast_messages
BroadcastMessage.current(request.path)
end
def broadcast_message(message)
return unless message.present?
 
Loading
Loading
# frozen_string_literal: true
 
module ConversationalDevelopmentIndexHelper
module DevOpsScoreHelper
def score_level(score)
if score < 33.33
'low'
Loading
Loading
Loading
Loading
@@ -161,6 +161,18 @@ module DiffHelper
end
end
 
def render_overflow_warning?(diffs_collection)
diff_files = diffs_collection.diff_files
if diff_files.any?(&:too_large?)
Gitlab::Metrics.add_event(:diffs_overflow_single_file_limits)
end
diff_files.overflow?.tap do |overflown|
Gitlab::Metrics.add_event(:diffs_overflow_collection_limits) if overflown
end
end
private
 
def diff_btn(title, name, selected)
Loading
Loading
@@ -203,12 +215,6 @@ module DiffHelper
link_to "#{hide_whitespace? ? 'Show' : 'Hide'} whitespace changes", url, class: options[:class]
end
 
def render_overflow_warning?(diffs_collection)
diffs = @merge_request_diff.presence || diffs_collection.diff_files
diffs.overflow?
end
def diff_file_path_text(diff_file, max: 60)
path = diff_file.new_path
 
Loading
Loading
Loading
Loading
@@ -193,6 +193,101 @@ module GitlabRoutingHelper
project = schedule.project
take_ownership_project_pipeline_schedule_path(project, schedule, *args)
end
def snippet_path(snippet, *args)
if snippet.is_a?(ProjectSnippet)
application_url_helpers.project_snippet_path(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_path(snippet, *new_args)
end
end
def snippet_url(snippet, *args)
if snippet.is_a?(ProjectSnippet)
application_url_helpers.project_snippet_url(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_url(snippet, *new_args)
end
end
def raw_snippet_path(snippet, *args)
if snippet.is_a?(ProjectSnippet)
application_url_helpers.raw_project_snippet_path(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.raw_snippet_path(snippet, *new_args)
end
end
def raw_snippet_url(snippet, *args)
if snippet.is_a?(ProjectSnippet)
application_url_helpers.raw_project_snippet_url(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.raw_snippet_url(snippet, *new_args)
end
end
def snippet_notes_path(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_notes_path(snippet, *new_args)
end
def snippet_notes_url(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_notes_url(snippet, *new_args)
end
def snippet_note_path(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_note_path(snippet, note, *new_args)
end
def snippet_note_url(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_note_url(snippet, note, *new_args)
end
def toggle_award_emoji_snippet_note_path(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.toggle_award_emoji_snippet_note_path(snippet, note, *new_args)
end
def toggle_award_emoji_snippet_note_url(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.toggle_award_emoji_snippet_note_url(snippet, note, *new_args)
end
def toggle_award_emoji_snippet_path(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.toggle_award_emoji_snippet_path(snippet, *new_args)
end
def toggle_award_emoji_snippet_url(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.toggle_award_emoji_snippet_url(snippet, *new_args)
end
private
def application_url_helpers
Gitlab::Routing.url_helpers
end
def snippet_query_params(snippet, *args)
opts = case args.last
when Hash
args.pop
when ActionController::Parameters
args.pop.to_h
else
{}
end
args << opts
end
end
 
GitlabRoutingHelper.include_if_ee('EE::GitlabRoutingHelper')
Loading
Loading
@@ -391,6 +391,10 @@ module IssuablesHelper
end
end
 
def issuable_templates_names(issuable)
issuable_templates(issuable).map { |template| template[:name] }
end
def selected_template(issuable)
params[:issuable_template] if issuable_templates(issuable).any? { |template| template[:name] == params[:issuable_template] }
end
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