Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/access_requests.rb6
-rw-r--r--lib/api/award_emoji.rb2
-rw-r--r--lib/api/boards_responses.rb2
-rw-r--r--lib/api/branches.rb4
-rw-r--r--lib/api/commit_statuses.rb4
-rw-r--r--lib/api/commits.rb2
-rw-r--r--lib/api/custom_attributes_endpoints.rb6
-rw-r--r--lib/api/deploy_keys.rb8
-rw-r--r--lib/api/deployments.rb2
-rw-r--r--lib/api/discussions.rb4
-rw-r--r--lib/api/entities.rb14
-rw-r--r--lib/api/events.rb8
-rw-r--r--lib/api/features.rb2
-rw-r--r--lib/api/group_variables.rb6
-rw-r--r--lib/api/groups.rb2
-rw-r--r--lib/api/helpers.rb18
-rw-r--r--lib/api/helpers/custom_attributes.rb2
-rw-r--r--lib/api/helpers/members_helpers.rb4
-rw-r--r--lib/api/helpers/pagination.rb4
-rw-r--r--lib/api/internal.rb10
-rw-r--r--lib/api/issues.rb10
-rw-r--r--lib/api/job_artifacts.rb2
-rw-r--r--lib/api/jobs.rb6
-rw-r--r--lib/api/labels.rb6
-rw-r--r--lib/api/members.rb12
-rw-r--r--lib/api/merge_requests.rb2
-rw-r--r--lib/api/notes.rb2
-rw-r--r--lib/api/pages_domains.rb4
-rw-r--r--lib/api/pipeline_schedules.rb6
-rw-r--r--lib/api/pipelines.rb2
-rw-r--r--lib/api/project_snippets.rb8
-rw-r--r--lib/api/projects.rb4
-rw-r--r--lib/api/protected_branches.rb8
-rw-r--r--lib/api/protected_tags.rb6
-rw-r--r--lib/api/resource_label_events.rb3
-rw-r--r--lib/api/runner.rb2
-rw-r--r--lib/api/runners.rb2
-rw-r--r--lib/api/services.rb2
-rw-r--r--lib/api/snippets.rb8
-rw-r--r--lib/api/system_hooks.rb2
-rw-r--r--lib/api/triggers.rb2
-rw-r--r--lib/api/users.rb56
-rw-r--r--lib/api/variables.rb6
43 files changed, 271 insertions, 0 deletions
diff --git a/lib/api/access_requests.rb b/lib/api/access_requests.rb
index ae13c248171..18063fb20a2 100644
--- a/lib/api/access_requests.rb
+++ b/lib/api/access_requests.rb
@@ -18,6 +18,7 @@ module API
params do
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/access_requests" do
source = find_source(source_type, params[:id])
@@ -26,6 +27,7 @@ module API
present access_requesters, with: Entities::AccessRequester
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc "Requests access for the authenticated user to a #{source_type}." do
detail 'This feature was introduced in GitLab 8.11.'
@@ -50,6 +52,7 @@ module API
requires :user_id, type: Integer, desc: 'The user ID of the access requester'
optional :access_level, type: Integer, desc: 'A valid access level (defaults: `30`, developer access level)'
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ':id/access_requests/:user_id/approve' do
source = find_source(source_type, params[:id])
@@ -61,6 +64,7 @@ module API
status :created
present member, with: Entities::Member
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Denies an access request for the given user.' do
detail 'This feature was introduced in GitLab 8.11.'
@@ -68,6 +72,7 @@ module API
params do
requires :user_id, type: Integer, desc: 'The user ID of the access requester'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ":id/access_requests/:user_id" do
source = find_source(source_type, params[:id])
member = source.requesters.find_by!(user_id: params[:user_id])
@@ -76,6 +81,7 @@ module API
::Members::DestroyService.new(current_user).execute(member)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/award_emoji.rb b/lib/api/award_emoji.rb
index bde4b3ff4f6..e334af22183 100644
--- a/lib/api/award_emoji.rb
+++ b/lib/api/award_emoji.rb
@@ -103,6 +103,7 @@ module API
awardable.user_can_award?(current_user)
end
+ # rubocop: disable CodeReuse/ActiveRecord
def awardable
@awardable ||=
begin
@@ -119,6 +120,7 @@ module API
end
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
def read_ability(awardable)
case awardable
diff --git a/lib/api/boards_responses.rb b/lib/api/boards_responses.rb
index 7e873012efe..3322b37c6ff 100644
--- a/lib/api/boards_responses.rb
+++ b/lib/api/boards_responses.rb
@@ -49,11 +49,13 @@ module API
end
end
+ # rubocop: disable CodeReuse/ActiveRecord
def authorize_list_type_resource!
unless available_labels_for(board_parent).exists?(params[:label_id])
render_api_error!({ error: 'Label not found!' }, 400)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
params :list_creation_params do
requires :label_id, type: Integer, desc: 'The ID of an existing label'
diff --git a/lib/api/branches.rb b/lib/api/branches.rb
index 6c1d445e53d..7ab9f3bb4f0 100644
--- a/lib/api/branches.rb
+++ b/lib/api/branches.rb
@@ -73,6 +73,7 @@ module API
optional :developers_can_push, type: Boolean, desc: 'Flag if developers can push to that branch'
optional :developers_can_merge, type: Boolean, desc: 'Flag if developers can merge to that branch'
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ':id/repository/branches/:branch/protect', requirements: BRANCH_ENDPOINT_REQUIREMENTS do
authorize_admin_project
@@ -100,6 +101,7 @@ module API
render_api_error!(protected_branch.errors.full_messages, 422)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
# Note: This API will be deprecated in favor of the protected branches API.
desc 'Unprotect a single branch' do
@@ -108,6 +110,7 @@ module API
params do
requires :branch, type: String, desc: 'The name of the branch'
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ':id/repository/branches/:branch/unprotect', requirements: BRANCH_ENDPOINT_REQUIREMENTS do
authorize_admin_project
@@ -117,6 +120,7 @@ module API
present branch, with: Entities::Branch, current_user: current_user, project: user_project
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Create branch' do
success Entities::Branch
diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb
index 829eef18795..8e6f706afd4 100644
--- a/lib/api/commit_statuses.rb
+++ b/lib/api/commit_statuses.rb
@@ -21,6 +21,7 @@ module API
optional :all, type: String, desc: 'Show all statuses, default: false'
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/repository/commits/:sha/statuses' do
authorize!(:read_commit_status, user_project)
@@ -34,6 +35,7 @@ module API
statuses = statuses.where(name: params[:name]) if params[:name].present?
present paginate(statuses), with: Entities::CommitStatus
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Post status to a commit' do
success Entities::CommitStatus
@@ -49,6 +51,7 @@ module API
optional :context, type: String, desc: 'A string label to differentiate this status from the status of other systems. Default: "default"'
optional :coverage, type: Float, desc: 'The total code coverage'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ':id/statuses/:sha' do
authorize! :create_commit_status, user_project
@@ -118,6 +121,7 @@ module API
render_api_error!(e.message, 400)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index 3e8de3c8dae..5a134ed78fd 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -136,6 +136,7 @@ module API
use :pagination
requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/repository/commits/:sha/comments', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
commit = user_project.commit(params[:sha])
@@ -144,6 +145,7 @@ module API
present paginate(notes), with: Entities::CommitNote
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Cherry pick commit into a branch' do
detail 'This feature was introduced in GitLab 8.15'
diff --git a/lib/api/custom_attributes_endpoints.rb b/lib/api/custom_attributes_endpoints.rb
index 5000aa0d9ac..b5864665cc3 100644
--- a/lib/api/custom_attributes_endpoints.rb
+++ b/lib/api/custom_attributes_endpoints.rb
@@ -30,6 +30,7 @@ module API
params do
use :custom_attributes_key
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/custom_attributes/:key' do
resource = public_send(attributable_finder, params[:id]) # rubocop:disable GitlabSecurity/PublicSend
authorize! :read_custom_attribute
@@ -38,12 +39,14 @@ module API
present custom_attribute, with: Entities::CustomAttribute
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc "Set a custom attribute on a #{attributable_name}"
params do
use :custom_attributes_key
requires :value, type: String, desc: 'The value of the custom attribute'
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ':id/custom_attributes/:key' do
resource = public_send(attributable_finder, params[:id]) # rubocop:disable GitlabSecurity/PublicSend
authorize! :update_custom_attribute
@@ -59,11 +62,13 @@ module API
render_validation_error!(custom_attribute)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc "Delete a custom attribute on a #{attributable_name}"
params do
use :custom_attributes_key
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/custom_attributes/:key' do
resource = public_send(attributable_finder, params[:id]) # rubocop:disable GitlabSecurity/PublicSend
authorize! :update_custom_attribute
@@ -72,6 +77,7 @@ module API
status 204
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb
index 6769855b899..501e9f64db0 100644
--- a/lib/api/deploy_keys.rb
+++ b/lib/api/deploy_keys.rb
@@ -9,9 +9,11 @@ module API
project.deploy_keys_projects.create(attrs)
end
+ # rubocop: disable CodeReuse/ActiveRecord
def find_by_deploy_key(project, key_id)
project.deploy_keys_projects.find_by!(deploy_key: key_id)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
desc 'Return all deploy keys'
@@ -36,11 +38,13 @@ module API
params do
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/deploy_keys" do
keys = user_project.deploy_keys_projects.preload(:deploy_key)
present paginate(keys), with: Entities::DeployKeysProject
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get single deploy key' do
success Entities::DeployKeysProject
@@ -62,6 +66,7 @@ module API
requires :title, type: String, desc: 'The name of the deploy key'
optional :can_push, type: Boolean, desc: "Can deploy key push to the project's repository"
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ":id/deploy_keys" do
params[:key].strip!
@@ -94,6 +99,7 @@ module API
render_validation_error!(deploy_key_project)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Update an existing deploy key for a project' do
success Entities::SSHKey
@@ -147,12 +153,14 @@ module API
params do
requires :key_id, type: Integer, desc: 'The ID of the deploy key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ":id/deploy_keys/:key_id" do
deploy_key_project = user_project.deploy_keys_projects.find_by(deploy_key_id: params[:key_id])
not_found!('Deploy Key') unless deploy_key_project
destroy_conditionally!(deploy_key_project)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/deployments.rb b/lib/api/deployments.rb
index 184fae0eb76..b7892599295 100644
--- a/lib/api/deployments.rb
+++ b/lib/api/deployments.rb
@@ -18,11 +18,13 @@ module API
optional :order_by, type: String, values: %w[id iid created_at ref], default: 'id', desc: 'Return deployments ordered by `id` or `iid` or `created_at` or `ref`'
optional :sort, type: String, values: %w[asc desc], default: 'asc', desc: 'Sort by asc (ascending) or desc (descending)'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/deployments' do
authorize! :read_deployment, user_project
present paginate(user_project.deployments.order(params[:order_by] => params[:sort])), with: Entities::Deployment
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Gets a specific deployment' do
detail 'This feature was introduced in GitLab 8.11.'
diff --git a/lib/api/discussions.rb b/lib/api/discussions.rb
index 13c34e3473a..88668992215 100644
--- a/lib/api/discussions.rb
+++ b/lib/api/discussions.rb
@@ -23,6 +23,7 @@ module API
requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable'
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/#{noteables_path}/:noteable_id/discussions" do
noteable = find_noteable(parent_type, noteables_str, params[:noteable_id])
@@ -36,6 +37,7 @@ module API
present paginate(discussions), with: Entities::Discussion
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc "Get a single #{noteable_type.to_s.downcase} discussion" do
success Entities::Discussion
@@ -219,6 +221,7 @@ module API
end
helpers do
+ # rubocop: disable CodeReuse/ActiveRecord
def readable_discussion_notes(noteable, discussion_id)
notes = noteable.notes
.where(discussion_id: discussion_id)
@@ -228,6 +231,7 @@ module API
notes.reject { |n| n.cross_reference_not_visible_for?(current_user) }
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index f0eafbaeb94..0fec3dc3dc4 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -168,6 +168,7 @@ module API
expose :namespace, using: 'API::Entities::NamespaceBasic'
expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
+ # rubocop: disable CodeReuse/ActiveRecord
def self.preload_relation(projects_relation, options = {})
# Preloading tags, should be done with using only `:tags`,
# as `:tags` are defined as: `has_many :tags, through: :taggings`
@@ -177,6 +178,7 @@ module API
.preload(:import_state, :tags)
.preload(namespace: [:route, :owner])
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
class Project < BasicProjectDetails
@@ -247,6 +249,7 @@ module API
expose :statistics, using: 'API::Entities::ProjectStatistics', if: :statistics
+ # rubocop: disable CodeReuse/ActiveRecord
def self.preload_relation(projects_relation, options = {})
# Preloading tags, should be done with using only `:tags`,
# as `:tags` are defined as: `has_many :tags, through: :taggings`
@@ -258,6 +261,7 @@ module API
forked_project_link: :forked_from_project,
forked_from_project: [:route, :forks, :tags, namespace: :route])
end
+ # rubocop: enable CodeReuse/ActiveRecord
def self.forks_counting_projects(projects_relation)
projects_relation + projects_relation.map(&:forked_from_project).compact
@@ -558,10 +562,12 @@ module API
expose :total_time_spent, as: :human_total_time_spent
end
+ # rubocop: disable CodeReuse/ActiveRecord
def total_time_spent
# Avoids an N+1 query since timelogs are preloaded
object.timelogs.map(&:time_spent).sum
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
class ExternalIssue < Grape::Entity
@@ -936,6 +942,7 @@ module API
end
end
+ # rubocop: disable CodeReuse/ActiveRecord
def self.preload_relation(projects_relation, options = {})
relation = super(projects_relation, options)
@@ -960,6 +967,7 @@ module API
relation
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
class LabelBasic < Grape::Entity
@@ -1066,9 +1074,11 @@ module API
options[:project].repository.commit(repo_tag.dereferenced_target)
end
+ # rubocop: disable CodeReuse/ActiveRecord
expose :release, using: Entities::Release do |repo_tag, options|
options[:project].releases.find_by(tag: repo_tag.name)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
class Runner < Grape::Entity
@@ -1091,6 +1101,7 @@ module API
expose :version, :revision, :platform, :architecture
expose :contacted_at
expose :token, if: lambda { |runner, options| options[:current_user].admin? || !runner.instance_type? }
+ # rubocop: disable CodeReuse/ActiveRecord
expose :projects, with: Entities::BasicProjectDetails do |runner, options|
if options[:current_user].admin?
runner.projects
@@ -1098,6 +1109,8 @@ module API
options[:current_user].authorized_projects.where(id: runner.projects)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
expose :groups, with: Entities::BasicGroupDetails do |runner, options|
if options[:current_user].admin?
runner.groups
@@ -1105,6 +1118,7 @@ module API
options[:current_user].authorized_groups.where(id: runner.groups)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
class RunnerRegistrationDetails < Grape::Entity
diff --git a/lib/api/events.rb b/lib/api/events.rb
index a415508a632..dfe0e81af26 100644
--- a/lib/api/events.rb
+++ b/lib/api/events.rb
@@ -16,12 +16,14 @@ module API
desc: 'Return events sorted in ascending and descending order'
end
+ # rubocop: disable CodeReuse/ActiveRecord
def present_events(events)
events = events.reorder(created_at: params[:sort])
.with_associations
present paginate(events), with: Entities::Event
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
resource :events do
@@ -36,6 +38,7 @@ module API
use :event_filter_params
use :sort_params
end
+ # rubocop: disable CodeReuse/ActiveRecord
get do
authenticate!
@@ -43,6 +46,7 @@ module API
present_events(events)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
params do
@@ -60,6 +64,7 @@ module API
use :event_filter_params
use :sort_params
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/events' do
user = find_user(params[:id])
not_found!('User') unless user
@@ -68,6 +73,7 @@ module API
present_events(events)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
params do
@@ -82,11 +88,13 @@ module API
use :event_filter_params
use :sort_params
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/events" do
events = EventsFinder.new(params.merge(source: user_project, current_user: current_user)).execute.preload(:author, :target)
present_events(events)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/features.rb b/lib/api/features.rb
index 11d848584d9..79be8c1903e 100644
--- a/lib/api/features.rb
+++ b/lib/api/features.rb
@@ -14,6 +14,7 @@ module API
end
end
+ # rubocop: disable CodeReuse/ActiveRecord
def gate_targets(params)
targets = []
targets << Feature.group(params[:feature_group]) if params[:feature_group]
@@ -21,6 +22,7 @@ module API
targets
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
resource :features do
diff --git a/lib/api/group_variables.rb b/lib/api/group_variables.rb
index 55d5c7f1606..b6610dd04b3 100644
--- a/lib/api/group_variables.rb
+++ b/lib/api/group_variables.rb
@@ -27,6 +27,7 @@ module API
params do
requires :key, type: String, desc: 'The key of the variable'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/variables/:key' do
key = params[:key]
variable = user_group.variables.find_by(key: key)
@@ -35,6 +36,7 @@ module API
present variable, with: Entities::Variable
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Create a new variable in a group' do
success Entities::Variable
@@ -64,6 +66,7 @@ module API
optional :value, type: String, desc: 'The value of the variable'
optional :protected, type: String, desc: 'Whether the variable is protected'
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ':id/variables/:key' do
variable = user_group.variables.find_by(key: params[:key])
@@ -77,6 +80,7 @@ module API
render_validation_error!(variable)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing variable from a group' do
success Entities::Variable
@@ -84,12 +88,14 @@ module API
params do
requires :key, type: String, desc: 'The key of the variable'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/variables/:key' do
variable = user_group.variables.find_by(key: params[:key])
not_found!('GroupVariable') unless variable
destroy_conditionally!(variable)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index b4f441f6a4f..018ca72c32a 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -38,6 +38,7 @@ module API
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
def find_groups(params, parent_id = nil)
find_params = params.slice(:all_available, :custom_attributes, :owned, :min_access_level)
find_params[:parent] = find_group!(parent_id) if parent_id
@@ -53,6 +54,7 @@ module API
groups
end
+ # rubocop: enable CodeReuse/ActiveRecord
def find_group_projects(params)
group = find_group!(params[:id])
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 5505d7a7b08..458cfc9d9a4 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -94,6 +94,7 @@ module API
LabelsFinder.new(current_user, search_params).execute
end
+ # rubocop: disable CodeReuse/ActiveRecord
def find_user(id)
if id =~ /^\d+$/
User.find_by(id: id)
@@ -101,7 +102,9 @@ module API
User.find_by(username: id)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def find_project(id)
if id.is_a?(Integer) || id =~ /^\d+$/
Project.find_by(id: id)
@@ -109,6 +112,7 @@ module API
Project.find_by_full_path(id)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
def find_project!(id)
project = find_project(id)
@@ -120,6 +124,7 @@ module API
end
end
+ # rubocop: disable CodeReuse/ActiveRecord
def find_group(id)
if id.to_s =~ /^\d+$/
Group.find_by(id: id)
@@ -127,6 +132,7 @@ module API
Group.find_by_full_path(id)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
def find_group!(id)
group = find_group(id)
@@ -138,6 +144,7 @@ module API
end
end
+ # rubocop: disable CodeReuse/ActiveRecord
def find_namespace(id)
if id.to_s =~ /^\d+$/
Namespace.find_by(id: id)
@@ -145,6 +152,7 @@ module API
Namespace.find_by_full_path(id)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
def find_namespace!(id)
namespace = find_namespace(id)
@@ -169,13 +177,17 @@ module API
label || not_found!('Label')
end
+ # rubocop: disable CodeReuse/ActiveRecord
def find_project_issue(iid)
IssuesFinder.new(current_user, project_id: user_project.id).find_by!(iid: iid)
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def find_project_merge_request(iid)
MergeRequestsFinder.new(current_user, project_id: user_project.id).find_by!(iid: iid)
end
+ # rubocop: enable CodeReuse/ActiveRecord
def find_project_commit(id)
user_project.commit_by(oid: id)
@@ -186,11 +198,13 @@ module API
SnippetsFinder.new(current_user, finder_params).find(id)
end
+ # rubocop: disable CodeReuse/ActiveRecord
def find_merge_request_with_access(iid, access_level = :read_merge_request)
merge_request = user_project.merge_requests.find_by!(iid: iid)
authorize! access_level, merge_request
merge_request
end
+ # rubocop: enable CodeReuse/ActiveRecord
def find_build!(id)
user_project.builds.find(id.to_i)
@@ -282,9 +296,11 @@ module API
Gitlab.rails5? ? permitted_attrs.to_h : permitted_attrs
end
+ # rubocop: disable CodeReuse/ActiveRecord
def filter_by_iid(items, iid)
items.where(iid: iid)
end
+ # rubocop: enable CodeReuse/ActiveRecord
def filter_by_search(items, text)
items.search(text)
@@ -381,9 +397,11 @@ module API
# project helpers
+ # rubocop: disable CodeReuse/ActiveRecord
def reorder_projects(projects)
projects.reorder(params[:order_by] => params[:sort])
end
+ # rubocop: enable CodeReuse/ActiveRecord
def project_finder_params
finder_params = {}
diff --git a/lib/api/helpers/custom_attributes.rb b/lib/api/helpers/custom_attributes.rb
index 10d652e33f5..3bbe827967e 100644
--- a/lib/api/helpers/custom_attributes.rb
+++ b/lib/api/helpers/custom_attributes.rb
@@ -12,6 +12,7 @@ module API
desc: 'Filter with custom attributes'
end
+ # rubocop: disable CodeReuse/ActiveRecord
def with_custom_attributes(collection_or_resource, options = {})
options = options.merge(
with_custom_attributes: params[:with_custom_attributes] &&
@@ -24,6 +25,7 @@ module API
[collection_or_resource, options]
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/helpers/members_helpers.rb b/lib/api/helpers/members_helpers.rb
index fed8846e505..518aaa62aef 100644
--- a/lib/api/helpers/members_helpers.rb
+++ b/lib/api/helpers/members_helpers.rb
@@ -17,6 +17,7 @@ module API
.non_request
end
+ # rubocop: disable CodeReuse/ActiveRecord
def find_all_members_for_project(project)
shared_group_ids = project.project_group_links.pluck(:group_id)
project_group_ids = project.group&.self_and_ancestors&.pluck(:id)
@@ -28,13 +29,16 @@ module API
.where(project_authorizations: { project_id: project.id })
.where(source_id: source_ids)
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def find_all_members_for_group(group)
source_ids = group.self_and_ancestors.pluck(:id)
Member.includes(:user)
.where(source_id: source_ids)
.where(source_type: 'Namespace')
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/helpers/pagination.rb b/lib/api/helpers/pagination.rb
index 3308212216e..50bcd4e0437 100644
--- a/lib/api/helpers/pagination.rb
+++ b/lib/api/helpers/pagination.rb
@@ -91,6 +91,7 @@ module API
@request_context = request_context
end
+ # rubocop: disable CodeReuse/ActiveRecord
def paginate(relation)
pagination = KeysetPaginationInfo.new(relation, request_context)
@@ -112,6 +113,7 @@ module API
paged_relation
end
+ # rubocop: enable CodeReuse/ActiveRecord
private
@@ -183,6 +185,7 @@ module API
private
+ # rubocop: disable CodeReuse/ActiveRecord
def add_default_order(relation)
if relation.is_a?(ActiveRecord::Relation) && relation.order_values.empty?
relation = relation.order(:id)
@@ -190,6 +193,7 @@ module API
relation
end
+ # rubocop: enable CodeReuse/ActiveRecord
def add_pagination_headers(paginated_data)
header 'X-Per-Page', paginated_data.limit_value.to_s
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index e3e8cb71c09..71b87f60bf6 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -26,6 +26,7 @@ module API
# project - project full_path (not path on disk)
# action - git action (git-upload-pack or git-receive-pack)
# changes - changes as "oldrev newrev ref", see Gitlab::ChangesList
+ # rubocop: disable CodeReuse/ActiveRecord
post "/allowed" do
# Stores some Git-specific env thread-safely
env = parse_env
@@ -96,7 +97,9 @@ module API
response_with_status(code: 500, success: false, message: UNKNOWN_CHECK_RESULT_ERROR)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
post "/lfs_authenticate" do
status 200
@@ -118,6 +121,7 @@ module API
repository_http_path: project.http_url_to_repo
}
end
+ # rubocop: enable CodeReuse/ActiveRecord
get "/merge_request_urls" do
merge_request_urls
@@ -126,6 +130,7 @@ module API
#
# Get a ssh key using the fingerprint
#
+ # rubocop: disable CodeReuse/ActiveRecord
get "/authorized_keys" do
fingerprint = params.fetch(:fingerprint) do
Gitlab::InsecureKeyFingerprint.new(params.fetch(:key)).fingerprint
@@ -134,10 +139,12 @@ module API
not_found!("Key") if key.nil?
present key, with: Entities::SSHKey
end
+ # rubocop: enable CodeReuse/ActiveRecord
#
# Discover user by ssh key, user id or username
#
+ # rubocop: disable CodeReuse/ActiveRecord
get "/discover" do
if params[:key_id]
key = Key.find(params[:key_id])
@@ -150,6 +157,7 @@ module API
present user, with: Entities::UserSafe
end
+ # rubocop: enable CodeReuse/ActiveRecord
get "/check" do
{
@@ -176,6 +184,7 @@ module API
end
end
+ # rubocop: disable CodeReuse/ActiveRecord
post '/two_factor_recovery_codes' do
status 200
@@ -217,6 +226,7 @@ module API
{ success: true, recovery_codes: codes }
end
+ # rubocop: enable CodeReuse/ActiveRecord
post '/pre_receive' do
status 200
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index cedfd2fbaa0..bcb03a0b540 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -7,6 +7,7 @@ module API
helpers ::Gitlab::IssuableMetadata
helpers do
+ # rubocop: disable CodeReuse/ActiveRecord
def find_issues(args = {})
args = declared_params.merge(args)
@@ -20,6 +21,7 @@ module API
issues.reorder(args[:order_by] => args[:sort])
end
+ # rubocop: enable CodeReuse/ActiveRecord
params :issues_params do
optional :labels, type: String, desc: 'Comma-separated list of label names'
@@ -207,6 +209,7 @@ module API
at_least_one_of :title, :description, :assignee_ids, :assignee_id, :milestone_id, :discussion_locked,
:labels, :created_at, :due_date, :confidential, :state_event
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ':id/issues/:issue_iid' do
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42322')
@@ -234,6 +237,7 @@ module API
render_validation_error!(issue)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Move an existing issue' do
success Entities::Issue
@@ -242,6 +246,7 @@ module API
requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue'
requires :to_project_id, type: Integer, desc: 'The ID of the new project'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ':id/issues/:issue_iid/move' do
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42323')
@@ -258,11 +263,13 @@ module API
render_api_error!(error.message, 400)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete a project issue'
params do
requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ":id/issues/:issue_iid" do
issue = user_project.issues.find_by(iid: params[:issue_iid])
not_found!('Issue') unless issue
@@ -273,6 +280,7 @@ module API
Issuable::DestroyService.new(user_project, current_user).execute(issue)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'List merge requests closing issue' do
success Entities::MergeRequestBasic
@@ -280,6 +288,7 @@ module API
params do
requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/issues/:issue_iid/closed_by' do
issue = find_project_issue(params[:issue_iid])
@@ -288,6 +297,7 @@ module API
present paginate(merge_requests), with: Entities::MergeRequestBasic, current_user: current_user, project: user_project
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'List participants for an issue' do
success Entities::UserBasic
diff --git a/lib/api/job_artifacts.rb b/lib/api/job_artifacts.rb
index 32379d7c8ab..ab4203c4e25 100644
--- a/lib/api/job_artifacts.rb
+++ b/lib/api/job_artifacts.rb
@@ -21,6 +21,7 @@ module API
requires :job, type: String, desc: 'The name for the job'
end
route_setting :authentication, job_token_allowed: true
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/jobs/artifacts/:ref_name/download',
requirements: { ref_name: /.+/ } do
authorize_download_artifacts!
@@ -30,6 +31,7 @@ module API
present_carrierwave_file!(latest_build.artifacts_file)
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Download the artifacts archive from a job' do
detail 'This feature was introduced in GitLab 8.5'
diff --git a/lib/api/jobs.rb b/lib/api/jobs.rb
index fc8c52085ab..27ffd42834c 100644
--- a/lib/api/jobs.rb
+++ b/lib/api/jobs.rb
@@ -34,6 +34,7 @@ module API
use :optional_scope
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/jobs' do
builds = user_project.builds.order('id DESC')
builds = filter_builds(builds, params[:scope])
@@ -41,6 +42,7 @@ module API
builds = builds.preload(:user, :job_artifacts_archive, :job_artifacts, :runner, pipeline: :project)
present paginate(builds), with: Entities::Job
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get pipeline jobs' do
success Entities::Job
@@ -50,6 +52,7 @@ module API
use :optional_scope
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/pipelines/:pipeline_id/jobs' do
pipeline = user_project.pipelines.find(params[:pipeline_id])
builds = pipeline.builds
@@ -58,6 +61,7 @@ module API
present paginate(builds), with: Entities::Job
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a specific job of a project' do
success Entities::Job
@@ -168,6 +172,7 @@ module API
end
helpers do
+ # rubocop: disable CodeReuse/ActiveRecord
def filter_builds(builds, scope)
return builds if scope.nil? || scope.empty?
@@ -178,6 +183,7 @@ module API
builds.where(status: available_statuses && scope)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/labels.rb b/lib/api/labels.rb
index 81eaf56e48e..98c9818db39 100644
--- a/lib/api/labels.rb
+++ b/lib/api/labels.rb
@@ -27,6 +27,7 @@ module API
optional :description, type: String, desc: 'The description of label to be created'
optional :priority, type: Integer, desc: 'The priority of the label', allow_blank: true
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ':id/labels' do
authorize! :admin_label, user_project
@@ -43,6 +44,7 @@ module API
render_validation_error!(label)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing label' do
success Entities::Label
@@ -50,6 +52,7 @@ module API
params do
requires :name, type: String, desc: 'The name of the label to be deleted'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/labels' do
authorize! :admin_label, user_project
@@ -58,6 +61,7 @@ module API
destroy_conditionally!(label)
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Update an existing label. At least one optional parameter is required.' do
success Entities::Label
@@ -70,6 +74,7 @@ module API
optional :priority, type: Integer, desc: 'The priority of the label', allow_blank: true
at_least_one_of :new_name, :color, :description, :priority
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ':id/labels' do
authorize! :admin_label, user_project
@@ -95,6 +100,7 @@ module API
present label, with: Entities::Label, current_user: current_user, project: user_project
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/members.rb b/lib/api/members.rb
index d23dd834c69..4d8e23dee91 100644
--- a/lib/api/members.rb
+++ b/lib/api/members.rb
@@ -18,6 +18,7 @@ module API
optional :query, type: String, desc: 'A query string to search for members'
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/members" do
source = find_source(source_type, params[:id])
@@ -27,6 +28,7 @@ module API
present members, with: Entities::Member
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Gets a list of group or project members viewable by the authenticated user, including those who gained membership through ancestor group.' do
success Entities::Member
@@ -35,6 +37,7 @@ module API
optional :query, type: String, desc: 'A query string to search for members'
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/members/all" do
source = find_source(source_type, params[:id])
@@ -44,6 +47,7 @@ module API
present members, with: Entities::Member
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Gets a member of a group or project.' do
success Entities::Member
@@ -51,6 +55,7 @@ module API
params do
requires :user_id, type: Integer, desc: 'The user ID of the member'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/members/:user_id" do
source = find_source(source_type, params[:id])
@@ -59,6 +64,7 @@ module API
present member, with: Entities::Member
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Adds a member to a group or project.' do
success Entities::Member
@@ -68,6 +74,7 @@ module API
requires :access_level, type: Integer, desc: 'A valid access level (defaults: `30`, developer access level)'
optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ":id/members" do
source = find_source(source_type, params[:id])
authorize_admin_source!(source_type, source)
@@ -88,6 +95,7 @@ module API
render_validation_error!(member)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Updates a member of a group or project.' do
success Entities::Member
@@ -97,6 +105,7 @@ module API
requires :access_level, type: Integer, desc: 'A valid access level'
optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY'
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ":id/members/:user_id" do
source = find_source(source_type, params.delete(:id))
authorize_admin_source!(source_type, source)
@@ -113,11 +122,13 @@ module API
render_validation_error!(updated_member)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Removes a user from a group or project.'
params do
requires :user_id, type: Integer, desc: 'The user ID of the member'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ":id/members/:user_id" do
source = find_source(source_type, params[:id])
member = source.members.find_by!(user_id: params[:user_id])
@@ -126,6 +137,7 @@ module API
::Members::DestroyService.new(current_user).execute(member)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 55f54fe3c43..cad38271cbb 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -28,6 +28,7 @@ module API
end
helpers do
+ # rubocop: disable CodeReuse/ActiveRecord
def find_merge_requests(args = {})
args = declared_params.merge(args)
@@ -45,6 +46,7 @@ module API
merge_requests
.preload(:notes, :author, :assignee, :milestone, :latest_merge_request_diff, :labels, :timelogs)
end
+ # rubocop: enable CodeReuse/ActiveRecord
def merge_request_pipelines_with_access
authorize! :read_pipeline, user_project
diff --git a/lib/api/notes.rb b/lib/api/notes.rb
index 39923e6d5b5..dc9373bb3c2 100644
--- a/lib/api/notes.rb
+++ b/lib/api/notes.rb
@@ -28,6 +28,7 @@ module API
desc: 'Return notes sorted in `asc` or `desc` order.'
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/#{noteables_str}/:noteable_id/notes" do
noteable = find_noteable(parent_type, noteables_str, params[:noteable_id])
@@ -45,6 +46,7 @@ module API
.reject { |n| n.cross_reference_not_visible_for?(current_user) }
present notes, with: Entities::Note
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc "Get a single #{noteable_type.to_s.downcase} note" do
success Entities::Note
diff --git a/lib/api/pages_domains.rb b/lib/api/pages_domains.rb
index ba33993d852..8730c91b426 100644
--- a/lib/api/pages_domains.rb
+++ b/lib/api/pages_domains.rb
@@ -13,9 +13,11 @@ module API
end
helpers do
+ # rubocop: disable CodeReuse/ActiveRecord
def find_pages_domain!
user_project.pages_domains.find_by(domain: params[:domain]) || not_found!('PagesDomain')
end
+ # rubocop: enable CodeReuse/ActiveRecord
def pages_domain
@pages_domain ||= find_pages_domain!
@@ -61,11 +63,13 @@ module API
params do
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/pages/domains" do
authorize! :read_pages, user_project
present paginate(user_project.pages_domains.order(:domain)), with: Entities::PagesDomain
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a single pages domain' do
success Entities::PagesDomain
diff --git a/lib/api/pipeline_schedules.rb b/lib/api/pipeline_schedules.rb
index 37f32411296..f858e199f36 100644
--- a/lib/api/pipeline_schedules.rb
+++ b/lib/api/pipeline_schedules.rb
@@ -16,6 +16,7 @@ module API
optional :scope, type: String, values: %w[active inactive],
desc: 'The scope of pipeline schedules'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/pipeline_schedules' do
authorize! :read_pipeline_schedule, user_project
@@ -23,6 +24,7 @@ module API
.preload([:owner, :last_pipeline])
present paginate(schedules), with: Entities::PipelineSchedule
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a single pipeline schedule' do
success Entities::PipelineScheduleDetails
@@ -161,6 +163,7 @@ module API
end
helpers do
+ # rubocop: disable CodeReuse/ActiveRecord
def pipeline_schedule
@pipeline_schedule ||=
user_project
@@ -172,7 +175,9 @@ module API
end
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def pipeline_schedule_variable
@pipeline_schedule_variable ||=
pipeline_schedule.variables.find_by(key: params[:key]).tap do |pipeline_schedule_variable|
@@ -181,6 +186,7 @@ module API
end
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/pipelines.rb b/lib/api/pipelines.rb
index 5d33a13d035..5cce96d5ae7 100644
--- a/lib/api/pipelines.rb
+++ b/lib/api/pipelines.rb
@@ -43,6 +43,7 @@ module API
requires :ref, type: String, desc: 'Reference'
optional :variables, Array, desc: 'Array of variables available in the pipeline'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ':id/pipeline' do
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42124')
@@ -63,6 +64,7 @@ module API
render_validation_error!(new_pipeline)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Gets a specific pipeline for the project' do
detail 'This feature was introduced in GitLab 8.11'
diff --git a/lib/api/project_snippets.rb b/lib/api/project_snippets.rb
index 0ada0ef4708..1ef176b1320 100644
--- a/lib/api/project_snippets.rb
+++ b/lib/api/project_snippets.rb
@@ -85,6 +85,7 @@ module API
desc: 'The visibility of the snippet'
at_least_one_of :title, :file_name, :code, :visibility_level
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ":id/snippets/:snippet_id" do
snippet = snippets_for_current_user.find_by(id: params.delete(:snippet_id))
not_found!('Snippet') unless snippet
@@ -107,11 +108,13 @@ module API
render_validation_error!(snippet)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete a project snippet'
params do
requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ":id/snippets/:snippet_id" do
snippet = snippets_for_current_user.find_by(id: params[:snippet_id])
not_found!('Snippet') unless snippet
@@ -120,11 +123,13 @@ module API
destroy_conditionally!(snippet)
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a raw project snippet'
params do
requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/snippets/:snippet_id/raw" do
snippet = snippets_for_current_user.find_by(id: params[:snippet_id])
not_found!('Snippet') unless snippet
@@ -133,6 +138,7 @@ module API
content_type 'text/plain'
present snippet.content
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get the user agent details for a project snippet' do
success Entities::UserAgentDetail
@@ -140,6 +146,7 @@ module API
params do
requires :snippet_id, type: Integer, desc: 'The ID of a project snippet'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/snippets/:snippet_id/user_agent_detail" do
authenticated_as_admin!
@@ -149,6 +156,7 @@ module API
present snippet.user_agent_detail, with: Entities::UserAgentDetail
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 2801ae918c6..ee426f39523 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -198,6 +198,7 @@ module API
use :optional_project_params
use :create_params
end
+ # rubocop: disable CodeReuse/ActiveRecord
post "user/:user_id" do
authenticated_as_admin!
user = User.find_by(id: params.delete(:user_id))
@@ -214,6 +215,7 @@ module API
render_validation_error!(project)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
params do
@@ -444,6 +446,7 @@ module API
params do
requires :group_id, type: Integer, desc: 'The ID of the group'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ":id/share/:group_id" do
authorize! :admin_project, user_project
@@ -452,6 +455,7 @@ module API
destroy_conditionally!(link)
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Upload a file'
params do
diff --git a/lib/api/protected_branches.rb b/lib/api/protected_branches.rb
index a30eb46c220..e569fad8663 100644
--- a/lib/api/protected_branches.rb
+++ b/lib/api/protected_branches.rb
@@ -16,11 +16,13 @@ module API
params do
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/protected_branches' do
protected_branches = user_project.protected_branches.preload(:push_access_levels, :merge_access_levels)
present paginate(protected_branches), with: Entities::ProtectedBranch, project: user_project
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a single protected branch' do
success Entities::ProtectedBranch
@@ -28,11 +30,13 @@ module API
params do
requires :name, type: String, desc: 'The name of the branch or wildcard'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/protected_branches/:name', requirements: BRANCH_ENDPOINT_REQUIREMENTS do
protected_branch = user_project.protected_branches.find_by!(name: params[:name])
present protected_branch, with: Entities::ProtectedBranch, project: user_project
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Protect a single branch or wildcard' do
success Entities::ProtectedBranch
@@ -46,6 +50,7 @@ module API
values: ProtectedRefAccess::ALLOWED_ACCESS_LEVELS,
desc: 'Access levels allowed to merge (defaults: `40`, maintainer access level)'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ':id/protected_branches' do
protected_branch = user_project.protected_branches.find_by(name: params[:name])
if protected_branch
@@ -62,11 +67,13 @@ module API
render_api_error!(protected_branch.errors.full_messages, 422)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Unprotect a single branch'
params do
requires :name, type: String, desc: 'The name of the protected branch'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/protected_branches/:name', requirements: BRANCH_ENDPOINT_REQUIREMENTS do
protected_branch = user_project.protected_branches.find_by!(name: params[:name])
@@ -75,6 +82,7 @@ module API
destroy_service.execute(protected_branch)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/protected_tags.rb b/lib/api/protected_tags.rb
index bf0a7184e1c..219d51a2bc5 100644
--- a/lib/api/protected_tags.rb
+++ b/lib/api/protected_tags.rb
@@ -17,11 +17,13 @@ module API
params do
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/protected_tags' do
protected_tags = user_project.protected_tags.preload(:create_access_levels)
present paginate(protected_tags), with: Entities::ProtectedTag, project: user_project
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a single protected tag' do
detail 'This feature was introduced in GitLab 11.3.'
@@ -30,11 +32,13 @@ module API
params do
requires :name, type: String, desc: 'The name of the tag or wildcard'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/protected_tags/:name', requirements: TAG_ENDPOINT_REQUIREMENTS do
protected_tag = user_project.protected_tags.find_by!(name: params[:name])
present protected_tag, with: Entities::ProtectedTag, project: user_project
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Protect a single tag or wildcard' do
detail 'This feature was introduced in GitLab 11.3.'
@@ -69,11 +73,13 @@ module API
params do
requires :name, type: String, desc: 'The name of the protected tag'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/protected_tags/:name', requirements: TAG_ENDPOINT_REQUIREMENTS do
protected_tag = user_project.protected_tags.find_by!(name: params[:name])
destroy_conditionally!(protected_tag)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/resource_label_events.rb b/lib/api/resource_label_events.rb
index 5ac3adeb990..b6fbe8c0235 100644
--- a/lib/api/resource_label_events.rb
+++ b/lib/api/resource_label_events.rb
@@ -25,12 +25,15 @@ module API
requires :eventable_id, types: [Integer, String], desc: 'The ID of the eventable'
use :pagination
end
+
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/#{eventables_str}/:eventable_id/resource_label_events" do
eventable = find_noteable(parent_type, eventables_str, params[:eventable_id])
events = eventable.resource_label_events.includes(:label, :user)
present paginate(events), with: Entities::ResourceLabelEvent
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc "Get a single #{eventable_type.to_s.downcase} resource label event" do
success Entities::ResourceLabelEvent
diff --git a/lib/api/runner.rb b/lib/api/runner.rb
index c9931c2d603..b2d46cef23c 100644
--- a/lib/api/runner.rb
+++ b/lib/api/runner.rb
@@ -17,6 +17,7 @@ module API
optional :tag_list, type: Array[String], desc: %q(List of Runner's tags)
optional :maximum_timeout, type: Integer, desc: 'Maximum timeout set when this Runner will handle the job'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post '/' do
attributes = attributes_for_keys([:description, :active, :locked, :run_untagged, :tag_list, :maximum_timeout])
.merge(get_runner_details_from_request)
@@ -43,6 +44,7 @@ module API
render_validation_error!(runner)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Deletes a registered Runner' do
http_codes [[204, 'Runner was deleted'], [403, 'Forbidden']]
diff --git a/lib/api/runners.rb b/lib/api/runners.rb
index 51242341dba..f35cf521e0a 100644
--- a/lib/api/runners.rb
+++ b/lib/api/runners.rb
@@ -146,6 +146,7 @@ module API
params do
requires :runner_id, type: Integer, desc: 'The ID of the runner'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/runners/:runner_id' do
runner_project = user_project.runner_projects.find_by(runner_id: params[:runner_id])
not_found!('Runner') unless runner_project
@@ -155,6 +156,7 @@ module API
destroy_conditionally!(runner_project)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
helpers do
diff --git a/lib/api/services.rb b/lib/api/services.rb
index d1a5ee7db35..0ae05ce08f1 100644
--- a/lib/api/services.rb
+++ b/lib/api/services.rb
@@ -821,11 +821,13 @@ module API
TRIGGER_SERVICES.each do |service_slug, settings|
helpers do
+ # rubocop: disable CodeReuse/ActiveRecord
def slash_command_service(project, service_slug, params)
project.services.active.where(template: false).find do |service|
service.try(:token) == params[:token] && service.to_param == service_slug.underscore
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
params do
diff --git a/lib/api/snippets.rb b/lib/api/snippets.rb
index b30305b4bc9..6352a9c8742 100644
--- a/lib/api/snippets.rb
+++ b/lib/api/snippets.rb
@@ -92,6 +92,7 @@ module API
desc: 'The visibility of the snippet'
at_least_one_of :title, :file_name, :content, :visibility
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ':id' do
snippet = snippets_for_current_user.find_by(id: params.delete(:id))
break not_found!('Snippet') unless snippet
@@ -110,6 +111,7 @@ module API
render_validation_error!(snippet)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Remove snippet' do
detail 'This feature was introduced in GitLab 8.15.'
@@ -118,6 +120,7 @@ module API
params do
requires :id, type: Integer, desc: 'The ID of a snippet'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id' do
snippet = snippets_for_current_user.find_by(id: params.delete(:id))
break not_found!('Snippet') unless snippet
@@ -126,6 +129,7 @@ module API
destroy_conditionally!(snippet)
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a raw snippet' do
detail 'This feature was introduced in GitLab 8.15.'
@@ -133,6 +137,7 @@ module API
params do
requires :id, type: Integer, desc: 'The ID of a snippet'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/raw" do
snippet = snippets_for_current_user.find_by(id: params.delete(:id))
break not_found!('Snippet') unless snippet
@@ -141,6 +146,7 @@ module API
content_type 'text/plain'
present snippet.content
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get the user agent details for a snippet' do
success Entities::UserAgentDetail
@@ -148,6 +154,7 @@ module API
params do
requires :id, type: Integer, desc: 'The ID of a snippet'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id/user_agent_detail" do
authenticated_as_admin!
@@ -157,6 +164,7 @@ module API
present snippet.user_agent_detail, with: Entities::UserAgentDetail
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/system_hooks.rb b/lib/api/system_hooks.rb
index c7a460df46a..07552aa18e8 100644
--- a/lib/api/system_hooks.rb
+++ b/lib/api/system_hooks.rb
@@ -63,12 +63,14 @@ module API
params do
requires :id, type: Integer, desc: 'The ID of the system hook'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ":id" do
hook = SystemHook.find_by(id: params[:id])
not_found!('System hook') unless hook
destroy_conditionally!(hook)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end
diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb
index b29e660c6e0..5e2917e4c3e 100644
--- a/lib/api/triggers.rb
+++ b/lib/api/triggers.rb
@@ -42,6 +42,7 @@ module API
params do
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/triggers' do
authenticate!
authorize! :admin_build, user_project
@@ -50,6 +51,7 @@ module API
present paginate(triggers), with: Entities::Trigger
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get specific trigger of a project' do
success Entities::Trigger
diff --git a/lib/api/users.rb b/lib/api/users.rb
index b0811bb4aad..b1657399cd8 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -14,11 +14,14 @@ module API
end
helpers do
+ # rubocop: disable CodeReuse/ActiveRecord
def find_user_by_id(params)
id = params[:user_id] || params[:id]
User.find_by(id: id) || not_found!('User')
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def reorder_users(users)
if params[:order_by] && params[:sort]
users.reorder(params[:order_by] => params[:sort])
@@ -26,6 +29,7 @@ module API
users
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
params :optional_attributes do
optional :skype, type: String, desc: 'The Skype username'
@@ -75,6 +79,7 @@ module API
use :pagination
use :with_custom_attributes
end
+ # rubocop: disable CodeReuse/ActiveRecord
get do
authenticated_as_admin! if params[:external].present? || (params[:extern_uid].present? && params[:provider].present?)
@@ -102,6 +107,7 @@ module API
present paginate(users), options
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a single user' do
success Entities::User
@@ -111,6 +117,7 @@ module API
use :with_custom_attributes
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ":id" do
user = User.find_by(id: params[:id])
not_found!('User') unless user && can?(current_user, :read_user, user)
@@ -120,6 +127,7 @@ module API
present user, opts
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc "Get the status of a user"
params do
@@ -145,6 +153,7 @@ module API
requires :username, type: String, desc: 'The username of the user'
use :optional_attributes
end
+ # rubocop: disable CodeReuse/ActiveRecord
post do
authenticated_as_admin!
@@ -165,6 +174,7 @@ module API
render_validation_error!(user)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Update a user. Available only for admins.' do
success Entities::UserPublic
@@ -178,6 +188,7 @@ module API
optional :username, type: String, desc: 'The username of the user'
use :optional_attributes
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ":id" do
authenticated_as_admin!
@@ -216,6 +227,7 @@ module API
render_validation_error!(user)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Add an SSH key to a specified user. Available only for admins.' do
success Entities::SSHKey
@@ -225,6 +237,7 @@ module API
requires :key, type: String, desc: 'The new SSH key'
requires :title, type: String, desc: 'The title of the new SSH key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ":id/keys" do
authenticated_as_admin!
@@ -239,6 +252,7 @@ module API
render_validation_error!(key)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get the SSH keys of a specified user. Available only for admins.' do
success Entities::SSHKey
@@ -247,6 +261,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/keys' do
authenticated_as_admin!
@@ -255,6 +270,7 @@ module API
present paginate(user.keys), with: Entities::SSHKey
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing SSH key from a specified user. Available only for admins.' do
success Entities::SSHKey
@@ -263,6 +279,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
requires :key_id, type: Integer, desc: 'The ID of the SSH key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/keys/:key_id' do
authenticated_as_admin!
@@ -274,6 +291,7 @@ module API
destroy_conditionally!(key)
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Add a GPG key to a specified user. Available only for admins.' do
detail 'This feature was added in GitLab 10.0'
@@ -283,6 +301,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
requires :key, type: String, desc: 'The new GPG key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ':id/gpg_keys' do
authenticated_as_admin!
@@ -297,6 +316,7 @@ module API
render_validation_error!(key)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get the GPG keys of a specified user. Available only for admins.' do
detail 'This feature was added in GitLab 10.0'
@@ -306,6 +326,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/gpg_keys' do
authenticated_as_admin!
@@ -314,6 +335,7 @@ module API
present paginate(user.gpg_keys), with: Entities::GPGKey
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing GPG key from a specified user. Available only for admins.' do
detail 'This feature was added in GitLab 10.0'
@@ -322,6 +344,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
requires :key_id, type: Integer, desc: 'The ID of the GPG key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/gpg_keys/:key_id' do
authenticated_as_admin!
@@ -334,6 +357,7 @@ module API
status 204
key.destroy
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Revokes an existing GPG key from a specified user. Available only for admins.' do
detail 'This feature was added in GitLab 10.0'
@@ -342,6 +366,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
requires :key_id, type: Integer, desc: 'The ID of the GPG key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ':id/gpg_keys/:key_id/revoke' do
authenticated_as_admin!
@@ -354,6 +379,7 @@ module API
key.revoke
status :accepted
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Add an email address to a specified user. Available only for admins.' do
success Entities::Email
@@ -362,6 +388,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
requires :email, type: String, desc: 'The email of the user'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ":id/emails" do
authenticated_as_admin!
@@ -376,6 +403,7 @@ module API
render_validation_error!(email)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get the emails addresses of a specified user. Available only for admins.' do
success Entities::Email
@@ -384,6 +412,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/emails' do
authenticated_as_admin!
user = User.find_by(id: params[:id])
@@ -391,6 +420,7 @@ module API
present paginate(user.emails), with: Entities::Email
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an email address of a specified user. Available only for admins.' do
success Entities::Email
@@ -399,6 +429,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
requires :email_id, type: Integer, desc: 'The ID of the email'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/emails/:email_id' do
authenticated_as_admin!
user = User.find_by(id: params[:id])
@@ -411,6 +442,7 @@ module API
Emails::DestroyService.new(current_user, user: user).execute(email)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete a user. Available only for admins.' do
success Entities::Email
@@ -419,6 +451,7 @@ module API
requires :id, type: Integer, desc: 'The ID of the user'
optional :hard_delete, type: Boolean, desc: "Whether to remove a user's contributions"
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ":id" do
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42279')
@@ -431,11 +464,13 @@ module API
user.delete_async(deleted_by: current_user, params: params)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Block a user. Available only for admins.'
params do
requires :id, type: Integer, desc: 'The ID of the user'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ':id/block' do
authenticated_as_admin!
user = User.find_by(id: params[:id])
@@ -447,11 +482,13 @@ module API
forbidden!('LDAP blocked users cannot be modified by the API')
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Unblock a user. Available only for admins.'
params do
requires :id, type: Integer, desc: 'The ID of the user'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post ':id/unblock' do
authenticated_as_admin!
user = User.find_by(id: params[:id])
@@ -463,6 +500,7 @@ module API
user.activate
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
params do
requires :user_id, type: Integer, desc: 'The ID of the user'
@@ -475,9 +513,11 @@ module API
PersonalAccessTokensFinder.new({ user: user, impersonation: true }.merge(options))
end
+ # rubocop: disable CodeReuse/ActiveRecord
def find_impersonation_token
finder.find_by(id: declared_params[:impersonation_token_id]) || not_found!('Impersonation Token')
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
before { authenticated_as_admin! }
@@ -578,12 +618,14 @@ module API
params do
requires :key_id, type: Integer, desc: 'The ID of the SSH key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get "keys/:key_id" do
key = current_user.keys.find_by(id: params[:key_id])
not_found!('Key') unless key
present key, with: Entities::SSHKey
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Add a new SSH key to the currently authenticated user' do
success Entities::SSHKey
@@ -608,12 +650,14 @@ module API
params do
requires :key_id, type: Integer, desc: 'The ID of the SSH key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete "keys/:key_id" do
key = current_user.keys.find_by(id: params[:key_id])
not_found!('Key') unless key
destroy_conditionally!(key)
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc "Get the currently authenticated user's GPG keys" do
detail 'This feature was added in GitLab 10.0'
@@ -633,12 +677,14 @@ module API
params do
requires :key_id, type: Integer, desc: 'The ID of the GPG key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get 'gpg_keys/:key_id' do
key = current_user.gpg_keys.find_by(id: params[:key_id])
not_found!('GPG Key') unless key
present key, with: Entities::GPGKey
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Add a new GPG key to the currently authenticated user' do
detail 'This feature was added in GitLab 10.0'
@@ -663,6 +709,7 @@ module API
params do
requires :key_id, type: Integer, desc: 'The ID of the GPG key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
post 'gpg_keys/:key_id/revoke' do
key = current_user.gpg_keys.find_by(id: params[:key_id])
not_found!('GPG Key') unless key
@@ -670,6 +717,7 @@ module API
key.revoke
status :accepted
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete a GPG key from the currently authenticated user' do
detail 'This feature was added in GitLab 10.0'
@@ -677,6 +725,7 @@ module API
params do
requires :key_id, type: Integer, desc: 'The ID of the SSH key'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete 'gpg_keys/:key_id' do
key = current_user.gpg_keys.find_by(id: params[:key_id])
not_found!('GPG Key') unless key
@@ -684,6 +733,7 @@ module API
status 204
key.destroy
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc "Get the currently authenticated user's email addresses" do
success Entities::Email
@@ -701,12 +751,14 @@ module API
params do
requires :email_id, type: Integer, desc: 'The ID of the email'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get "emails/:email_id" do
email = current_user.emails.find_by(id: params[:email_id])
not_found!('Email') unless email
present email, with: Entities::Email
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Add new email address to the currently authenticated user' do
success Entities::Email
@@ -728,6 +780,7 @@ module API
params do
requires :email_id, type: Integer, desc: 'The ID of the email'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete "emails/:email_id" do
email = current_user.emails.find_by(id: params[:email_id])
not_found!('Email') unless email
@@ -736,12 +789,14 @@ module API
Emails::DestroyService.new(current_user, user: current_user).execute(email)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a list of user activities'
params do
optional :from, type: DateTime, default: 6.months.ago, desc: 'Date string in the format YEAR-MONTH-DAY'
use :pagination
end
+ # rubocop: disable CodeReuse/ActiveRecord
get "activities" do
authenticated_as_admin!
@@ -751,6 +806,7 @@ module API
present paginate(activities), with: Entities::UserActivity
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Set the status of the current user' do
success Entities::UserStatus
diff --git a/lib/api/variables.rb b/lib/api/variables.rb
index a34de9410e8..50e6fa6bcdf 100644
--- a/lib/api/variables.rb
+++ b/lib/api/variables.rb
@@ -27,6 +27,7 @@ module API
params do
requires :key, type: String, desc: 'The key of the variable'
end
+ # rubocop: disable CodeReuse/ActiveRecord
get ':id/variables/:key' do
key = params[:key]
variable = user_project.variables.find_by(key: key)
@@ -35,6 +36,7 @@ module API
present variable, with: Entities::Variable
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Create a new variable in a project' do
success Entities::Variable
@@ -64,6 +66,7 @@ module API
optional :value, type: String, desc: 'The value of the variable'
optional :protected, type: String, desc: 'Whether the variable is protected'
end
+ # rubocop: disable CodeReuse/ActiveRecord
put ':id/variables/:key' do
variable = user_project.variables.find_by(key: params[:key])
@@ -77,6 +80,7 @@ module API
render_validation_error!(variable)
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing variable from a project' do
success Entities::Variable
@@ -84,6 +88,7 @@ module API
params do
requires :key, type: String, desc: 'The key of the variable'
end
+ # rubocop: disable CodeReuse/ActiveRecord
delete ':id/variables/:key' do
variable = user_project.variables.find_by(key: params[:key])
not_found!('Variable') unless variable
@@ -92,6 +97,7 @@ module API
status 204
variable.destroy
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end