2019-04-04 10:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe GroupMemberPolicy do
|
2021-01-18 04:11:05 -05:00
|
|
|
include DesignManagementTestHelpers
|
|
|
|
|
2019-04-04 10:19:57 -04:00
|
|
|
let(:guest) { create(:user) }
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
let(:group) { create(:group, :private) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_guest(guest)
|
|
|
|
group.add_owner(owner)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:member_related_permissions) do
|
|
|
|
[:update_group_member, :destroy_group_member]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:membership) { current_user.members.first }
|
|
|
|
|
|
|
|
subject { described_class.new(current_user, membership) }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
context 'with anonymous user' do
|
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
let(:membership) { guest.members.first }
|
2019-04-04 10:19:57 -04:00
|
|
|
|
|
|
|
it do
|
2021-01-18 04:11:05 -05:00
|
|
|
expect_disallowed(:read_design_activity, *member_related_permissions)
|
|
|
|
expect_allowed(:read_group)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'design management is enabled' do
|
|
|
|
before do
|
|
|
|
create(:project, :public, group: group) # Necessary to enable design management
|
|
|
|
enable_design_management
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect_allowed(:read_design_activity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a private group' do
|
|
|
|
let(:group) { create(:group, :private) }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect_disallowed(:read_group, :read_design_activity, *member_related_permissions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for an internal group' do
|
|
|
|
let(:group) { create(:group, :internal) }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect_disallowed(:read_group, :read_design_activity, *member_related_permissions)
|
|
|
|
end
|
2019-04-04 10:19:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
context 'with guest user, for own membership' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
specify { expect_disallowed(:update_group_member) }
|
|
|
|
specify { expect_allowed(:read_group, :destroy_group_member) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with guest user, for other membership' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
let(:membership) { owner.members.first }
|
|
|
|
|
|
|
|
specify { expect_disallowed(:destroy_group_member, :update_group_member) }
|
|
|
|
specify { expect_allowed(:read_group) }
|
|
|
|
end
|
|
|
|
|
2022-01-17 07:17:11 -05:00
|
|
|
context 'with bot user' do
|
|
|
|
let(:current_user) { create(:user, :project_bot) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
specify { expect_allowed(:read_group, :destroy_project_bot_member) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with anonymous bot user' do
|
|
|
|
let(:current_user) { create(:user, :project_bot) }
|
|
|
|
let(:membership) { guest.members.first }
|
|
|
|
|
|
|
|
specify { expect_disallowed(:read_group, :destroy_project_bot_member) }
|
|
|
|
end
|
|
|
|
|
2019-04-04 10:19:57 -04:00
|
|
|
context 'with one owner' do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
specify { expect_disallowed(*member_related_permissions) }
|
|
|
|
specify { expect_allowed(:read_group) }
|
2019-04-04 10:19:57 -04:00
|
|
|
end
|
|
|
|
|
2021-03-15 20:09:44 -04:00
|
|
|
context 'with one blocked owner' do
|
|
|
|
let(:owner) { create(:user, :blocked) }
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
specify { expect_disallowed(*member_related_permissions) }
|
|
|
|
specify { expect_disallowed(:read_group) }
|
|
|
|
end
|
|
|
|
|
2019-04-04 10:19:57 -04:00
|
|
|
context 'with more than one owner' do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(create(:user))
|
|
|
|
end
|
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
specify { expect_allowed(*member_related_permissions) }
|
2022-01-17 07:17:11 -05:00
|
|
|
specify { expect_disallowed(:destroy_project_bot_member) }
|
2019-04-04 10:19:57 -04:00
|
|
|
end
|
|
|
|
|
2019-07-24 05:20:54 -04:00
|
|
|
context 'with the group parent' do
|
2019-04-04 10:19:57 -04:00
|
|
|
let(:current_user) { create :user }
|
|
|
|
let(:subgroup) { create(:group, :private, parent: group)}
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(owner)
|
|
|
|
subgroup.add_owner(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect_allowed(:destroy_group_member)
|
|
|
|
expect_allowed(:update_group_member)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without group parent' do
|
|
|
|
let(:current_user) { create :user }
|
|
|
|
let(:subgroup) { create(:group, :private)}
|
|
|
|
|
|
|
|
before do
|
|
|
|
subgroup.add_owner(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect_disallowed(:destroy_group_member)
|
|
|
|
expect_disallowed(:update_group_member)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without group parent with two owners' do
|
|
|
|
let(:current_user) { create :user }
|
|
|
|
let(:other_user) { create :user }
|
|
|
|
let(:subgroup) { create(:group, :private)}
|
|
|
|
|
|
|
|
before do
|
|
|
|
subgroup.add_owner(current_user)
|
|
|
|
subgroup.add_owner(other_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect_allowed(:destroy_group_member)
|
|
|
|
expect_allowed(:update_group_member)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|