mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-28 11:14:24 +08:00
Refactor inventory limit checks [SCI-4434]
This commit is contained in:
parent
f201826eb8
commit
02817a5a1e
2 changed files with 14 additions and 9 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue