debian-mirror-gitlab/spec/policies/group_policy_spec.rb

210 lines
4.8 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe GroupPolicy do
2017-08-17 22:00:37 +05:30
let(:guest) { create(:user) }
let(:reporter) { create(:user) }
let(:developer) { create(:user) }
let(:master) { create(:user) }
let(:owner) { create(:user) }
let(:admin) { create(:admin) }
let(:group) { create(:group) }
2017-09-10 17:25:29 +05:30
let(:reporter_permissions) { [:admin_label] }
2017-08-17 22:00:37 +05:30
let(:master_permissions) do
[
:create_projects,
2017-09-10 17:25:29 +05:30
:admin_milestones
2017-08-17 22:00:37 +05:30
]
end
let(:owner_permissions) do
[
:admin_group,
:admin_namespace,
:admin_group_member,
:change_visibility_level,
:create_subgroup
]
end
before do
group.add_guest(guest)
group.add_reporter(reporter)
group.add_developer(developer)
group.add_master(master)
group.add_owner(owner)
end
2017-09-10 17:25:29 +05:30
subject { described_class.new(current_user, group) }
def expect_allowed(*permissions)
permissions.each { |p| is_expected.to be_allowed(p) }
end
def expect_disallowed(*permissions)
permissions.each { |p| is_expected.not_to be_allowed(p) }
end
2017-08-17 22:00:37 +05:30
context 'with no user' do
let(:current_user) { nil }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_disallowed(*reporter_permissions)
expect_disallowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'guests' do
let(:current_user) { guest }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_disallowed(*reporter_permissions)
expect_disallowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'reporter' do
let(:current_user) { reporter }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_allowed(*reporter_permissions)
expect_disallowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'developer' do
let(:current_user) { developer }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_allowed(*reporter_permissions)
expect_disallowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'master' do
let(:current_user) { master }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_allowed(*reporter_permissions)
expect_allowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'owner' do
let(:current_user) { owner }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_allowed(*reporter_permissions)
expect_allowed(*master_permissions)
expect_allowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'admin' do
let(:current_user) { admin }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_allowed(*reporter_permissions)
expect_allowed(*master_permissions)
expect_allowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
2017-09-10 17:25:29 +05:30
describe 'private nested group use the highest access level from the group and inherited permissions', :nested_groups do
2017-08-17 22:00:37 +05:30
let(:nested_group) { create(:group, :private, parent: group) }
2017-09-10 17:25:29 +05:30
before do
nested_group.add_guest(guest)
nested_group.add_guest(reporter)
nested_group.add_guest(developer)
nested_group.add_guest(master)
group.owners.destroy_all
group.add_guest(owner)
nested_group.add_owner(owner)
end
subject { described_class.new(current_user, nested_group) }
2017-08-17 22:00:37 +05:30
context 'with no user' do
let(:current_user) { nil }
it do
2017-09-10 17:25:29 +05:30
expect_disallowed(:read_group)
expect_disallowed(*reporter_permissions)
expect_disallowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'guests' do
let(:current_user) { guest }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_disallowed(*reporter_permissions)
expect_disallowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'reporter' do
let(:current_user) { reporter }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_allowed(*reporter_permissions)
expect_disallowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'developer' do
let(:current_user) { developer }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_allowed(*reporter_permissions)
expect_disallowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'master' do
let(:current_user) { master }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_allowed(*reporter_permissions)
expect_allowed(*master_permissions)
expect_disallowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'owner' do
let(:current_user) { owner }
it do
2017-09-10 17:25:29 +05:30
expect_allowed(:read_group)
expect_allowed(*reporter_permissions)
expect_allowed(*master_permissions)
expect_allowed(*owner_permissions)
2017-08-17 22:00:37 +05:30
end
end
end
end