mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Fix DynamicFindBy issues in our Codebase
This commit is contained in:
+8
-5
@@ -60,7 +60,7 @@ Layout/MultilineOperationIndentation:
|
||||
Enabled: false
|
||||
|
||||
Lint/AmbiguousBlockAssociation:
|
||||
AllowedMethods: [change]
|
||||
AllowedMethods: [ change ]
|
||||
|
||||
Lint/AmbiguousOperator:
|
||||
Enabled: false
|
||||
@@ -147,9 +147,9 @@ Naming/PredicatePrefix:
|
||||
|
||||
Naming/VariableNumber:
|
||||
AllowedPatterns:
|
||||
- '\w_20\d\d' # allow dates like christmas_2022 or date_2034_04_12
|
||||
- '\w\d++(_\d++)+' # allow hierarchical data like child1_2_5 (second + in regex is possessive qualifier)
|
||||
- 'custom_field_\d+' # allow custom field method names to be called with send :custom_field_1001
|
||||
- "\\w_20\\d\\d" # allow dates like christmas_2022 or date_2034_04_12
|
||||
- "\\w\\d++(_\\d++)+" # allow hierarchical data like child1_2_5 (second + in regex is possessive qualifier)
|
||||
- "custom_field_\\d+" # allow custom field method names to be called with send :custom_field_1001
|
||||
|
||||
OpenProject/AddPreviewForViewComponent:
|
||||
Include:
|
||||
@@ -181,6 +181,9 @@ Rails/DynamicFindBy:
|
||||
- find_by_login
|
||||
- find_by_mail
|
||||
- find_by_plaintext_value
|
||||
- find_by_rss_key
|
||||
- find_by_unique
|
||||
- find_by_api_key
|
||||
|
||||
# Allow reorder to prevent find each cop triggering
|
||||
Rails/FindEach:
|
||||
@@ -402,7 +405,7 @@ Style/FormatString:
|
||||
Enabled: false
|
||||
|
||||
Style/FormatStringToken:
|
||||
AllowedMethods: [redirect]
|
||||
AllowedMethods: [ redirect ]
|
||||
|
||||
Style/FrozenStringLiteralComment:
|
||||
Enabled: true
|
||||
|
||||
@@ -118,7 +118,7 @@ module WorkPackages::Costs
|
||||
reassign_to = ::WorkPackage
|
||||
.joins(:project)
|
||||
.merge(Project.allowed_to(user, :edit_cost_entries))
|
||||
.find_by_id(ids)
|
||||
.find_by(id: ids)
|
||||
|
||||
if reassign_to.nil?
|
||||
work_packages.each do |wp|
|
||||
|
||||
@@ -51,7 +51,7 @@ module OpenProject
|
||||
end
|
||||
|
||||
def authenticate!
|
||||
token = ::Token::API.find_by_plaintext_value(@access_token) # rubocop:disable Rails/DynamicFindBy
|
||||
token = ::Token::API.find_by_plaintext_value(@access_token)
|
||||
return fail_with_header!(error: "invalid_token") if token.nil?
|
||||
|
||||
authentication_result(token.user)
|
||||
|
||||
@@ -58,7 +58,7 @@ module Bim::Bcf
|
||||
if attachments.loaded?
|
||||
attachments.detect { |a| a.description == "snapshot" }
|
||||
else
|
||||
attachments.find_by_description("snapshot")
|
||||
attachments.find_by(description: "snapshot")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ module Bim
|
||||
if attachments.loaded?
|
||||
attachments.detect { |a| a.description == key.to_s && !a.marked_for_destruction? }
|
||||
else
|
||||
attachments.find_by_description(key.to_s)
|
||||
attachments.find_by(description: key.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ RSpec.describe Budget do
|
||||
budget.destroy
|
||||
end
|
||||
|
||||
it { expect(Budget.find_by_id(budget.id)).to be_nil }
|
||||
it { expect(WorkPackage.find_by_id(work_package.id)).to eq(work_package) }
|
||||
it { expect(described_class.find_by(id: budget.id)).to be_nil }
|
||||
it { expect(WorkPackage.find_by(id: work_package.id)).to eq(work_package) }
|
||||
it { expect(work_package.reload.budget).to be_nil }
|
||||
end
|
||||
|
||||
|
||||
+2
-2
@@ -36,9 +36,9 @@ module OpenProject::GitlabIntegration
|
||||
|
||||
def process(payload_params) # rubocop:disable Metrics/AbcSize
|
||||
@payload = wrap_payload(payload_params)
|
||||
user = User.find_by_id(payload.open_project_user_id)
|
||||
user = User.find_by(id: payload.open_project_user_id)
|
||||
text = [payload.object_attributes.title, payload.object_attributes.description]
|
||||
.select(&:present?)
|
||||
.compact_blank
|
||||
.join(" - ")
|
||||
work_packages = find_mentioned_work_packages(text, user)
|
||||
notes = generate_notes(payload)
|
||||
|
||||
+2
-2
@@ -47,9 +47,9 @@ module OpenProject::GitlabIntegration
|
||||
@payload = wrap_payload(payload_params)
|
||||
return unless (accepted_actions.include? payload.object_attributes.action) || (accepted_states.include? payload.object_attributes.state)
|
||||
|
||||
user = User.find_by_id(payload.open_project_user_id)
|
||||
user = User.find_by(id: payload.open_project_user_id)
|
||||
text = [payload.object_attributes.title, payload.object_attributes.description]
|
||||
.select(&:present?)
|
||||
.compact_blank
|
||||
.join(" - ")
|
||||
work_packages = find_mentioned_work_packages(text, user)
|
||||
notes = generate_notes(payload)
|
||||
|
||||
+2
-2
@@ -39,9 +39,9 @@ module OpenProject::GitlabIntegration
|
||||
return nil unless payload.object_kind == "push"
|
||||
|
||||
payload.commits.each do |commit|
|
||||
user = User.find_by_id(payload.open_project_user_id)
|
||||
user = User.find_by(id: payload.open_project_user_id)
|
||||
text = [commit["title"], commit["message"]]
|
||||
.select(&:present?)
|
||||
.compact_blank
|
||||
.join(" - ")
|
||||
work_packages = find_mentioned_work_packages(text, user)
|
||||
notes = generate_notes(commit, payload)
|
||||
|
||||
+2
-2
@@ -39,9 +39,9 @@ module OpenProject::GitlabIntegration
|
||||
return nil unless payload.object_kind == "push"
|
||||
|
||||
payload.commits.each do |commit|
|
||||
user = User.find_by_id(payload.open_project_user_id)
|
||||
user = User.find_by(id: payload.open_project_user_id)
|
||||
text = [commit["title"], commit["message"]]
|
||||
.select(&:present?)
|
||||
.compact_blank
|
||||
.join(" - ")
|
||||
work_packages = find_mentioned_work_packages(text, user)
|
||||
notes = generate_notes(commit, payload)
|
||||
|
||||
Reference in New Issue
Block a user