diff --git a/app/models/repository.rb b/app/models/repository.rb index 302bf9058..2fa75675b 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -50,6 +50,18 @@ class Repository < ApplicationRecord .where.not(id: accessible_by_teams(team.id).select(:id)).distinct } + def self.within_global_limits? + return true unless Rails.configuration.x.global_repositories_limit.positive? + + count < Rails.configuration.x.global_repositories_limit + end + + def self.within_team_limits?(team) + return true unless Rails.configuration.x.team_repositories_limit.positive? + + team.repositories.count < Rails.configuration.x.team_repositories_limit + end + def self.search( user, query = nil, diff --git a/app/permissions/team.rb b/app/permissions/team.rb index 3c38611a9..e8a564fd7 100644 --- a/app/permissions/team.rb +++ b/app/permissions/team.rb @@ -48,15 +48,8 @@ Canaid::Permissions.register_for(Team) do # repository: create, copy can :create_repositories do |user, team| - within_limits = true - if Rails.configuration.x.global_repositories_limit.positive? - within_limits = Repository.count < Rails.configuration.x.global_repositories_limit - end - - if within_limits && Rails.configuration.x.team_repositories_limit.positive? - within_limits = team.repositories.count < Rails.configuration.x.team_repositories_limit - end - + within_limits = Repository.within_global_limits? + within_limits = Repository.within_team_limits?(team) if within_limits within_limits && user.is_admin_of_team?(team) end