2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
2020-10-24 23:57:45 +05:30
|
|
|
require "spec_helper"
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe DesignManagement::DesignPolicy do
|
2020-05-24 23:13:21 +05:30
|
|
|
include DesignManagementTestHelpers
|
|
|
|
|
|
|
|
let(:guest_design_abilities) { %i[read_design] }
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:developer_design_abilities) { %i[create_design destroy_design move_design] }
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:design_abilities) { guest_design_abilities + developer_design_abilities }
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
let_it_be(:guest) { create(:user) }
|
|
|
|
let_it_be(:reporter) { create(:user) }
|
|
|
|
let_it_be(:developer) { create(:user) }
|
|
|
|
let_it_be(:maintainer) { create(:user) }
|
|
|
|
let_it_be(:owner) { create(:user) }
|
|
|
|
let_it_be(:admin) { create(:admin) }
|
|
|
|
let_it_be(:project) { create(:project, :public, namespace: owner.namespace) }
|
|
|
|
let_it_be(:issue) { create(:issue, project: project) }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:design) { create(:design, issue: issue) }
|
|
|
|
|
|
|
|
subject(:design_policy) { described_class.new(current_user, design) }
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
before_all do
|
|
|
|
project.add_guest(guest)
|
|
|
|
project.add_maintainer(maintainer)
|
|
|
|
project.add_developer(developer)
|
|
|
|
project.add_reporter(reporter)
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
shared_examples_for "design abilities not available" do
|
|
|
|
context "for owners" do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for admins" do
|
|
|
|
let(:current_user) { admin }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for maintainers" do
|
|
|
|
let(:current_user) { maintainer }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for developers" do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for reporters" do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for guests" do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for anonymous users" do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
shared_examples_for "read-only design abilities" do
|
|
|
|
it { is_expected.to be_allowed(*guest_design_abilities) }
|
|
|
|
it { is_expected.to be_disallowed(*developer_design_abilities) }
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
shared_examples_for "design abilities available for members" do
|
|
|
|
context "for owners" do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for admins" do
|
|
|
|
let(:current_user) { admin }
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context "when admin mode enabled", :enable_admin_mode do
|
2020-05-24 23:13:21 +05:30
|
|
|
it { is_expected.to be_allowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context "when admin mode disabled" do
|
2021-01-03 14:25:43 +05:30
|
|
|
it_behaves_like "read-only design abilities"
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for maintainers" do
|
|
|
|
let(:current_user) { maintainer }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for developers" do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for reporters" do
|
|
|
|
let(:current_user) { reporter }
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it_behaves_like "read-only design abilities"
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when DesignManagement is not enabled" do
|
|
|
|
before do
|
|
|
|
enable_design_management(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "design abilities not available"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the feature is available" do
|
|
|
|
before do
|
|
|
|
enable_design_management
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "design abilities available for members"
|
|
|
|
|
|
|
|
context "for guests in private projects" do
|
2020-10-24 23:57:45 +05:30
|
|
|
let_it_be(:project) { create(:project, :private) }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:current_user) { guest }
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it_behaves_like "read-only design abilities"
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "for anonymous users in public projects" do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it_behaves_like "read-only design abilities"
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "when the issue is confidential" do
|
2020-10-24 23:57:45 +05:30
|
|
|
let_it_be(:issue) { create(:issue, :confidential, project: project) }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
it_behaves_like "design abilities available for members"
|
|
|
|
|
|
|
|
context "for guests" do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "for anonymous users" do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*design_abilities) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the project is archived" do
|
2020-10-24 23:57:45 +05:30
|
|
|
let_it_be(:project) { create(:project, :public, :archived) }
|
|
|
|
let_it_be(:issue) { create(:issue, project: project) }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it_behaves_like "read-only design abilities"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|