From 8ec643c54b03caeed9a14f18b2e58fc549c04f4d Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Wed, 9 May 2018 18:03:16 +0200 Subject: [PATCH] Move REPOSITORIES_LIMIT from constants to env variables [SCI-2301] --- app/controllers/at_who_controller.rb | 3 ++- app/controllers/repositories_controller.rb | 6 ++++-- app/permissions/team.rb | 2 +- config/initializers/constants.rb | 3 --- config/initializers/repositories.rb | 4 ++++ 5 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 config/initializers/repositories.rb diff --git a/app/controllers/at_who_controller.rb b/app/controllers/at_who_controller.rb index 89bc35c82..62ff98f85 100644 --- a/app/controllers/at_who_controller.rb +++ b/app/controllers/at_who_controller.rb @@ -44,7 +44,8 @@ class AtWhoController < ApplicationController end def repositories - repositories = @team.repositories.limit(Constants::REPOSITORIES_LIMIT) + repositories = + @team.repositories.limit(Rails.configuration.x.repositories_limit) respond_to do |format| format.json do render json: { diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9087d9c0b..31b6dae1b 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -300,8 +300,10 @@ class RepositoriesController < ApplicationController end def check_create_permissions - render_403 unless can_create_repositories?(@team) || - @team.repositories.count < Constants::REPOSITORIES_LIMIT + unless can_create_repositories?(@team) || + @team.repositories.count < Rails.configuration.x.repositories_limit + render_403 + end end def check_manage_permissions diff --git a/app/permissions/team.rb b/app/permissions/team.rb index cd45190f5..06753024f 100644 --- a/app/permissions/team.rb +++ b/app/permissions/team.rb @@ -44,7 +44,7 @@ Canaid::Permissions.register_for(Team) do # repository: create, copy can :create_repositories do |user, team| user.is_admin_of_team?(team) && - team.repositories.count < Constants::REPOSITORIES_LIMIT + team.repositories.count < Rails.configuration.x.repositories_limit end # repository: create/import record diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index f6e265ac6..8522fa252 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -58,9 +58,6 @@ class Constants # Max characters for repository name in Atwho modal ATWHO_REP_NAME_LIMIT = 16 - # Maximum number of repositories per team allowed - REPOSITORIES_LIMIT = 5 - #============================================================================= # File and data memory size #============================================================================= diff --git a/config/initializers/repositories.rb b/config/initializers/repositories.rb new file mode 100644 index 000000000..84d360168 --- /dev/null +++ b/config/initializers/repositories.rb @@ -0,0 +1,4 @@ +Rails.application.configure do + # Maximum number of repositories per team allowed + config.x.repositories_limit = ENV['REPOSITORIES_LIMIT'].to_i || 5 +end