OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add validation to contract
Oliver Günthera842422482b2
diff --git a/app/contracts/users/create_contract.rb b/app/contracts/users/create_contract.rbindex 63b7abd48bc..1b4ddab137e 100644--- a/app/contracts/users/create_contract.rb+++ b/app/contracts/users/create_contract.rb@@ -42,9 +42,16 @@ module Usersvalidate :user_allowed_to_addvalidate :authentication_definedvalidate :type_is_user+ validate :user_limit_not_exceededprivate+ def user_limit_not_exceeded+ if OpenProject::Enterprise.user_limit_reached?+ errors.add :base, :user_limit_reached+ end+ end+def authentication_definederrors.add :password, :blank if model.active? && no_auth?enddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 410ca6a2eb7..f1c2e3abbcb 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -812,6 +812,8 @@ en:group_without_name: "Unnamed groups are not allowed."user:attributes:+ base:+ user_limit_reached: "User limit reached. No more accounts can be created on the current plan."password_confirmation:confirmation: "Password confirmation does not match password."format: "%{message}"diff --git a/spec/contracts/users/create_contract_spec.rb b/spec/contracts/users/create_contract_spec.rbindex 31911877335..15cf4d27875 100644--- a/spec/contracts/users/create_contract_spec.rb+++ b/spec/contracts/users/create_contract_spec.rb@@ -71,6 +71,14 @@ describe Users::CreateContract doit_behaves_like 'contract is valid'endend++ context 'when user limit reached' do+ before do+ allow(OpenProject::Enterprise).to receive(:user_limit_reached?).and_return(true)+ end++ it_behaves_like 'contract is invalid', base: :user_limit_reached+ endendendend