Welcome to mirror list, hosted at ThFree Co, Russian Federation.

organization_policy_spec.rb « organizations « policies « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7eed497d6444cad91e55e3d2d77affff6446e287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Organizations::OrganizationPolicy, feature_category: :cell do
  let_it_be(:organization) { create(:organization) }
  let_it_be(:current_user) { create :user }

  subject(:policy) { described_class.new(current_user, organization) }

  context 'when the user is anonymous' do
    let_it_be(:current_user) { nil }

    it { is_expected.to be_allowed(:read_organization) }
    it { is_expected.to be_disallowed(:admin_organization) }
  end

  context 'when the user is an admin' do
    let_it_be(:current_user) { create(:user, :admin) }

    context 'when admin mode is enabled', :enable_admin_mode do
      it { is_expected.to be_allowed(:admin_organization) }
      it { is_expected.to be_allowed(:read_organization) }
      it { is_expected.to be_allowed(:read_organization_user) }
    end

    context 'when admin mode is disabled' do
      it { is_expected.to be_disallowed(:admin_organization) }
      it { is_expected.to be_allowed(:read_organization) }
    end
  end

  context 'when the user is part of the organization' do
    before do
      create :organization_user, organization: organization, user: current_user
    end

    it { is_expected.to be_allowed(:admin_organization) }
    it { is_expected.to be_allowed(:read_organization) }
    it { is_expected.to be_allowed(:read_organization_user) }
  end

  context 'when the user is not part of the organization' do
    it { is_expected.to be_disallowed(:admin_organization) }
    it { is_expected.to be_disallowed(:read_organization_user) }
    # All organizations are currently public, and hence they are allowed to be read
    # even if the user is not a part of the organization.
    it { is_expected.to be_allowed(:read_organization) }
  end
end