Commit bda7e75d authored by Toon Claes's avatar Toon Claes

Use User#has_full_private_access? to check if user has Private access

CE and EE implement this differently, so abstract it out of VisibilityLevel.
parent 304dce21
...@@ -28,7 +28,7 @@ module Gitlab ...@@ -28,7 +28,7 @@ module Gitlab
def levels_for_user(user = nil) def levels_for_user(user = nil)
return [PUBLIC] unless user return [PUBLIC] unless user
if user.admin_or_auditor? if user.has_full_private_access?
[PRIVATE, INTERNAL, PUBLIC] [PRIVATE, INTERNAL, PUBLIC]
elsif user.external? elsif user.external?
[PUBLIC] [PUBLIC]
......
require 'spec_helper'
describe Gitlab::VisibilityLevel, lib: true do
describe '.levels_for_user' do
it 'returns all levels for an auditor' do
user = build(:user, :auditor)
expect(described_class.levels_for_user(user)).
to eq([Gitlab::VisibilityLevel::PRIVATE,
Gitlab::VisibilityLevel::INTERNAL,
Gitlab::VisibilityLevel::PUBLIC])
end
end
end
...@@ -21,7 +21,7 @@ describe Gitlab::VisibilityLevel, lib: true do ...@@ -21,7 +21,7 @@ describe Gitlab::VisibilityLevel, lib: true do
describe '.levels_for_user' do describe '.levels_for_user' do
it 'returns all levels for an admin' do it 'returns all levels for an admin' do
user = double(:user, admin?: true) user = build(:user, :admin)
expect(described_class.levels_for_user(user)). expect(described_class.levels_for_user(user)).
to eq([Gitlab::VisibilityLevel::PRIVATE, to eq([Gitlab::VisibilityLevel::PRIVATE,
...@@ -30,7 +30,7 @@ describe Gitlab::VisibilityLevel, lib: true do ...@@ -30,7 +30,7 @@ describe Gitlab::VisibilityLevel, lib: true do
end end
it 'returns INTERNAL and PUBLIC for internal users' do it 'returns INTERNAL and PUBLIC for internal users' do
user = double(:user, admin?: false, external?: false) user = build(:user)
expect(described_class.levels_for_user(user)). expect(described_class.levels_for_user(user)).
to eq([Gitlab::VisibilityLevel::INTERNAL, to eq([Gitlab::VisibilityLevel::INTERNAL,
...@@ -38,7 +38,7 @@ describe Gitlab::VisibilityLevel, lib: true do ...@@ -38,7 +38,7 @@ describe Gitlab::VisibilityLevel, lib: true do
end end
it 'returns PUBLIC for external users' do it 'returns PUBLIC for external users' do
user = double(:user, admin?: false, external?: true) user = build(:user, :external)
expect(described_class.levels_for_user(user)). expect(described_class.levels_for_user(user)).
to eq([Gitlab::VisibilityLevel::PUBLIC]) to eq([Gitlab::VisibilityLevel::PUBLIC])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment