require enterprise feature in projects create contract

This commit is contained in:
Ivan Kuchin
2025-11-26 14:22:52 +01:00
parent cf156d4ca4
commit 891da06266
2 changed files with 42 additions and 30 deletions
@@ -34,11 +34,15 @@ module Projects
attribute :template
include AdminWritableTimestamps
include RequiresEnterpriseGuard
# Projects update their updated_at timestamp due to awesome_nested_set
# so allowing writing here would be useless.
allow_writable_timestamps :created_at
self.enterprise_action = :portfolio_management
self.enterprise_condition = proc { model.portfolio? || model.program? }
def writable_attributes
if allowed_to_write_custom_fields?
super
+38 -30
View File
@@ -64,34 +64,6 @@ RSpec.describe Projects::CreateContract do
it_behaves_like "contract is invalid", base: %i(error_unauthorized)
end
context "when having the 'portfolio' workspace_type and having the add_portfolios permission" do
let(:project_workspace_type) { "portfolio" }
let(:global_permissions) { [:add_portfolios] }
it_behaves_like "contract is valid"
end
context "when having the 'portfolio' workspace_type and lacking the add_portfolios permission" do
let(:project_workspace_type) { "portfolio" }
let(:global_permissions) { [] }
it_behaves_like "contract is invalid", base: %i(error_unauthorized)
end
context "when having the 'program' workspace_type and having the add_programs permission" do
let(:project_workspace_type) { "program" }
let(:global_permissions) { [:add_programs] }
it_behaves_like "contract is valid"
end
context "when having the 'program' workspace_type and lacking the add_programs permission" do
let(:project_workspace_type) { "program" }
let(:global_permissions) { [:add_portfolios] }
it_behaves_like "contract is invalid", base: %i(error_unauthorized)
end
context "if workspace_type is nil" do
let(:project_workspace_type) { nil }
@@ -107,13 +79,49 @@ RSpec.describe Projects::CreateContract do
context "if workspace type is 'program'" do
let(:project_workspace_type) { "program" }
it_behaves_like "contract is valid"
context "without portfolio_management enterprise feature", with_ee: [] do
it_behaves_like "contract is invalid", base: %i[error_enterprise_only]
end
context "with portfolio_management enterprise feature", with_ee: :portfolio_management do
it_behaves_like "contract is valid"
context "without the add_programs permission" do
let(:global_permissions) { %i[add_project add_portfolios] }
it_behaves_like "contract is invalid", base: %i[error_unauthorized]
end
context "having the add_programs permission" do
let(:global_permissions) { %i[add_programs] }
it_behaves_like "contract is valid"
end
end
end
context "if workspace type is 'portfolio'" do
let(:project_workspace_type) { "portfolio" }
it_behaves_like "contract is valid"
context "without portfolio_management enterprise feature", with_ee: [] do
it_behaves_like "contract is invalid", base: %i[error_enterprise_only]
end
context "with portfolio_management enterprise feature", with_ee: :portfolio_management do
it_behaves_like "contract is valid"
context "without the add_portfolios permission" do
let(:global_permissions) { %i[add_project add_programs] }
it_behaves_like "contract is invalid", base: %i[error_unauthorized]
end
context "having the add_portfolios permission" do
let(:global_permissions) { %i[add_portfolios] }
it_behaves_like "contract is valid"
end
end
end
context "if workspace type is 'invalid type'" do