Skip to content
代码片段 群组 项目
提交 a4409dd4 编辑于 作者: Corinna Wiesner's avatar Corinna Wiesner
浏览文件

Secure path logic against any other directory with ee in it

The logic was breaking for a path that included ee in its name other
than the ee/ directory, e.g. employee/ or gitlab-ee/. This is fixed
with a better detection of a file within the ee directory.
上级 2504bf9b
No related branches found
No related tags found
无相关合并请求
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module RuboCop module RuboCop
module Cop module Cop
# Cop that blacklists the usage of Group.public_or_visible_to_user # Cop that blacklists the usage of `ActiveRecord::Base.ignored_columns=` directly
class IgnoredColumns < RuboCop::Cop::Cop class IgnoredColumns < RuboCop::Cop::Cop
USE_CONCERN_MSG = 'Use `IgnoredColumns` concern instead of adding to `self.ignored_columns`.' USE_CONCERN_MSG = 'Use `IgnoredColumns` concern instead of adding to `self.ignored_columns`.'
WRONG_MODEL_MSG = 'If the model exists in CE and EE, the column has to be ignored ' \ WRONG_MODEL_MSG = 'If the model exists in CE and EE, the column has to be ignored ' \
...@@ -43,11 +43,19 @@ def used_in_wrong_model? ...@@ -43,11 +43,19 @@ def used_in_wrong_model?
end end
def ee_model?(path) def ee_model?(path)
path.include?('ee/') path.include?(ee_directory)
end
def ee_directory
File.join(rails_root, 'ee')
end
def rails_root
File.expand_path('../..', __dir__)
end end
def ce_model_exists?(path) def ce_model_exists?(path)
File.exist?(path.gsub(%r{ee/}, '')) File.exist?(path.gsub(%r{/ee/}, '/'))
end end
end end
end end
......
...@@ -43,8 +43,6 @@ class Baz < ApplicationRecord ...@@ -43,8 +43,6 @@ class Baz < ApplicationRecord
end end
it 'flags ignore_columns usage in EE model' do it 'flags ignore_columns usage in EE model' do
file_path = full_path('ee/app/models/ee/bar.rb')
expect_no_offenses(<<~RUBY, file_path) expect_no_offenses(<<~RUBY, file_path)
class Bar < ApplicationRecord class Bar < ApplicationRecord
ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22' ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
...@@ -90,7 +88,7 @@ class Bar < ApplicationRecord ...@@ -90,7 +88,7 @@ class Bar < ApplicationRecord
private private
def full_path(path) def full_path(path)
rails_root = '../../../../' rails_root = '../../../'
File.expand_path(File.join(rails_root, path), __dir__) File.expand_path(File.join(rails_root, path), __dir__)
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册