Commit 67856357 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ee-rubocop-code-reuse' into 'master'

EE: Add RuboCop cops to enforce code reusing rules

See merge request gitlab-org/gitlab-ee!7229
parents ba37a5ae cd7b816e
......@@ -30,6 +30,7 @@ class AbuseReportsController < ApplicationController
))
end
# rubocop: disable CodeReuse/ActiveRecord
def set_user
@user = User.find_by(id: params[:user_id])
......@@ -39,4 +40,5 @@ class AbuseReportsController < ApplicationController
redirect_to @user, alert: "Cannot create the abuse report. This user has been blocked."
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
class Admin::AbuseReportsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index
@abuse_reports = AbuseReport.order(id: :desc).page(params[:page])
@abuse_reports.includes(:reporter, :user)
end
# rubocop: enable CodeReuse/ActiveRecord
def destroy
abuse_report = AbuseReport.find(params[:id])
......
......@@ -4,9 +4,11 @@ class Admin::ApplicationsController < Admin::ApplicationController
before_action :set_application, only: [:show, :edit, :update, :destroy]
before_action :load_scopes, only: [:new, :create, :edit, :update]
# rubocop: disable CodeReuse/ActiveRecord
def index
@applications = Doorkeeper::Application.where("owner_id IS NULL")
end
# rubocop: enable CodeReuse/ActiveRecord
def show
end
......@@ -45,9 +47,11 @@ class Admin::ApplicationsController < Admin::ApplicationController
private
# rubocop: disable CodeReuse/ActiveRecord
def set_application
@application = Doorkeeper::Application.where("owner_id IS NULL").find(params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
# Only allow a trusted parameter "white list" through.
def application_params
......
......@@ -3,10 +3,12 @@ class Admin::BroadcastMessagesController < Admin::ApplicationController
before_action :finder, only: [:edit, :update, :destroy]
# rubocop: disable CodeReuse/ActiveRecord
def index
@broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page])
@broadcast_message = BroadcastMessage.new
end
# rubocop: enable CodeReuse/ActiveRecord
def edit
end
......
......@@ -6,10 +6,12 @@ class Admin::DashboardController < Admin::ApplicationController
COUNTED_ITEMS = [Project, User, Group, ForkedProjectLink, Issue, MergeRequest,
Note, Snippet, Key, Milestone].freeze
# rubocop: disable CodeReuse/ActiveRecord
def index
@counts = Gitlab::Database::Count.approximate_counts(COUNTED_ITEMS)
@projects = Project.order_id_desc.without_deleted.with_route.limit(10)
@users = User.order_id_desc.limit(10)
@groups = Group.order_id_desc.with_route.limit(10)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -12,6 +12,7 @@ class Admin::GroupsController < Admin::ApplicationController
@groups = @groups.page(params[:page])
end
# rubocop: disable CodeReuse/ActiveRecord
def show
@group = Group.with_statistics.joins(:route).group('routes.path').find_by_full_path(params[:id])
@members = present_members(
......@@ -20,6 +21,7 @@ class Admin::GroupsController < Admin::ApplicationController
AccessRequestsFinder.new(@group).execute(current_user))
@projects = @group.projects.with_statistics.page(params[:projects_page])
end
# rubocop: enable CodeReuse/ActiveRecord
def new
@group = Group.new
......
......@@ -44,9 +44,11 @@ class Admin::IdentitiesController < Admin::ApplicationController
protected
# rubocop: disable CodeReuse/ActiveRecord
def user
@user ||= User.find_by!(username: params[:user_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def identity
@identity ||= user.identities.find(params[:id])
......
......@@ -30,9 +30,11 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController
private
# rubocop: disable CodeReuse/ActiveRecord
def user
@user ||= User.find_by!(username: params[:user_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def finder(options = {})
PersonalAccessTokensFinder.new({ user: user, impersonation: true }.merge(options))
......@@ -42,6 +44,7 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController
params.require(:personal_access_token).permit(:name, :expires_at, :impersonation, scopes: [])
end
# rubocop: disable CodeReuse/ActiveRecord
def set_index_vars
@scopes = Gitlab::Auth.available_scopes(current_user)
......@@ -49,4 +52,5 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController
@inactive_impersonation_tokens = finder(state: 'inactive').execute
@active_impersonation_tokens = finder(state: 'active').execute.order(:expires_at)
end
# rubocop: enable CodeReuse/ActiveRecord
end
class Admin::JobsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index
@scope = params[:scope]
@all_builds = Ci::Build
......@@ -16,6 +17,7 @@ class Admin::JobsController < Admin::ApplicationController
end
@builds = @builds.page(params[:page]).per(30)
end
# rubocop: enable CodeReuse/ActiveRecord
def cancel_all
Ci::Build.running_or_pending.each(&:cancel)
......
......@@ -24,9 +24,11 @@ class Admin::KeysController < Admin::ApplicationController
protected
# rubocop: disable CodeReuse/ActiveRecord
def user
@user ||= User.find_by!(username: params[:user_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def key_params
params.require(:user_id, :id)
......
......@@ -19,6 +19,7 @@ class Admin::ProjectsController < Admin::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def show
if @group
@group_members = present_members(
......@@ -30,7 +31,9 @@ class Admin::ProjectsController < Admin::ApplicationController
@requesters = present_members(
AccessRequestsFinder.new(@project).execute(current_user))
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def transfer
namespace = Namespace.find_by(id: params[:new_namespace_id])
::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace)
......@@ -38,6 +41,7 @@ class Admin::ProjectsController < Admin::ApplicationController
@project.reload
redirect_to admin_project_path(@project)
end
# rubocop: enable CodeReuse/ActiveRecord
def repository_check
RepositoryCheck::SingleRepositoryWorker.perform_async(@project.id)
......
class Admin::RunnersController < Admin::ApplicationController
before_action :runner, except: :index
# rubocop: disable CodeReuse/ActiveRecord
def index
sort = params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc }
@runners = Ci::Runner.order(sort)
......@@ -8,6 +9,7 @@ class Admin::RunnersController < Admin::ApplicationController
@runners = @runners.page(params[:page]).per(30)
@active_runners_cnt = Ci::Runner.online.count
end
# rubocop: enable CodeReuse/ActiveRecord
def show
assign_builds_and_projects
......@@ -57,6 +59,7 @@ class Admin::RunnersController < Admin::ApplicationController
params.require(:runner).permit(Ci::Runner::FORM_EDITABLE)
end
# rubocop: disable CodeReuse/ActiveRecord
def assign_builds_and_projects
@builds = runner.builds.order('id DESC').first(30)
@projects =
......@@ -69,4 +72,5 @@ class Admin::RunnersController < Admin::ApplicationController
@projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any?
@projects = @projects.page(params[:page]).per(30)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -30,16 +30,20 @@ class Admin::ServicesController < Admin::ApplicationController
private
# rubocop: disable CodeReuse/ActiveRecord
def services_templates
Service.available_services_names.map do |service_name|
service_template = "#{service_name}_service".camelize.constantize
service_template.where(template: true).first_or_create
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def service
@service ||= Service.where(id: params[:id], template: true).first
end
# rubocop: enable CodeReuse/ActiveRecord
def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42430')
......
class Admin::SpamLogsController < Admin::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index
@spam_logs = SpamLog.order(id: :desc).page(params[:page])
end
# rubocop: enable CodeReuse/ActiveRecord
def destroy
spam_log = SpamLog.find(params[:id])
......
......@@ -176,9 +176,11 @@ class Admin::UsersController < Admin::ApplicationController
user == current_user
end
# rubocop: disable CodeReuse/ActiveRecord
def user
@user ||= User.find_by!(username: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
def redirect_back_or_admin_user(options = {})
redirect_back_or_default(default: default_route, options: options)
......
......@@ -11,6 +11,7 @@ module Boards
before_action :authorize_update_issue, only: [:update]
skip_before_action :authenticate_user!, only: [:index]
# rubocop: disable CodeReuse/ActiveRecord
def index
list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params)
issues = list_service.execute
......@@ -25,6 +26,7 @@ module Boards
render_issues(issues, list_service.metadata)
end
# rubocop: enable CodeReuse/ActiveRecord
def create
service = Boards::Issues::CreateService.new(board_parent, project, current_user, issue_params)
......
......@@ -88,6 +88,7 @@ module AuthenticatesWithTwoFactor
# Setup in preparation of communication with a U2F (universal 2nd factor) device
# Actual communication is performed using a Javascript API
# rubocop: disable CodeReuse/ActiveRecord
def setup_u2f_authentication(user)
key_handles = user.u2f_registrations.pluck(:key_handle)
u2f = U2F::U2F.new(u2f_app_id)
......@@ -99,4 +100,5 @@ module AuthenticatesWithTwoFactor
sign_requests: sign_requests })
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -99,6 +99,7 @@ module CreatesCommit
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def merge_request_exists?
strong_memoize(:merge_request) do
MergeRequestsFinder.new(current_user, project_id: @project.id)
......@@ -110,6 +111,7 @@ module CreatesCommit
target_branch: @start_branch)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def different_project?
......
......@@ -24,6 +24,7 @@ module EnforcesTwoFactorAuthentication
current_user.try(:require_two_factor_authentication_from_group?)
end
# rubocop: disable CodeReuse/ActiveRecord
def two_factor_authentication_reason(global: -> {}, group: -> {})
if two_factor_authentication_required?
if Gitlab::CurrentSettings.require_two_factor_authentication?
......@@ -34,6 +35,7 @@ module EnforcesTwoFactorAuthentication
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def two_factor_grace_period
periods = [Gitlab::CurrentSettings.two_factor_grace_period]
......
module GroupTree
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def render_group_tree(groups)
groups = groups.sort_by_attribute(@sort = params[:sort])
......@@ -23,7 +24,9 @@ module GroupTree
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def filtered_groups_with_ancestors(groups)
filtered_groups = groups.search(params[:filter]).page(params[:page])
......@@ -40,4 +43,5 @@ module GroupTree
filtered_groups
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -90,6 +90,7 @@ module IssuableActions
render json: { notice: "#{quantity} #{resource_name.pluralize(quantity)} updated" }
end
# rubocop: disable CodeReuse/ActiveRecord
def discussions
notes = issuable.discussion_notes
.inc_relations_for_view
......@@ -104,6 +105,7 @@ module IssuableActions
render json: discussion_serializer.represent(discussions, context: self)
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -49,9 +49,11 @@ module IssuableCollections
false
end
# rubocop: disable CodeReuse/ActiveRecord
def issuables_collection
finder.execute.preload(preload_for_collection)
end
# rubocop: enable CodeReuse/ActiveRecord
def redirect_out_of_range(total_pages)
return false if total_pages.nil? || total_pages.zero?
......@@ -82,6 +84,7 @@ module IssuableCollections
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def filter_params
set_sort_order_from_cookie
set_default_state
......@@ -102,6 +105,7 @@ module IssuableCollections
@filter_params.permit(finder_type.valid_params)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def set_default_state
......
......@@ -2,6 +2,7 @@ module IssuesCalendar
extend ActiveSupport::Concern
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def render_issues_calendar(issuables)
@issues = issuables
.non_archived
......@@ -20,5 +21,6 @@ module IssuesCalendar
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:enable Gitlab/ModuleWithInstanceVariables
end
......@@ -10,10 +10,12 @@ module MembersPresentation
).fabricate!
end
# rubocop: disable CodeReuse/ActiveRecord
def preload_associations(members)
ActiveRecord::Associations::Preloader.new.preload(members, :user)
ActiveRecord::Associations::Preloader.new.preload(members, :source)
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :status)
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :u2f_registrations)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -57,6 +57,7 @@ module MembershipActions
redirect_to members_page_url
end
# rubocop: disable CodeReuse/ActiveRecord
def leave
member = membershipable.members_and_requesters.find_by!(user_id: current_user.id)
Members::DestroyService.new(current_user).execute(member)
......@@ -77,6 +78,7 @@ module MembershipActions
format.json { render json: { notice: notice } }
end
end
# rubocop: enable CodeReuse/ActiveRecord
def resend_invite
member = membershipable.members.find(params[:id])
......
......@@ -13,6 +13,7 @@ module RendersMemberAccess
private
# rubocop: disable CodeReuse/ActiveRecord
def preload_max_member_access_for_collection(klass, collection)
return if !current_user || collection.blank?
......@@ -20,4 +21,5 @@ module RendersMemberAccess
current_user.public_send(method_name, collection.ids) # rubocop:disable GitlabSecurity/PublicSend
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -20,9 +20,11 @@ module RendersNotes
project.team.max_member_access_for_user_ids(user_ids)
end
# rubocop: disable CodeReuse/ActiveRecord
def preload_noteable_for_regular_notes(notes)
ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable)
end
# rubocop: enable CodeReuse/ActiveRecord
def preload_first_time_contribution_for_authors(noteable, notes)
return unless noteable.is_a?(Issuable) && noteable.first_contribution?
......@@ -30,7 +32,9 @@ module RendersNotes
notes.each {|n| n.specialize_for_first_contribution!(noteable)}
end
# rubocop: disable CodeReuse/ActiveRecord
def preload_author_status(notes)
ActiveRecord::Associations::Preloader.new.preload(notes, { author: :status })
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -89,6 +89,7 @@ module UploadsActions
end
end
# rubocop: disable CodeReuse/ActiveRecord
def build_uploader_from_upload
return unless uploader = build_uploader
......@@ -96,6 +97,7 @@ module UploadsActions
upload = Upload.find_by(uploader: uploader_class.to_s, path: upload_paths)
upload&.build_uploader
end
# rubocop: enable CodeReuse/ActiveRecord
def build_uploader_from_params
return unless uploader = build_uploader
......
......@@ -23,6 +23,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def starred
@projects = load_projects(params.merge(starred: true))
.includes(:forked_from_project, :tags)
......@@ -38,6 +39,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......@@ -46,6 +48,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
@sort = params[:sort]
end
# rubocop: disable CodeReuse/ActiveRecord
def load_projects(finder_params)
projects = ProjectsFinder
.new(params: finder_params, current_user: current_user)
......@@ -55,6 +58,7 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
prepare_projects_for_rendering(projects)
end
# rubocop: enable CodeReuse/ActiveRecord
def load_events
projects = load_projects(params.merge(non_public: true))
......
......@@ -73,6 +73,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id)
end
# rubocop: disable CodeReuse/ActiveRecord
def redirect_out_of_range(todos)
total_pages =
if todo_params.except(:sort, :page).empty?
......@@ -91,4 +92,5 @@ class Dashboard::TodosController < Dashboard::ApplicationController
out_of_range
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -34,6 +34,7 @@ class Explore::ProjectsController < Explore::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def starred
@projects = load_projects.reorder('star_count DESC')
......@@ -46,9 +47,11 @@ class Explore::ProjectsController < Explore::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
# rubocop: disable CodeReuse/ActiveRecord
def load_projects
projects = ProjectsFinder.new(current_user: current_user, params: params)
.execute
......@@ -58,4 +61,5 @@ class Explore::ProjectsController < Explore::ApplicationController
prepare_projects_for_rendering(projects)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -98,6 +98,7 @@ class GroupsController < Groups::ApplicationController
redirect_to root_path, status: 302, alert: "Group '#{@group.name}' was scheduled for deletion."
end
# rubocop: disable CodeReuse/ActiveRecord
def transfer
parent_group = Group.find_by(id: params[:new_parent_group_id])
service = ::Groups::TransferService.new(@group, current_user)
......@@ -110,9 +111,11 @@ class GroupsController < Groups::ApplicationController
render :edit
end
end
# rubocop: enable CodeReuse/ActiveRecord
protected
# rubocop: disable CodeReuse/ActiveRecord
def authorize_create_group!
allowed = if params[:parent_id].present?
parent = Group.find_by(id: params[:parent_id])
......@@ -123,6 +126,7 @@ class GroupsController < Groups::ApplicationController
render_404 unless allowed
end
# rubocop: enable CodeReuse/ActiveRecord
def determine_layout
if [:new, :create].include?(action_name.to_sym)
......@@ -157,6 +161,7 @@ class GroupsController < Groups::ApplicationController
]
end
# rubocop: disable CodeReuse/ActiveRecord
def load_events
params[:sort] ||= 'latest_activity_desc'
......@@ -176,6 +181,7 @@ class GroupsController < Groups::ApplicationController
.new(current_user)
.execute(@events, atom_request: request.format.atom?)
end
# rubocop: enable CodeReuse/ActiveRecord
def user_actions
if current_user
......
class Import::BaseController < ApplicationController
private
# rubocop: disable CodeReuse/ActiveRecord
def find_already_added_projects(import_type)
current_user.created_projects.where(import_type: import_type).includes(:import_state)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_jobs(import_type)
current_user.created_projects
.includes(:import_state)
.where(import_type: import_type)
.to_json(only: [:id], methods: [:import_status])
end
# rubocop: enable CodeReuse/ActiveRecord
def find_or_create_namespace(names, owner)
names = params[:target_namespace].presence || names
......
......@@ -16,6 +16,7 @@ class Import::BitbucketController < Import::BaseController
redirect_to status_import_bitbucket_url
end
# rubocop: disable CodeReuse/ActiveRecord
def status
bitbucket_client = Bitbucket::Client.new(credentials)
repos = bitbucket_client.repos
......@@ -27,6 +28,7 @@ class Import::BitbucketController < Import::BaseController
@repos.to_a.reject! { |repo| already_added_projects_names.include?(repo.full_name) }
end
# rubocop: enable CodeReuse/ActiveRecord
def jobs
render json: find_jobs('bitbucket')
......
......@@ -52,6 +52,7 @@ class Import::BitbucketServerController < Import::BaseController
redirect_to status_import_bitbucket_server_path
end
# rubocop: disable CodeReuse/ActiveRecord
def status
repos = bitbucket_client.repos
......@@ -66,6 +67,7 @@ class Import::BitbucketServerController < Import::BaseController
clear_session_data
redirect_to new_import_bitbucket_server_path
end
# rubocop: enable CodeReuse/ActiveRecord
def jobs
render json: find_jobs('bitbucket_server')
......
......@@ -39,6 +39,7 @@ class Import::FogbugzController < Import::BaseController
redirect_to status_import_fogbugz_path
end
# rubocop: disable CodeReuse/ActiveRecord
def status
unless client.valid?
return redirect_to new_import_fogbugz_path
......@@ -51,6 +52,7 @@ class Import::FogbugzController < Import::BaseController
@repos.reject! { |repo| already_added_projects_names.include? repo.name }
end
# rubocop: enable CodeReuse/ActiveRecord
def jobs
render json: find_jobs('fogbugz')
......
......@@ -24,6 +24,7 @@ class Import::GithubController < Import::BaseController
redirect_to status_import_url
end
# rubocop: disable CodeReuse/ActiveRecord
def status
@repos = client.repos
@already_added_projects = find_already_added_projects(provider)
......@@ -31,6 +32,7 @@ class Import::GithubController < Import::BaseController
@repos.reject! { |repo| already_added_projects_names.include? repo.full_name }
end
# rubocop: enable CodeReuse/ActiveRecord
def jobs
render json: find_jobs(provider)
......@@ -106,9 +108,11 @@ class Import::GithubController < Import::BaseController
:github
end
# rubocop: disable CodeReuse/ActiveRecord
def logged_in_with_provider?
current_user.identities.exists?(provider: provider)
end
# rubocop: enable CodeReuse/ActiveRecord
def provider_auth
if session[access_token_key].blank?
......
......@@ -12,6 +12,7 @@ class Import::GitlabController < Import::BaseController
redirect_to status_import_gitlab_url
end
# rubocop: disable CodeReuse/ActiveRecord
def status
@repos = client.projects(starting_page: 1, page_limit: MAX_PROJECT_PAGES, per_page: PER_PAGE_PROJECTS)
......@@ -20,6 +21,7 @@ class Import::GitlabController < Import::BaseController
@repos = @repos.to_a.reject { |repo| already_added_projects_names.include? repo["path_with_namespace"] }
end
# rubocop: enable CodeReuse/ActiveRecord
def jobs
render json: find_jobs('gitlab')
......
......@@ -65,6 +65,7 @@ class Import::GoogleCodeController < Import::BaseController
redirect_to status_import_google_code_path
end
# rubocop: disable CodeReuse/ActiveRecord
def status
unless client.valid?
return redirect_to new_import_google_code_path
......@@ -78,6 +79,7 @@ class Import::GoogleCodeController < Import::BaseController
@repos.reject! { |repo| already_added_projects_names.include? repo.name }
end
# rubocop: enable CodeReuse/ActiveRecord
def jobs
render json: find_jobs('google_code')
......
......@@ -6,6 +6,7 @@ class Import::ManifestController < Import::BaseController
def new
end
# rubocop: disable CodeReuse/ActiveRecord
def status
@already_added_projects = find_already_added_projects
already_added_import_urls = @already_added_projects.pluck(:import_url)
......@@ -14,6 +15,7 @@ class Import::ManifestController < Import::BaseController
already_added_import_urls.include?(repository[:url])
end
end
# rubocop: enable CodeReuse/ActiveRecord
def upload
group = Group.find(params[:group_id])
......@@ -64,9 +66,11 @@ class Import::ManifestController < Import::BaseController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def group
@group ||= Group.find_by(id: session[:manifest_import_group_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def repositories
@repositories ||= session[:manifest_import_repositories]
......@@ -76,12 +80,14 @@ class Import::ManifestController < Import::BaseController
find_already_added_projects.to_json(only: [:id], methods: [:import_status])
end
# rubocop: disable CodeReuse/ActiveRecord
def find_already_added_projects
group.all_projects
.where(import_type: 'manifest')
.where(creator_id: current_user)
.includes(:import_state)
end
# rubocop: enable CodeReuse/ActiveRecord
def verify_import_enabled
render_404 unless manifest_import_enabled?
......
# frozen_string_literal: true
class InstanceStatistics::ConversationalDevelopmentIndexController < InstanceStatistics::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def index
@metric = ConversationalDevelopmentIndex::Metric.order(:created_at).last&.present
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -7,6 +7,7 @@ class PasswordsController < Devise::PasswordsController
prepend EE::PasswordsController
# rubocop: disable CodeReuse/ActiveRecord
def edit
super
reset_password_token = Devise.token_generator.digest(
......@@ -26,6 +27,7 @@ class PasswordsController < Devise::PasswordsController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def update
super do |resource|
......
......@@ -5,6 +5,7 @@ class Profiles::AccountsController < Profiles::ApplicationController
@user = current_user
end
# rubocop: disable CodeReuse/ActiveRecord
def unlink
provider = params[:provider]
identity = current_user.identities.find_by(provider: provider)
......@@ -19,4 +20,5 @@ class Profiles::AccountsController < Profiles::ApplicationController
redirect_to profile_account_path
end
# rubocop: enable CodeReuse/ActiveRecord
end
class Profiles::NotificationsController < Profiles::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def show
@user = current_user
@group_notifications = current_user.notification_settings.for_groups.order(:id)
@project_notifications = current_user.notification_settings.for_projects.order(:id)
@global_notification_setting = current_user.global_notification_setting
end
# rubocop: enable CodeReuse/ActiveRecord
def update
result = Users::UpdateService.new(current_user, user_params.merge(user: current_user)).execute
......
......@@ -38,6 +38,7 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
params.require(:personal_access_token).permit(:name, :expires_at, scopes: [])
end
# rubocop: disable CodeReuse/ActiveRecord
def set_index_vars
@scopes = Gitlab::Auth.available_scopes(current_user)
......@@ -46,4 +47,5 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
@new_personal_access_token = PersonalAccessToken.redis_getdel(current_user.id)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -44,11 +44,13 @@ class ProfilesController < Profiles::ApplicationController
redirect_to profile_personal_access_tokens_path
end
# rubocop: disable CodeReuse/ActiveRecord
def audit_log
@events = AuditEvent.where(entity_type: "User", entity_id: current_user.id)
.order("created_at DESC")
.page(params[:page])
end
# rubocop: enable CodeReuse/ActiveRecord
def update_username
result = Users::UpdateService.new(current_user, user: @user, username: username_param).execute
......
......@@ -82,16 +82,20 @@ class Projects::ArtifactsController < Projects::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def build_from_id
project.builds.find_by(id: params[:job_id]) if params[:job_id]
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def build_from_ref
return unless @ref_name
builds = project.latest_successful_builds_for(@ref_name)
builds.find_by(name: params[:job])
end
# rubocop: enable CodeReuse/ActiveRecord
def artifacts_file
@artifacts_file ||= build.artifacts_file
......
......@@ -177,6 +177,7 @@ class Projects::BlobController < Projects::ApplicationController
render_404
end
# rubocop: disable CodeReuse/ActiveRecord
def after_edit_path
from_merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).find_by(iid: params[:from_merge_request_iid])
if from_merge_request && @branch_name == @ref
......@@ -186,6 +187,7 @@ class Projects::BlobController < Projects::ApplicationController
project_blob_path(@project, File.join(@branch_name, @path))
end
end
# rubocop: enable CodeReuse/ActiveRecord
def editor_variables
@branch_name = params[:branch_name]
......
......@@ -48,6 +48,7 @@ class Projects::BranchesController < Projects::ApplicationController
@branches = @repository.recent_branches
end
# rubocop: disable CodeReuse/ActiveRecord
def create
branch_name = sanitize(strip_tags(params[:branch_name]))
branch_name = Addressable::URI.unescape(branch_name)
......@@ -88,6 +89,7 @@ class Projects::BranchesController < Projects::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def destroy
@branch_name = Addressable::URI.unescape(params[:id])
......
......@@ -42,14 +42,18 @@ class Projects::BuildArtifactsController < Projects::ApplicationController
@job ||= job_from_id || job_from_ref
end
# rubocop: disable CodeReuse/ActiveRecord
def job_from_id
project.builds.find_by(id: params[:build_id]) if params[:build_id]
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def job_from_ref
return unless @ref_name
jobs = project.latest_successful_builds_for(@ref_name)
jobs.find_by(name: params[:job])
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -4,6 +4,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
before_action :authorize_read_cluster!
before_action :authorize_create_cluster!, only: [:create]
# rubocop: disable CodeReuse/ActiveRecord
def create
application = @application_class.find_or_initialize_by(cluster: @cluster)
......@@ -23,6 +24,7 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
rescue StandardError
head :bad_request
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -38,6 +38,7 @@ class Projects::CommitController < Projects::ApplicationController
render_diff_for_path(@commit.diffs(diff_options))
end
# rubocop: disable CodeReuse/ActiveRecord
def pipelines
@pipelines = @commit.pipelines.order(id: :desc)
@pipelines = @pipelines.where(ref: params[:ref]) if params[:ref]
......@@ -58,6 +59,7 @@ class Projects::CommitController < Projects::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def merge_requests
@merge_requests = @commit.merge_requests.map do |mr|
......@@ -144,6 +146,7 @@ class Projects::CommitController < Projects::ApplicationController
@environment = EnvironmentsFinder.new(@project, current_user, commit: @commit).execute.last
end
# rubocop: disable CodeReuse/ActiveRecord
def define_note_vars
@noteable = @commit
@note = @project.build_commit_note(commit)
......@@ -176,6 +179,7 @@ class Projects::CommitController < Projects::ApplicationController
@notes = (@grouped_diff_discussions.values.flatten + @discussions).flat_map(&:notes)
@notes = prepare_notes_for_rendering(@notes, @commit)
end
# rubocop: enable CodeReuse/ActiveRecord
def assign_change_commit_vars
@start_branch = params[:start_branch]
......
......@@ -15,6 +15,7 @@ class Projects::CommitsController < Projects::ApplicationController
redirect_to project_commits_path(@project, @project.default_branch)
end
# rubocop: disable CodeReuse/ActiveRecord
def show
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
......@@ -32,6 +33,7 @@ class Projects::CommitsController < Projects::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def signatures
respond_to do |format|
......
......@@ -96,8 +96,10 @@ class Projects::CompareController < Projects::ApplicationController
@diff_notes_disabled = compare.present?
end
# rubocop: disable CodeReuse/ActiveRecord
def merge_request
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: head_ref, target_branch: start_ref)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -56,6 +56,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def disable
deploy_key_project = @project.deploy_keys_projects.find_by(deploy_key_id: params[:id])
return render_404 unless deploy_key_project
......@@ -69,6 +70,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
format.json { head :ok }
end
end
# rubocop: enable CodeReuse/ActiveRecord
protected
......
......@@ -2,6 +2,7 @@ class Projects::DeploymentsController < Projects::ApplicationController
before_action :authorize_read_environment!
before_action :authorize_read_deployment!
# rubocop: disable CodeReuse/ActiveRecord
def index
deployments = environment.deployments.reorder(created_at: :desc)
deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time
......@@ -9,6 +10,7 @@ class Projects::DeploymentsController < Projects::ApplicationController
render json: { deployments: DeploymentSerializer.new(project: project)
.represent_concise(deployments) }
end
# rubocop: enable CodeReuse/ActiveRecord
def metrics
return render_404 unless deployment.has_metrics?
......@@ -41,9 +43,11 @@ class Projects::DeploymentsController < Projects::ApplicationController
private
# rubocop: disable CodeReuse/ActiveRecord
def deployment
@deployment ||= environment.deployments.find_by(iid: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
def environment
@environment ||= project.environments.find(params[:environment_id])
......
......@@ -50,9 +50,11 @@ class Projects::DiscussionsController < Projects::ApplicationController
}
end
# rubocop: disable CodeReuse/ActiveRecord
def merge_request
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).find_by!(iid: params[:merge_request_id])
end
# rubocop: enable CodeReuse/ActiveRecord
def discussion
@discussion ||= @merge_request.find_discussion(params[:id]) || render_404
......
......@@ -33,6 +33,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def folder
folder_environments = project.environments.where(environment_type: params[:id])
@environments = folder_environments.with_state(params[:scope] || :available)
......@@ -53,10 +54,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def show
@deployments = environment.deployments.order(id: :desc).page(params[:page])
end
# rubocop: enable CodeReuse/ActiveRecord
def new
@environment = project.environments.new
......
......@@ -7,6 +7,7 @@ class Projects::ForksController < Projects::ApplicationController
before_action :authorize_download_code!
before_action :authenticate_user!, only: [:new, :create]
# rubocop: disable CodeReuse/ActiveRecord
def index
base_query = project.forks.includes(:creator)
......@@ -27,12 +28,14 @@ class Projects::ForksController < Projects::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def new
@namespaces = current_user.manageable_namespaces
@namespaces.delete(@project.namespace)
end
# rubocop: disable CodeReuse/ActiveRecord
def create
namespace = Namespace.find(params[:namespace_key])
......@@ -55,6 +58,7 @@ class Projects::ForksController < Projects::ApplicationController
render :error
end
end
# rubocop: enable CodeReuse/ActiveRecord
def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42335')
......
......@@ -165,6 +165,7 @@ class Projects::IssuesController < Projects::ApplicationController
protected
# rubocop: disable CodeReuse/ActiveRecord
def issue
return @issue if defined?(@issue)
......@@ -176,6 +177,7 @@ class Projects::IssuesController < Projects::ApplicationController
@issue
end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :subscribable_resource, :issue
alias_method :issuable, :issue
alias_method :awardable, :issue
......
......@@ -11,6 +11,7 @@ class Projects::JobsController < Projects::ApplicationController
layout 'project'
# rubocop: disable CodeReuse/ActiveRecord
def index
@scope = params[:scope]
@all_builds = project.builds.relevant
......@@ -33,6 +34,7 @@ class Projects::JobsController < Projects::ApplicationController
])
@builds = @builds.page(params[:page]).per(30).without_count
end
# rubocop: enable CodeReuse/ActiveRecord
def cancel_all
return access_denied! unless can?(current_user, :update_build, project)
......@@ -44,6 +46,7 @@ class Projects::JobsController < Projects::ApplicationController
redirect_to project_jobs_path(project)
end
# rubocop: disable CodeReuse/ActiveRecord
def show
@pipeline = @build.pipeline
@builds = @pipeline.builds
......@@ -61,6 +64,7 @@ class Projects::JobsController < Projects::ApplicationController
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def trace
build.trace.read do |stream|
......
......@@ -90,6 +90,7 @@ class Projects::LabelsController < Projects::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def set_priorities
Label.transaction do
available_labels_ids = @available_labels.where(id: params[:label_ids]).pluck(:id)
......@@ -105,6 +106,7 @@ class Projects::LabelsController < Projects::ApplicationController
format.json { render json: { message: 'success' } }
end
end
# rubocop: enable CodeReuse/ActiveRecord
def promote
promote_service = Labels::PromoteService.new(@project, @current_user)
......
......@@ -46,11 +46,13 @@ class Projects::LfsApiController < Projects::GitHttpClientController
params[:operation] == 'upload'
end
# rubocop: disable CodeReuse/ActiveRecord
def existing_oids
@existing_oids ||= begin
project.all_lfs_objects.where(oid: objects.map { |o| o['oid'].to_s }).pluck(:oid)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def download_objects!
objects.each do |object|
......
......@@ -56,6 +56,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
params[:size].to_i
end
# rubocop: disable CodeReuse/ActiveRecord
def store_file!(oid, size)
object = LfsObject.find_by(oid: oid, size: size)
unless object&.file&.exists?
......@@ -66,6 +67,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
link_to_project!(object)
end
# rubocop: enable CodeReuse/ActiveRecord
def create_file!(oid, size)
uploaded_file = UploadedFile.from_params(
......@@ -75,9 +77,11 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
LfsObject.create!(oid: oid, size: size, file: uploaded_file)
end
# rubocop: disable CodeReuse/ActiveRecord
def link_to_project!(object)
if object && !object.projects.exists?(storage_project.id)
object.lfs_objects_projects.create!(project: storage_project)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -7,9 +7,11 @@ class Projects::MergeRequests::ApplicationController < Projects::ApplicationCont
private
# rubocop: disable CodeReuse/ActiveRecord
def merge_request
@issuable = @merge_request ||= @project.merge_requests.includes(author: :status).find_by!(iid: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
def merge_request_params
params.require(:merge_request).permit(merge_request_params_attributes)
......
......@@ -111,6 +111,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap
set_pipeline_variables
end
# rubocop: disable CodeReuse/ActiveRecord
def selected_target_project
if @project.id.to_s == params[:target_project_id] || !@project.forked?
@project
......@@ -121,6 +122,7 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap
@project.forked_from_project
end
end
# rubocop: enable CodeReuse/ActiveRecord
def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42384')
......
......@@ -34,13 +34,16 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
@diffs = @compare.diffs(diff_options)
end
# rubocop: disable CodeReuse/ActiveRecord
def commit
return nil unless commit_id = params[:commit_id].presence
return nil unless @merge_request.all_commits.exists?(sha: commit_id)
@commit ||= @project.commit(commit_id)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_merge_request_diff_compare
@merge_request_diff =
if diff_id = params[:diff_id].presence
......@@ -68,6 +71,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
@merge_request_diff
end
end
# rubocop: enable CodeReuse/ActiveRecord
def additional_attributes
{
......
......@@ -118,9 +118,11 @@ class Projects::MilestonesController < Projects::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def milestone
@milestone ||= @project.milestones.find_by!(iid: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
def authorize_admin_milestone!
return render_404 unless can?(current_user, :admin_milestone, @project)
......
......@@ -5,9 +5,11 @@ class Projects::PagesController < Projects::ApplicationController
before_action :authorize_read_pages!, only: [:show]
before_action :authorize_update_pages!, except: [:show]
# rubocop: disable CodeReuse/ActiveRecord
def show
@domains = @project.pages_domains.order(:domain)
end
# rubocop: enable CodeReuse/ActiveRecord
def destroy
project.remove_pages
......
......@@ -70,7 +70,9 @@ class Projects::PagesDomainsController < Projects::ApplicationController
params.require(:pages_domain).permit(:key, :certificate)
end
# rubocop: disable CodeReuse/ActiveRecord
def domain
@domain ||= @project.pages_domains.find_by!(domain: params[:id].to_s)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -8,12 +8,14 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController
before_action :authorize_update_pipeline_schedule!, except: [:index, :new, :create, :play]
before_action :authorize_admin_pipeline_schedule!, only: [:destroy]
# rubocop: disable CodeReuse/ActiveRecord
def index
@scope = params[:scope]
@all_schedules = PipelineSchedulesFinder.new(@project).execute
@schedules = PipelineSchedulesFinder.new(@project).execute(scope: params[:scope])
.includes(:last_pipeline)
end
# rubocop: enable CodeReuse/ActiveRecord
def new
@schedule = project.pipeline_schedules.new
......
......@@ -161,6 +161,7 @@ class Projects::PipelinesController < Projects::ApplicationController
params.require(:pipeline).permit(:ref, variables_attributes: %i[key secret_value])
end
# rubocop: disable CodeReuse/ActiveRecord
def pipeline
@pipeline ||= project
.pipelines
......@@ -168,6 +169,7 @@ class Projects::PipelinesController < Projects::ApplicationController
.find_by!(id: params[:id])
.present(current_user: current_user)
end
# rubocop: enable CodeReuse/ActiveRecord
def whitelist_query_limiting
# Also see https://gitlab.com/gitlab-org/gitlab-ce/issues/42343
......
......@@ -6,6 +6,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
# Authorize
before_action :authorize_admin_project_member!, except: [:index, :leave, :request_access]
# rubocop: disable CodeReuse/ActiveRecord
def index
@sort = params[:sort].presence || sort_value_name
@group_links = @project.project_group_links
......@@ -25,6 +26,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
@requesters = present_members(AccessRequestsFinder.new(@project).execute(current_user))
@project_member = @project.project_members.new
end
# rubocop: enable CodeReuse/ActiveRecord
def import
@projects = current_user.authorized_projects.order_id_desc
......
......@@ -28,9 +28,11 @@ class Projects::ReleasesController < Projects::ApplicationController
@tag ||= @repository.find_tag(params[:tag_id])
end
# rubocop: disable CodeReuse/ActiveRecord
def release
@release ||= @project.releases.find_or_initialize_by(tag: @tag.name)
end
# rubocop: enable CodeReuse/ActiveRecord
def release_params
params.require(:release).permit(:description)
......
......@@ -33,6 +33,7 @@ module Projects
render 'show'
end
# rubocop: disable CodeReuse/ActiveRecord
def define_protected_refs
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
@protected_tags = @project.protected_tags.order(:name).page(params[:page])
......@@ -44,6 +45,7 @@ module Projects
load_gon_index
end
# rubocop: enable CodeReuse/ActiveRecord
def remote_mirror
@remote_mirror = project.remote_mirrors.first_or_initialize
......
......@@ -7,6 +7,7 @@ class Projects::TagsController < Projects::ApplicationController
before_action :authorize_push_code!, only: [:new, :create]
before_action :authorize_admin_project!, only: [:destroy]
# rubocop: disable CodeReuse/ActiveRecord
def index
params[:sort] = params[:sort].presence || sort_value_recently_updated
......@@ -23,7 +24,9 @@ class Projects::TagsController < Projects::ApplicationController
format.atom { render layout: 'xml.atom' }
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def show
@tag = @repository.find_tag(params[:id])
......@@ -32,6 +35,7 @@ class Projects::TagsController < Projects::ApplicationController
@release = @project.releases.find_or_initialize_by(tag: @tag.name)
@commit = @repository.commit(@tag.dereferenced_target)
end
# rubocop: enable CodeReuse/ActiveRecord
def create
result = Tags::CreateService.new(@project, current_user)
......
......@@ -27,12 +27,14 @@ class ProjectsController < Projects::ApplicationController
redirect_to(current_user ? root_path : explore_root_path)
end
# rubocop: disable CodeReuse/ActiveRecord
def new
namespace = Namespace.find_by(id: params[:namespace_id]) if params[:namespace_id]
return access_denied! if namespace && !can?(current_user, :create_projects, namespace)
@project = Project.new(namespace_id: namespace&.id)
end
# rubocop: enable CodeReuse/ActiveRecord
def edit
@badge_api_endpoint = expose_url(api_v4_projects_badges_path(id: @project.id))
......@@ -77,6 +79,7 @@ class ProjectsController < Projects::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def transfer
return access_denied! unless can?(current_user, :change_namespace, @project)
......@@ -87,6 +90,7 @@ class ProjectsController < Projects::ApplicationController
flash[:alert] = @project.errors[:new_namespace].first
end
end
# rubocop: enable CodeReuse/ActiveRecord
def remove_fork
return access_denied! unless can?(current_user, :remove_fork_project, @project)
......@@ -233,6 +237,7 @@ class ProjectsController < Projects::ApplicationController
}
end
# rubocop: disable CodeReuse/ActiveRecord
def refs
find_refs = params['find']
......@@ -267,6 +272,7 @@ class ProjectsController < Projects::ApplicationController
render json: options.to_json
end
# rubocop: enable CodeReuse/ActiveRecord
# Render project landing depending of which features are available
# So if page is not availble in the list it renders the next page
......@@ -305,6 +311,7 @@ class ProjectsController < Projects::ApplicationController
end
end
# rubocop: disable CodeReuse/ActiveRecord
def load_events
projects = Project.where(id: @project.id)
......@@ -314,6 +321,7 @@ class ProjectsController < Projects::ApplicationController
Events::RenderService.new(current_user).execute(@events, atom_request: request.format.atom?)
end
# rubocop: enable CodeReuse/ActiveRecord
def project_params
params.require(:project)
......
......@@ -31,6 +31,7 @@ class SearchController < ApplicationController
check_single_commit_result
end
# rubocop: disable CodeReuse/ActiveRecord
def autocomplete
term = params[:term]
......@@ -43,6 +44,7 @@ class SearchController < ApplicationController
render json: search_autocomplete_opts(term).to_json
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -108,6 +108,7 @@ class SessionsController < Devise::SessionsController
# Handle an "initial setup" state, where there's only one user, it's an admin,
# and they require a password change.
# rubocop: disable CodeReuse/ActiveRecord
def check_initial_setup
return unless User.limit(2).count == 1 # Count as much 2 to know if we have exactly one
......@@ -122,6 +123,7 @@ class SessionsController < Devise::SessionsController
redirect_to edit_user_password_path(reset_password_token: @token),
notice: "Please create a password for your new account."
end
# rubocop: enable CodeReuse/ActiveRecord
def user_params
params.require(:user).permit(:login, :password, :remember_me, :otp_attempt, :device_response)
......
......@@ -17,9 +17,11 @@ class Snippets::NotesController < ApplicationController
nil
end
# rubocop: disable CodeReuse/ActiveRecord
def snippet
PersonalSnippet.find_by(id: params[:snippet_id])
end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :noteable, :snippet
def note_params
......
......@@ -24,6 +24,7 @@ class SnippetsController < ApplicationController
layout 'snippets'
respond_to :html
# rubocop: disable CodeReuse/ActiveRecord
def index
if params[:username].present?
@user = User.find_by(username: params[:username])
......@@ -38,6 +39,7 @@ class SnippetsController < ApplicationController
redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def new
@snippet = PersonalSnippet.new
......@@ -94,9 +96,11 @@ class SnippetsController < ApplicationController
protected
# rubocop: disable CodeReuse/ActiveRecord
def snippet
@snippet ||= PersonalSnippet.inc_relations_for_view.find_by(id: params[:id])
end
# rubocop: enable CodeReuse/ActiveRecord
alias_method :awardable, :snippet
alias_method :spammable, :snippet
......
......@@ -13,9 +13,11 @@ class UserCalloutsController < ApplicationController
private
# rubocop: disable CodeReuse/ActiveRecord
def ensure_callout
current_user.callouts.find_or_create_by(feature_name: UserCallout.feature_names[feature_name])
end
# rubocop: enable CodeReuse/ActiveRecord
def feature_name
params.require(:feature_name)
......
......@@ -6,6 +6,7 @@ class Admin::ProjectsFinder
@current_user = current_user
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
items = Project.without_deleted.with_statistics.with_route
items = by_namespace_id(items)
......@@ -19,6 +20,7 @@ class Admin::ProjectsFinder
items = items.includes(namespace: [:owner, :route])
sort(items).page(params[:page])
end
# rubocop: enable CodeReuse/ActiveRecord
private
......@@ -26,9 +28,11 @@ class Admin::ProjectsFinder
params[:namespace_id].present? ? items.in_namespace(params[:namespace_id]) : items
end
# rubocop: disable CodeReuse/ActiveRecord
def by_visibilty_level(items)
params[:visibility_level].present? ? items.where(visibility_level: params[:visibility_level]) : items
end
# rubocop: enable CodeReuse/ActiveRecord
def by_with_push(items)
params[:with_push].present? ? items.with_push : items
......@@ -38,9 +42,11 @@ class Admin::ProjectsFinder
params[:abandoned].present? ? items.abandoned : items
end
# rubocop: disable CodeReuse/ActiveRecord
def by_last_repository_check_failed(items)
params[:last_repository_check_failed].present? ? items.where(last_repository_check_failed: true) : items
end
# rubocop: enable CodeReuse/ActiveRecord
def by_archived(items)
if params[:archived] == 'only'
......
......@@ -46,6 +46,7 @@ module Autocomplete
# Returns the users based on the input parameters, as an Array.
#
# This method is separate so it is easier to extend in EE.
# rubocop: disable CodeReuse/ActiveRecord
def limited_users
# When changing the order of these method calls, make sure that
# reorder_by_name() is called _before_ optionally_search(), otherwise
......@@ -63,6 +64,7 @@ module Autocomplete
.limit(LIMIT)
.to_a
end
# rubocop: enable CodeReuse/ActiveRecord
def prepend_current_user?
filter_by_current_user.present? && current_user
......@@ -72,6 +74,7 @@ module Autocomplete
author_id.present? && current_user
end
# rubocop: disable CodeReuse/ActiveRecord
def find_users
if project
project.authorized_users.union_with_user(author_id)
......@@ -83,5 +86,6 @@ module Autocomplete
User.none
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
module CustomAttributesFilter
# rubocop: disable CodeReuse/ActiveRecord
def by_custom_attributes(items)
return items unless params[:custom_attributes].is_a?(Hash)
return items unless Ability.allowed?(current_user, :read_custom_attribute)
......@@ -17,4 +18,5 @@ module CustomAttributesFilter
scope.where('EXISTS (?)', custom_attributes.where(key: key, value: value))
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
module FinderMethods
# rubocop: disable CodeReuse/ActiveRecord
def find_by!(*args)
raise_not_found_unless_authorized execute.find_by!(*args)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def find_by(*args)
if_authorized execute.find_by(*args)
end
# rubocop: enable CodeReuse/ActiveRecord
def find(*args)
raise_not_found_unless_authorized model.find(*args)
......
......@@ -14,6 +14,7 @@ module FinderWithCrossProjectAccess
end
override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute(*args)
check = Gitlab::CrossProjectAccess.find_check(self)
original = super
......@@ -27,6 +28,7 @@ module FinderWithCrossProjectAccess
original
end
end
# rubocop: enable CodeReuse/ActiveRecord
# We can skip the cross project check for finding indivitual records.
# this would be handled by the `can?(:read_*, result)` call in `FinderMethods`
......
......@@ -10,11 +10,13 @@ class ContributedProjectsFinder < UnionFinder
# visible by this user.
#
# Returns an ActiveRecord::Relation.
# rubocop: disable CodeReuse/ActiveRecord
def execute(current_user = nil)
segments = all_projects(current_user)
find_union(segments, Project).includes(:namespace).order_id_desc
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -5,6 +5,7 @@ class EnvironmentsFinder
@project, @current_user, @params = project, current_user, params
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
deployments = project.deployments
deployments =
......@@ -42,6 +43,7 @@ class EnvironmentsFinder
environments
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
......@@ -36,32 +36,42 @@ class EventsFinder
private
# rubocop: disable CodeReuse/ActiveRecord
def by_current_user_access(events)
events.merge(ProjectsFinder.new(current_user: current_user).execute)
events.merge(ProjectsFinder.new(current_user: current_user).execute) # rubocop: disable CodeReuse/Finder
.joins(:project)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_action(events)
return events unless Event::ACTIONS[params[:action]]
events.where(action: Event::ACTIONS[params[:action]])
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_target_type(events)
return events unless Event::TARGET_TYPES[params[:target_type]]
events.where(target_type: Event::TARGET_TYPES[params[:target_type]])
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_created_at_before(events)
return events unless params[:before]
events.where('events.created_at < ?', params[:before].beginning_of_day)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_created_at_after(events)
return events unless params[:after]
events.where('events.created_at > ?', params[:after].end_of_day)
end
# rubocop: enable CodeReuse/ActiveRecord
end
class ForkProjectsFinder < ProjectsFinder
# rubocop: disable CodeReuse/ActiveRecord
def initialize(project, params: {}, current_user: nil)
project_ids = project.forks.includes(:creator).select(:id)
super(params: params, current_user: current_user, project_ids_relation: project_ids)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -61,12 +61,16 @@ class GroupDescendantsFinder
end
def direct_child_groups
# rubocop: disable CodeReuse/Finder
GroupsFinder.new(current_user,
parent: parent_group,
all_available: true).execute
# rubocop: enable CodeReuse/Finder
end
# rubocop: disable CodeReuse/ActiveRecord
def all_visible_descendant_groups
# rubocop: disable CodeReuse/Finder
groups_table = Group.arel_table
visible_to_user = groups_table[:visibility_level]
.in(Gitlab::VisibilityLevel.levels_for_user(current_user))
......@@ -84,7 +88,9 @@ class GroupDescendantsFinder
hierarchy_for_parent
.descendants
.where(visible_to_user)
# rubocop: enable CodeReuse/Finder
end
# rubocop: enable CodeReuse/ActiveRecord
def subgroups_matching_filter
all_visible_descendant_groups
......@@ -101,24 +107,29 @@ class GroupDescendantsFinder
#
# So when searching 'project', on the 'subgroup' page we want to preload
# 'nested-group' but not 'subgroup' or 'root'
# rubocop: disable CodeReuse/ActiveRecord
def ancestors_of_groups(base_for_ancestors)
group_ids = base_for_ancestors.except(:select, :sort).select(:id)
Gitlab::GroupHierarchy.new(Group.where(id: group_ids))
.base_and_ancestors(upto: parent_group.id)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def ancestors_of_filtered_projects
projects_to_load_ancestors_of = projects.where.not(namespace: parent_group)
groups_to_load_ancestors_of = Group.where(id: projects_to_load_ancestors_of.select(:namespace_id))
ancestors_of_groups(groups_to_load_ancestors_of)
.with_selects_for_list(archived: params[:archived])
end
# rubocop: enable CodeReuse/ActiveRecord
def ancestors_of_filtered_subgroups
ancestors_of_groups(subgroups)
.with_selects_for_list(archived: params[:archived])
end
# rubocop: disable CodeReuse/ActiveRecord
def subgroups
return Group.none unless Group.supports_nested_groups?
......@@ -132,22 +143,29 @@ class GroupDescendantsFinder
groups.with_selects_for_list(archived: params[:archived]).order_by(sort)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/Finder
def direct_child_projects
GroupProjectsFinder.new(group: parent_group, current_user: current_user, params: params, options: { only_owned: true })
.execute
end
# rubocop: enable CodeReuse/Finder
# Finds all projects nested under `parent_group` or any of its descendant
# groups
# rubocop: disable CodeReuse/ActiveRecord
def projects_matching_filter
# rubocop: disable CodeReuse/Finder
projects_nested_in_group = Project.where(namespace_id: hierarchy_for_parent.base_and_descendants.select(:id))
params_with_search = params.merge(search: params[:filter])
ProjectsFinder.new(params: params_with_search,
current_user: current_user,
project_ids_relation: projects_nested_in_group).execute
# rubocop: enable CodeReuse/Finder
end
# rubocop: enable CodeReuse/ActiveRecord
def projects
projects = if params[:filter]
......@@ -163,7 +181,9 @@ class GroupDescendantsFinder
params.fetch(:sort, 'id_asc')
end
# rubocop: disable CodeReuse/ActiveRecord
def hierarchy_for_parent
@hierarchy ||= Gitlab::GroupHierarchy.new(Group.where(id: parent_group.id))
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -5,6 +5,7 @@ class GroupFinder
@current_user = current_user
end
# rubocop: disable CodeReuse/ActiveRecord
def execute(*params)
group = Group.find_by(*params)
......@@ -14,4 +15,5 @@ class GroupFinder
nil
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -3,6 +3,7 @@ class GroupMembersFinder
@group = group
end
# rubocop: disable CodeReuse/ActiveRecord
def execute(include_descendants: false)
group_members = @group.members
wheres = []
......@@ -29,4 +30,5 @@ class GroupMembersFinder
GroupMember.where(wheres.join(' OR '))
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -82,6 +82,7 @@ class GroupProjectsFinder < ProjectsFinder
options.fetch(:include_subgroups, false)
end
# rubocop: disable CodeReuse/ActiveRecord
def owned_projects
if include_subgroups?
Project.where(namespace_id: group.self_and_descendants.select(:id))
......@@ -89,6 +90,7 @@ class GroupProjectsFinder < ProjectsFinder
group.projects
end
end
# rubocop: enable CodeReuse/ActiveRecord
def shared_projects
group.shared_projects
......
......@@ -38,6 +38,7 @@ class GroupsFinder < UnionFinder
attr_reader :current_user, :params
# rubocop: disable CodeReuse/ActiveRecord
def all_groups
return [owned_groups] if params[:owned]
return [groups_with_min_access_level] if min_access_level?
......@@ -49,6 +50,7 @@ class GroupsFinder < UnionFinder
groups << Group.none if groups.empty?
groups
end
# rubocop: enable CodeReuse/ActiveRecord
def groups_for_ancestors
current_user.authorized_groups
......@@ -58,6 +60,7 @@ class GroupsFinder < UnionFinder
current_user.groups
end
# rubocop: disable CodeReuse/ActiveRecord
def groups_with_min_access_level
groups = current_user
.groups
......@@ -67,16 +70,21 @@ class GroupsFinder < UnionFinder
.new(groups)
.base_and_descendants
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_parent(groups)
return groups unless params[:parent]
groups.where(parent: params[:parent])
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def owned_groups
current_user&.owned_groups || Group.none
end
# rubocop: enable CodeReuse/ActiveRecord
def include_public_groups?
current_user.nil? || all_available?
......
......@@ -109,6 +109,7 @@ class IssuableFinder
# (even if that query is slower than any of the individual state queries) and
# grouping and counting within that query.
#
# rubocop: disable CodeReuse/ActiveRecord
def count_by_state
count_params = params.merge(state: nil, sort: nil)
finder = self.class.new(current_user, count_params)
......@@ -132,6 +133,7 @@ class IssuableFinder
counts.with_indifferent_access
end
# rubocop: enable CodeReuse/ActiveRecord
def group
return @group if defined?(@group)
......@@ -157,6 +159,7 @@ class IssuableFinder
@project = project
end
# rubocop: disable CodeReuse/ActiveRecord
def projects(items = nil)
return @projects = project if project?
......@@ -165,13 +168,14 @@ class IssuableFinder
current_user.authorized_projects
elsif group
finder_options = { include_subgroups: params[:include_subgroups], only_owned: true }
GroupProjectsFinder.new(group: group, current_user: current_user, options: finder_options).execute
GroupProjectsFinder.new(group: group, current_user: current_user, options: finder_options).execute # rubocop: disable CodeReuse/Finder
else
ProjectsFinder.new(current_user: current_user).execute
ProjectsFinder.new(current_user: current_user).execute # rubocop: disable CodeReuse/Finder
end
@projects = projects.with_feature_available_for_user(klass, current_user).reorder(nil)
end
# rubocop: enable CodeReuse/ActiveRecord
def search
params[:search].presence
......@@ -185,6 +189,7 @@ class IssuableFinder
milestones? && params[:milestone_title] == Milestone::None.title
end
# rubocop: disable CodeReuse/ActiveRecord
def milestones
return @milestones if defined?(@milestones)
......@@ -200,11 +205,12 @@ class IssuableFinder
search_params =
{ title: params[:milestone_title], project_ids: project_id, group_ids: group_id }
MilestonesFinder.new(search_params).execute
MilestonesFinder.new(search_params).execute # rubocop: disable CodeReuse/Finder
else
Milestone.none
end
end
# rubocop: enable CodeReuse/ActiveRecord
def labels?
params[:label_name].present?
......@@ -214,16 +220,18 @@ class IssuableFinder
labels? && params[:label_name].include?(Label::None.title)
end
# rubocop: disable CodeReuse/ActiveRecord
def labels
return @labels if defined?(@labels)
@labels =
if labels? && !filter_by_no_label?
LabelsFinder.new(current_user, project_ids: projects, title: label_names).execute(skip_authorization: true)
LabelsFinder.new(current_user, project_ids: projects, title: label_names).execute(skip_authorization: true) # rubocop: disable CodeReuse/Finder
else
Label.none
end
end
# rubocop: enable CodeReuse/ActiveRecord
def assignee_id?
params[:assignee_id].present? && params[:assignee_id] != NONE
......@@ -238,6 +246,7 @@ class IssuableFinder
params[:assignee_id] == NONE || params[:assignee_username] == NONE
end
# rubocop: disable CodeReuse/ActiveRecord
def assignee
return @assignee if defined?(@assignee)
......@@ -250,6 +259,7 @@ class IssuableFinder
nil
end
end
# rubocop: enable CodeReuse/ActiveRecord
def author_id?
params[:author_id].present? && params[:author_id] != NONE
......@@ -264,6 +274,7 @@ class IssuableFinder
params[:author_id] == NONE || params[:author_username] == NONE
end
# rubocop: disable CodeReuse/ActiveRecord
def author
return @author if defined?(@author)
......@@ -276,6 +287,7 @@ class IssuableFinder
nil
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......@@ -283,6 +295,7 @@ class IssuableFinder
klass.all
end
# rubocop: disable CodeReuse/ActiveRecord
def by_scope(items)
return items.none if current_user_related? && !current_user
......@@ -295,6 +308,7 @@ class IssuableFinder
items
end
end
# rubocop: enable CodeReuse/ActiveRecord
def by_updated_at(items)
items = items.updated_after(params[:updated_after]) if params[:updated_after].present?
......@@ -303,6 +317,7 @@ class IssuableFinder
items
end
# rubocop: disable CodeReuse/ActiveRecord
def by_state(items)
case params[:state].to_s
when 'closed'
......@@ -317,12 +332,14 @@ class IssuableFinder
items
end
end
# rubocop: enable CodeReuse/ActiveRecord
def by_group(items)
# Selection by group is already covered by `by_project` and `projects`
items
end
# rubocop: disable CodeReuse/ActiveRecord
def by_project(items)
items =
if project?
......@@ -335,6 +352,7 @@ class IssuableFinder
items
end
# rubocop: enable CodeReuse/ActiveRecord
def use_cte_for_search?
return false unless search
......@@ -343,6 +361,7 @@ class IssuableFinder
params[:use_cte_for_search]
end
# rubocop: disable CodeReuse/ActiveRecord
def by_search(items)
return items unless search
......@@ -355,17 +374,23 @@ class IssuableFinder
items.full_search(search)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_iids(items)
params[:iids].present? ? items.where(iid: params[:iids]) : items
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def sort(items)
# Ensure we always have an explicit sort order (instead of inheriting
# multiple orders when combining ActiveRecord::Relation objects).
params[:sort] ? items.sort_by_attribute(params[:sort], excluded_labels: label_names) : items.reorder(id: :desc)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_assignee(items)
if assignee
items = items.where(assignee_id: assignee.id)
......@@ -377,7 +402,9 @@ class IssuableFinder
items
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def by_author(items)
if author
items = items.where(author_id: author.id)
......@@ -389,6 +416,7 @@ class IssuableFinder
items
end
# rubocop: enable CodeReuse/ActiveRecord
def filter_by_upcoming_milestone?
params[:milestone_title] == Milestone::Upcoming.name
......@@ -398,6 +426,7 @@ class IssuableFinder
params[:milestone_title] == Milestone::Started.name
end
# rubocop: disable CodeReuse/ActiveRecord
def by_milestone(items)
if milestones?
if filter_by_no_milestone?
......@@ -414,6 +443,7 @@ class IssuableFinder
items
end
# rubocop: enable CodeReuse/ActiveRecord
def by_label(items)
return items unless labels?
......
......@@ -31,10 +31,13 @@ class IssuesFinder < IssuableFinder
@scalar_params ||= super + [:due_date]
end
# rubocop: disable CodeReuse/ActiveRecord
def klass
Issue.includes(:author)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def with_confidentiality_access_check
return Issue.all if user_can_see_all_confidential_issues?
return Issue.where('issues.confidential IS NOT TRUE') if user_cannot_see_confidential_issues?
......@@ -48,6 +51,7 @@ class IssuesFinder < IssuableFinder
user_id: current_user.id,
project_ids: current_user.authorized_projects(CONFIDENTIAL_ACCESS_LEVEL).select(:id))
end
# rubocop: enable CodeReuse/ActiveRecord
private
......@@ -127,6 +131,7 @@ class IssuesFinder < IssuableFinder
current_user.blank?
end
# rubocop: disable CodeReuse/ActiveRecord
def by_assignee(items)
if assignee
items.assigned_to(assignee)
......@@ -138,4 +143,5 @@ class IssuesFinder < IssuableFinder
items
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -10,6 +10,7 @@ class LabelsFinder < UnionFinder
@params = params
end
# rubocop: disable CodeReuse/ActiveRecord
def execute(skip_authorization: false)
@skip_authorization = skip_authorization
items = find_union(label_ids, Label) || Label.none
......@@ -17,11 +18,13 @@ class LabelsFinder < UnionFinder
items = by_search(items)
sort(items)
end
# rubocop: enable CodeReuse/ActiveRecord
private
attr_reader :current_user, :params, :skip_authorization
# rubocop: disable CodeReuse/ActiveRecord
def label_ids
label_ids = []
......@@ -52,7 +55,9 @@ class LabelsFinder < UnionFinder
label_ids
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def sort(items)
if params[:sort]
items.order_by(params[:sort])
......@@ -60,13 +65,16 @@ class LabelsFinder < UnionFinder
items.reorder(title: :asc)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def with_title(items)
return items if title.nil?
return items.none if title.blank?
items.where(title: title)
end
# rubocop: enable CodeReuse/ActiveRecord
def by_search(labels)
return labels unless search?
......@@ -138,13 +146,14 @@ class LabelsFinder < UnionFinder
@project
end
# rubocop: disable CodeReuse/ActiveRecord
def projects
return @projects if defined?(@projects)
@projects = if skip_authorization
Project.all
else
ProjectsFinder.new(params: { non_archived: true }, current_user: current_user).execute
ProjectsFinder.new(params: { non_archived: true }, current_user: current_user).execute # rubocop: disable CodeReuse/Finder
end
@projects = @projects.in_namespace(params[:group_id]) if group?
......@@ -153,6 +162,7 @@ class LabelsFinder < UnionFinder
@projects
end
# rubocop: enable CodeReuse/ActiveRecord
def authorized_to_read_labels?(label_parent)
return true if skip_authorization
......
......@@ -7,12 +7,13 @@ class MembersFinder
@group = project.group
end
# rubocop: disable CodeReuse/ActiveRecord
def execute(include_descendants: false)
project_members = project.project_members
project_members = project_members.non_invite unless can?(current_user, :admin_project, project)
if group
group_members = GroupMembersFinder.new(group).execute(include_descendants: include_descendants)
group_members = GroupMembersFinder.new(group).execute(include_descendants: include_descendants) # rubocop: disable CodeReuse/Finder
group_members = group_members.non_invite
union = Gitlab::SQL::Union.new([project_members, group_members], remove_duplicates: false)
......@@ -24,6 +25,7 @@ class MembersFinder
project_members
end
end
# rubocop: enable CodeReuse/ActiveRecord
def can?(*args)
Ability.allowed?(*args)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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