mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-12 08:04:34 +08:00
Add global repositories limit [SCI-4383]
This commit is contained in:
parent
f2ce01db75
commit
63e557ea9e
5 changed files with 32 additions and 116 deletions
|
@ -362,16 +362,11 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_create_permissions
|
def check_create_permissions
|
||||||
unless can_create_repositories?(@team) ||
|
render_403 unless can_create_repositories?(@team)
|
||||||
@team.repositories.count < Rails.configuration.x.repositories_limit
|
|
||||||
render_403
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_copy_permissions
|
def check_copy_permissions
|
||||||
render_403 if !can_create_repositories?(@team) ||
|
render_403 if !can_create_repositories?(@team) || @repository.shared_with?(current_team)
|
||||||
@team.repositories.count >= Rails.configuration.x.repositories_limit ||
|
|
||||||
@repository.shared_with?(current_team)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_manage_permissions
|
def check_manage_permissions
|
||||||
|
|
|
@ -43,8 +43,16 @@ Canaid::Permissions.register_for(Team) do
|
||||||
|
|
||||||
# repository: create, copy
|
# repository: create, copy
|
||||||
can :create_repositories do |user, team|
|
can :create_repositories do |user, team|
|
||||||
user.is_admin_of_team?(team) &&
|
within_limits = true
|
||||||
team.repositories.count < Rails.configuration.x.repositories_limit
|
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 && user.is_admin_of_team?(team)
|
||||||
end
|
end
|
||||||
|
|
||||||
# this permission is scattered around the application
|
# this permission is scattered around the application
|
||||||
|
|
|
@ -43,26 +43,8 @@ module FirstTimeDataGenerator
|
||||||
)
|
)
|
||||||
|
|
||||||
# check if samples repo already exist, then create custom repository samples
|
# check if samples repo already exist, then create custom repository samples
|
||||||
repository = Repository.where(team: team).where(name: REPO_SAMPLES_NAME)
|
repository = Repository.where(team: team).where(name: REPO_SAMPLES_NAME).take
|
||||||
repository =
|
repository ||= Repository.create(name: REPO_SAMPLES_NAME, team: team, created_by: user)
|
||||||
if repository.blank?
|
|
||||||
if team.repositories.count < Rails.configuration.x.repositories_limit
|
|
||||||
Repository.create(
|
|
||||||
name: REPO_SAMPLES_NAME,
|
|
||||||
team: team,
|
|
||||||
created_by: user
|
|
||||||
)
|
|
||||||
else
|
|
||||||
# User first repo just as a placeholder, this call will fail anyhow
|
|
||||||
Repository.create(
|
|
||||||
name: team.repositories.first.name,
|
|
||||||
team: team,
|
|
||||||
created_by: user
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
repository.first
|
|
||||||
end
|
|
||||||
|
|
||||||
# create list value column for sample types
|
# create list value column for sample types
|
||||||
repo_columns = []
|
repo_columns = []
|
||||||
|
@ -164,64 +146,6 @@ module FirstTimeDataGenerator
|
||||||
)
|
)
|
||||||
repository_rows_to_assign << repository_row
|
repository_rows_to_assign << repository_row
|
||||||
end
|
end
|
||||||
# Create sample types
|
|
||||||
SampleType.create(
|
|
||||||
name: 'Potato leaves',
|
|
||||||
team: team
|
|
||||||
)
|
|
||||||
|
|
||||||
SampleType.create(
|
|
||||||
name: 'Tea leaves',
|
|
||||||
team: team
|
|
||||||
)
|
|
||||||
|
|
||||||
SampleType.create(
|
|
||||||
name: 'Potato bug',
|
|
||||||
team: team
|
|
||||||
)
|
|
||||||
|
|
||||||
SampleGroup.create(
|
|
||||||
name: 'Fodder',
|
|
||||||
team: team,
|
|
||||||
color: Constants::TAG_COLORS[1]
|
|
||||||
)
|
|
||||||
|
|
||||||
SampleGroup.create(
|
|
||||||
name: 'Nutrient',
|
|
||||||
team: team,
|
|
||||||
color: Constants::TAG_COLORS[0]
|
|
||||||
)
|
|
||||||
|
|
||||||
SampleGroup.create(
|
|
||||||
name: 'Seed',
|
|
||||||
team: team,
|
|
||||||
color: Constants::TAG_COLORS[2]
|
|
||||||
)
|
|
||||||
|
|
||||||
samples = []
|
|
||||||
# Generate random sample names start
|
|
||||||
# and put it on the beginning of 5 samples
|
|
||||||
sample_name = (0...3).map{65.+(rand(26)).chr}.join << '/'
|
|
||||||
for i in 1..5
|
|
||||||
samples << Sample.create(
|
|
||||||
name: sample_name + i.to_s,
|
|
||||||
team: team,
|
|
||||||
user: user,
|
|
||||||
sample_type: rand < 0.8 ? pluck_random(team.sample_types) : nil,
|
|
||||||
sample_group: rand < 0.8 ? pluck_random(team.sample_groups) : nil
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
sample_name = (0...3).map{65.+(rand(26)).chr}.join << '/'
|
|
||||||
for i in 1..5
|
|
||||||
samples << Sample.create(
|
|
||||||
name: sample_name + i.to_s,
|
|
||||||
team: team,
|
|
||||||
user: user,
|
|
||||||
sample_type: rand < 0.8 ? pluck_random(team.sample_types) : nil,
|
|
||||||
sample_group: rand < 0.8 ? pluck_random(team.sample_groups) : nil
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
experiment_description =
|
experiment_description =
|
||||||
'Polymerase chain reaction (PCR) monitors the amplification of DNA ' \
|
'Polymerase chain reaction (PCR) monitors the amplification of DNA ' \
|
||||||
|
@ -347,24 +271,7 @@ module FirstTimeDataGenerator
|
||||||
created_at: generate_random_time(archived_module.created_at, 2.minutes)
|
created_at: generate_random_time(archived_module.created_at, 2.minutes)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Assign 4 samples to modules
|
|
||||||
samples_to_assign = []
|
|
||||||
taken_sample_ids = []
|
|
||||||
for _ in 1..4
|
|
||||||
begin
|
|
||||||
sample = samples.sample
|
|
||||||
end while sample.id.in? taken_sample_ids
|
|
||||||
taken_sample_ids << sample.id
|
|
||||||
samples_to_assign << sample
|
|
||||||
end
|
|
||||||
|
|
||||||
my_modules[1].downstream_modules.each do |mm|
|
my_modules[1].downstream_modules.each do |mm|
|
||||||
samples_to_assign.each do |s|
|
|
||||||
SampleMyModule.create(
|
|
||||||
sample: s,
|
|
||||||
my_module: mm
|
|
||||||
)
|
|
||||||
end
|
|
||||||
repository_rows_to_assign.each do |repository_row|
|
repository_rows_to_assign.each do |repository_row|
|
||||||
MyModuleRepositoryRow.create!(
|
MyModuleRepositoryRow.create!(
|
||||||
repository_row: repository_row,
|
repository_row: repository_row,
|
||||||
|
@ -572,9 +479,6 @@ module FirstTimeDataGenerator
|
||||||
module_step_names,
|
module_step_names,
|
||||||
module_step_descriptions)
|
module_step_descriptions)
|
||||||
|
|
||||||
# Delete repository items, if we went over the limit
|
|
||||||
repository_rows_to_assign.map(&:destroy) unless repository.id
|
|
||||||
|
|
||||||
# Add table to existig step
|
# Add table to existig step
|
||||||
step = my_modules[1].protocol.steps.where('position = 0').take
|
step = my_modules[1].protocol.steps.where('position = 0').take
|
||||||
Table.create(
|
Table.create(
|
||||||
|
@ -632,7 +536,7 @@ module FirstTimeDataGenerator
|
||||||
)
|
)
|
||||||
temp_text = "There are many biological replicates we harvested " \
|
temp_text = "There are many biological replicates we harvested " \
|
||||||
"for each type of sample (code-names):\n\n"
|
"for each type of sample (code-names):\n\n"
|
||||||
samples_to_assign.each do |s|
|
repository_rows_to_assign.each do |s|
|
||||||
temp_text << "* #{s.name}\n\n"
|
temp_text << "* #{s.name}\n\n"
|
||||||
end
|
end
|
||||||
temp_result.result_text = ResultText.new(
|
temp_result.result_text = ResultText.new(
|
||||||
|
@ -1082,10 +986,10 @@ module FirstTimeDataGenerator
|
||||||
created_by: user,
|
created_by: user,
|
||||||
team: team,
|
team: team,
|
||||||
contents: tab_content['module6']['distribution'] % {
|
contents: tab_content['module6']['distribution'] % {
|
||||||
sample0: samples_to_assign[0].name,
|
sample0: repository_rows_to_assign[0].name,
|
||||||
sample1: samples_to_assign[1].name,
|
sample1: repository_rows_to_assign[1].name,
|
||||||
sample2: samples_to_assign[2].name,
|
sample2: repository_rows_to_assign[2].name,
|
||||||
sample3: samples_to_assign[3].name
|
sample3: repository_rows_to_assign[3].name
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
temp_result.save
|
temp_result.save
|
||||||
|
|
|
@ -996,6 +996,8 @@ class Constants
|
||||||
|
|
||||||
IMPORT_REPOSITORY_ITEMS_LIMIT = 2000
|
IMPORT_REPOSITORY_ITEMS_LIMIT = 2000
|
||||||
|
|
||||||
|
DEFAULT_TEAM_REPOSITORIES_LIMIT = 6
|
||||||
|
|
||||||
# Very basic regex to check for validity of emails
|
# Very basic regex to check for validity of emails
|
||||||
BASIC_EMAIL_REGEX = URI::MailTo::EMAIL_REGEXP
|
BASIC_EMAIL_REGEX = URI::MailTo::EMAIL_REGEXP
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
Rails.application.configure do
|
Rails.application.configure do
|
||||||
# Maximum number of repositories per team allowed
|
# Maximum number of repositories per team allowed
|
||||||
config.x.repositories_limit =
|
config.x.team_repositories_limit =
|
||||||
if ENV['REPOSITORIES_LIMIT']
|
if ENV['TEAM_REPOSITORIES_LIMIT']
|
||||||
ENV['REPOSITORIES_LIMIT'].to_i
|
ENV['TEAM_REPOSITORIES_LIMIT'].to_i
|
||||||
else
|
else
|
||||||
6
|
Constants::DEFAULT_TEAM_REPOSITORIES_LIMIT
|
||||||
|
end
|
||||||
|
|
||||||
|
config.x.global_repositories_limit =
|
||||||
|
if ENV['GLOBAL_REPOSITORIES_LIMIT']
|
||||||
|
ENV['GLOBAL_REPOSITORIES_LIMIT'].to_i
|
||||||
|
else
|
||||||
|
0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue