Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
dadd2772
Commit
dadd2772
authored
Feb 23, 2022
by
Siddharth Asthana
Committed by
Peter Leitzen
Mar 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve Rails/FindById rubocop offenses
Changelog: other EE: true
parent
4c6b42a8
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
15 additions
and
29 deletions
+15
-29
.rubocop_todo.yml
.rubocop_todo.yml
+0
-16
app/controllers/projects/pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+1
-1
app/services/concerns/deploy_token_methods.rb
app/services/concerns/deploy_token_methods.rb
+1
-1
ee/app/controllers/ee/groups/group_members_controller.rb
ee/app/controllers/ee/groups/group_members_controller.rb
+1
-1
ee/lib/api/audit_events.rb
ee/lib/api/audit_events.rb
+1
-1
ee/lib/api/merge_request_approval_rules.rb
ee/lib/api/merge_request_approval_rules.rb
+1
-1
ee/lib/ee/api/groups.rb
ee/lib/ee/api/groups.rb
+2
-2
ee/lib/ee/api/projects.rb
ee/lib/ee/api/projects.rb
+2
-2
ee/spec/finders/audit_log_finder_spec.rb
ee/spec/finders/audit_log_finder_spec.rb
+1
-1
lib/api/snippets.rb
lib/api/snippets.rb
+1
-1
spec/finders/concerns/finder_methods_spec.rb
spec/finders/concerns/finder_methods_spec.rb
+2
-0
spec/finders/concerns/finder_with_cross_project_access_spec.rb
...finders/concerns/finder_with_cross_project_access_spec.rb
+2
-2
No files found.
.rubocop_todo.yml
View file @
dadd2772
...
...
@@ -333,22 +333,6 @@ Rails/CreateTableWithTimestamps:
Rails/FilePath
:
Enabled
:
false
# Offense count: 15
# Cop supports --auto-correct.
Rails/FindById
:
Exclude
:
-
'
app/controllers/projects/pipelines_controller.rb'
-
'
app/services/concerns/deploy_token_methods.rb'
-
'
ee/app/controllers/ee/groups/group_members_controller.rb'
-
'
ee/lib/api/audit_events.rb'
-
'
ee/lib/api/merge_request_approval_rules.rb'
-
'
ee/lib/ee/api/groups.rb'
-
'
ee/lib/ee/api/projects.rb'
-
'
ee/spec/finders/audit_log_finder_spec.rb'
-
'
lib/api/snippets.rb'
-
'
spec/finders/concerns/finder_methods_spec.rb'
-
'
spec/finders/concerns/finder_with_cross_project_access_spec.rb'
# Offense count: 354
# Configuration parameters: Include.
# Include: app/models/**/*.rb
...
...
app/controllers/projects/pipelines_controller.rb
View file @
dadd2772
...
...
@@ -268,7 +268,7 @@ class Projects::PipelinesController < Projects::ApplicationController
project
.
all_pipelines
.
includes
(
builds: :tags
,
user: :status
)
.
find
_by!
(
id:
params
[
:id
])
.
find
(
params
[
:id
])
.
present
(
current_user:
current_user
)
end
end
...
...
app/services/concerns/deploy_token_methods.rb
View file @
dadd2772
...
...
@@ -11,7 +11,7 @@ module DeployTokenMethods
end
def
destroy_deploy_token
(
entity
,
params
)
deploy_token
=
entity
.
deploy_tokens
.
find
_by_id!
(
params
[
:token_id
])
deploy_token
=
entity
.
deploy_tokens
.
find
(
params
[
:token_id
])
deploy_token
.
destroy
end
...
...
ee/app/controllers/ee/groups/group_members_controller.rb
View file @
dadd2772
...
...
@@ -29,7 +29,7 @@ module EE
# rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord
def
override
member
=
membershipable_members
.
find
_by!
(
id:
params
[
:id
])
member
=
membershipable_members
.
find
(
params
[
:id
])
result
=
::
Members
::
UpdateService
.
new
(
current_user
,
override_params
).
execute
(
member
,
permission: :override
)
...
...
ee/lib/api/audit_events.rb
View file @
dadd2772
...
...
@@ -46,7 +46,7 @@ module API
level
=
::
Gitlab
::
Audit
::
Levels
::
Instance
.
new
# rubocop: disable CodeReuse/ActiveRecord
# This is not `find_by!` from ActiveRecord
audit_event
=
AuditLogFinder
.
new
(
level:
level
).
find
_by!
(
id:
params
[
:id
])
audit_event
=
AuditLogFinder
.
new
(
level:
level
).
find
(
params
[
:id
])
# rubocop: enable CodeReuse/ActiveRecord
present
audit_event
,
with:
EE
::
API
::
Entities
::
AuditEvent
...
...
ee/lib/api/merge_request_approval_rules.rb
View file @
dadd2772
...
...
@@ -8,7 +8,7 @@ module API
helpers
do
def
find_merge_request_approval_rule
(
merge_request
,
id
)
merge_request
.
approval_rules
.
find
_by_id!
(
id
)
merge_request
.
approval_rules
.
find
(
id
)
end
end
...
...
ee/lib/ee/api/groups.rb
View file @
dadd2772
...
...
@@ -133,11 +133,11 @@ module EE
end
get
'/:audit_event_id'
do
level
=
::
Gitlab
::
Audit
::
Levels
::
Group
.
new
(
group:
user_group
)
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
, Rails/FindById
# This is not `find_by!` from ActiveRecord
audit_event
=
AuditLogFinder
.
new
(
level:
level
,
params:
audit_log_finder_params
)
.
find_by!
(
id:
params
[
:audit_event_id
])
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
, Rails/FindById
present
audit_event
,
with:
EE
::
API
::
Entities
::
AuditEvent
end
...
...
ee/lib/ee/api/projects.rb
View file @
dadd2772
...
...
@@ -55,11 +55,11 @@ module EE
end
get
'/:audit_event_id'
,
feature_category: :audit_events
do
level
=
::
Gitlab
::
Audit
::
Levels
::
Project
.
new
(
project:
user_project
)
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
, Rails/FindById
# This is not `find_by!` from ActiveRecord
audit_event
=
AuditLogFinder
.
new
(
level:
level
,
params:
audit_log_finder_params
)
.
find_by!
(
id:
params
[
:audit_event_id
])
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
, Rails/FindById
present
audit_event
,
with:
EE
::
API
::
Entities
::
AuditEvent
end
...
...
ee/spec/finders/audit_log_finder_spec.rb
View file @
dadd2772
...
...
@@ -350,7 +350,7 @@ RSpec.describe AuditLogFinder do
describe
'#find_by!'
do
let
(
:id
)
{
user_audit_event
.
id
}
subject
{
finder
.
find_by!
(
id:
id
)
}
subject
{
finder
.
find_by!
(
id:
id
)
}
# rubocop:disable Rails/FindById
it
{
is_expected
.
to
eq
(
user_audit_event
)
}
...
...
lib/api/snippets.rb
View file @
dadd2772
...
...
@@ -200,7 +200,7 @@ module API
get
":id/user_agent_detail"
do
authenticated_as_admin!
snippet
=
Snippet
.
find
_by_id!
(
params
[
:id
])
snippet
=
Snippet
.
find
(
params
[
:id
])
break
not_found!
(
'UserAgentDetail'
)
unless
snippet
.
user_agent_detail
...
...
spec/finders/concerns/finder_methods_spec.rb
View file @
dadd2772
...
...
@@ -30,6 +30,7 @@ RSpec.describe FinderMethods do
authorized_project
.
add_developer
(
user
)
end
# rubocop:disable Rails/FindById
describe
'#find_by!'
do
it
'returns the project if the user has access'
do
expect
(
finder
.
find_by!
(
id:
authorized_project
.
id
)).
to
eq
(
authorized_project
)
...
...
@@ -53,6 +54,7 @@ RSpec.describe FinderMethods do
finder
.
find_by!
(
id:
authorized_project
.
id
)
end
end
# rubocop:enable Rails/FindById
describe
'#find'
do
it
'returns the project if the user has access'
do
...
...
spec/finders/concerns/finder_with_cross_project_access_spec.rb
View file @
dadd2772
...
...
@@ -93,11 +93,11 @@ RSpec.describe FinderWithCrossProjectAccess do
it
'checks the accessibility of the subject directly'
do
expect_access_check_on_result
finder
.
find
_by!
(
id:
result
.
id
)
finder
.
find
(
result
.
id
)
end
it
're-enables the check after the find failed'
do
finder
.
find
_by!
(
id:
non_existing_record_id
)
rescue
ActiveRecord
::
RecordNotFound
finder
.
find
(
non_existing_record_id
)
rescue
ActiveRecord
::
RecordNotFound
expect
(
finder
.
instance_variable_get
(
:@should_skip_cross_project_check
))
.
to
eq
(
false
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment