From f12e9cb0d6384ef742ed4c712909df3e31c2c892 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Sun, 28 Aug 2016 10:41:31 +0100 Subject: adds migration and controller updating for repository_size_limit --- app/controllers/admin/application_settings_controller.rb | 2 +- app/models/application_setting.rb | 4 ++-- app/models/project.rb | 9 +++++++++ app/views/admin/application_settings/_form.html.haml | 5 +++-- 4 files changed, 15 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index be483459f70..42e5a288710 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -118,7 +118,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController :container_registry_token_expire_delay, :repository_storage, :enabled_git_access_protocol, - :project_size_limit, + :repository_size_limit, restricted_visibility_levels: [], import_sources: [], disabled_oauth_sign_in_sources: [] diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 36d8bfa36ef..73c4d639335 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -63,9 +63,9 @@ class ApplicationSetting < ActiveRecord::Base presence: true, numericality: { only_integer: true, greater_than: 0 } - validates :project_size_limit, + validates :repository_size_limit, presence: true, - numericality: { only_integer: true, greater_than: 0 } + numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :container_registry_token_expire_delay, presence: true, diff --git a/app/models/project.rb b/app/models/project.rb index e5027af4a0e..41122caf4ae 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1286,6 +1286,15 @@ class Project < ActiveRecord::Base end end + def above_size_limit? + return false if current_application_settings.repository_size_limit == 0 + repository_size >= current_application_settings.repository_size_limit + end + + def size_to_remove + return repository_size - current_application_settings.repository_size_limit + end + private def default_branch_protected? diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index 7410e6d883e..e8dde039c1b 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -89,9 +89,10 @@ .col-sm-10 = f.number_field :max_attachment_size, class: 'form-control' .form-group - = f.label :project_size_limit, 'Project size limit (MB)', class: 'control-label col-sm-2' + = f.label :repository_size_limit, 'Repository size limit (MB)', class: 'control-label col-sm-2' .col-sm-10 - = f.number_field :project_size_limit, class: 'form-control' + = f.number_field :repository_size_limit, class: 'form-control' + %span.help-block#repository_size_limit_help_block This limit is per repository. This includes LFS storage. 0 for unlimited .form-group = f.label :session_expire_delay, 'Session duration (minutes)', class: 'control-label col-sm-2' .col-sm-10 -- cgit v1.2.3