Skip to content
代码片段 群组 项目
提交 4987152c 编辑于 作者: Brian Williams's avatar Brian Williams
浏览文件

Add predicate for when on GitLab.com and not JiHu

For things which are highly specific to GitLab.com, we may want to
exclude JiHu. This adds a `com_except_jh?` method to check for when the
instance is GitLab.com but not JiHu.
上级 077ceb32
No related branches found
No related tags found
无相关合并请求
......@@ -10,7 +10,7 @@ module Com
def self.gitlab_com_group_member?(user)
return false unless user.is_a?(::User)
Gitlab.com? && gitlab_com_user_ids.include?(user.id)
Gitlab.com_except_jh? && gitlab_com_user_ids.include?(user.id)
end
# rubocop: disable CodeReuse/ActiveRecord
......@@ -18,7 +18,6 @@ def self.gitlab_com_user_ids
l1_cache_backend.fetch(ALLOWED_USER_IDS_KEY, expires_in: EXPIRY_TIME_L1_CACHE) do
l2_cache_backend.fetch(ALLOWED_USER_IDS_KEY, expires_in: EXPIRY_TIME_L2_CACHE) do
group = Group.find_by(path: GITLAB_COM_GROUP, parent_id: nil)
if group
group.members.pluck_user_ids.to_set
else
......
......@@ -13,6 +13,7 @@
before do
allow(Gitlab).to receive(:com?).and_return(true)
allow(Gitlab).to receive(:jh?).and_return(false)
end
context 'when user is a gitlab team member' do
......@@ -27,6 +28,22 @@
it_behaves_like 'allowed user IDs are cached'
end
context 'when not on Gitlab.com' do
before do
allow(Gitlab).to receive(:com?).and_return(false)
end
it { is_expected.to be false }
end
context 'when on JiHu' do
before do
allow(Gitlab).to receive(:jh?).and_return(true)
end
it { is_expected.to be false }
end
end
context 'when user is not a gitlab team member' do
......
......@@ -60,6 +60,10 @@ def self.com?
simulate_com? || Gitlab.config.gitlab.url == Gitlab::Saas.com_url || gl_subdomain?
end
def self.com_except_jh?
com? && !jh?
end
def self.com
yield if com?
end
......
......@@ -132,6 +132,28 @@
end
end
describe '.com_except_jh?' do
subject { described_class.com_except_jh? }
before do
allow(described_class).to receive(:com?).and_return(com?)
allow(described_class).to receive(:jh?).and_return(jh?)
end
using RSpec::Parameterized::TableSyntax
where(:com?, :jh?, :expected) do
true | true | false
true | false | true
false | true | false
false | false | false
end
with_them do
it { is_expected.to eq(expected) }
end
end
describe '.com' do
subject { described_class.com { true } }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册