Commit 156c40d6 authored by Rubén Dávila's avatar Rubén Dávila

Protect repository size limit setting through a license check

parent 9bd93670
......@@ -414,6 +414,8 @@ module EE
end
def size_limit_enabled?
return false unless License.feature_available?(:repository_size_limit)
actual_size_limit != 0
end
......
......@@ -25,7 +25,8 @@ class License < ActiveRecord::Base
OBJECT_STORAGE_FEATURE = 'GitLab_ObjectStorage'.freeze
PROTECTED_REFS_FOR_USERS_FEATURE = 'GitLab_RefPermissionsForUsers'.freeze
PUSH_RULES_FEATURE = 'GitLab_PushRules'.freeze
RELATED_ISSUES_FEATURE = 'RelatedIssues'.freeze
RELATED_ISSUES_FEATURE = 'GitLab_RelatedIssues'.freeze
REPOSITORY_SIZE_LIMIT_FEATURE = 'GitLab_RepositorySizeLimit'.freeze
SERVICE_DESK_FEATURE = 'GitLab_ServiceDesk'.freeze
VARIABLE_ENVIRONMENT_SCOPE_FEATURE = 'GitLab_VariableEnvironmentScope'.freeze
......@@ -36,6 +37,7 @@ class License < ActiveRecord::Base
geo: GEO_FEATURE,
object_storage: OBJECT_STORAGE_FEATURE,
related_issues: RELATED_ISSUES_FEATURE,
repository_size_limit: REPOSITORY_SIZE_LIMIT_FEATURE,
service_desk: SERVICE_DESK_FEATURE,
variable_environment_scope: VARIABLE_ENVIRONMENT_SCOPE_FEATURE,
......@@ -85,7 +87,8 @@ class License < ActiveRecord::Base
{ MULTIPLE_ISSUE_BOARDS_FEATURE => 1 },
{ PUSH_RULES_FEATURE => 1 },
{ PROTECTED_REFS_FOR_USERS_FEATURE => 1 },
{ RELATED_ISSUES_FEATURE => 1 }
{ RELATED_ISSUES_FEATURE => 1 },
{ REPOSITORY_SIZE_LIMIT_FEATURE => 1 }
].freeze
EEP_FEATURES = [
......
......@@ -65,14 +65,9 @@
= f.label :max_attachment_size, 'Maximum attachment size (MB)', class: 'control-label col-sm-2'
.col-sm-10
= f.number_field :max_attachment_size, class: 'form-control'
.form-group
= f.label :repository_size_limit, class: 'control-label col-sm-2' do
Size limit per repository (MB)
.col-sm-10
= f.number_field :repository_size_limit, value: f.object.repository_size_limit.try(:to_mb), class: 'form-control', min: 0
%span.help-block#repository_size_limit_help_block
Includes LFS objects. It can be overridden per group, or per project. 0 for unlimited.
= link_to icon('question-circle'), help_page_path("user/admin_area/settings/account_and_limit_settings")
= render 'repository_size_limit_setting', form: f
.form-group
= f.label :session_expire_delay, 'Session duration (minutes)', class: 'control-label col-sm-2'
.col-sm-10
......
- return unless License.feature_available?(:repository_size_limit)
- form = local_assigns.fetch(:form)
.form-group
= form.label :repository_size_limit, class: 'control-label col-sm-2' do
Size limit per repository (MB)
.col-sm-10
= form.number_field :repository_size_limit, value: form.object.repository_size_limit.try(:to_mb), class: 'form-control', min: 0
%span.help-block#repository_size_limit_help_block
Includes LFS objects. It can be overridden per group, or per project. 0 for unlimited.
= link_to icon('question-circle'), help_page_path("user/admin_area/settings/account_and_limit_settings")
......@@ -2,7 +2,7 @@
= form_errors(@group)
= render 'shared/group_form', f: f
= render 'groups/repository_size_limit_setting', f: f
= render 'shared/repository_size_limit_setting', form: f, type: :group
- if current_application_settings.should_check_namespace_plan?
= render 'admin/namespace_plan', f: f
......
- if current_user.admin?
.form-group
= f.label :repository_size_limit, class: 'control-label' do
Repository size limit (MB)
.col-sm-10
= f.number_field :repository_size_limit, value: f.object.repository_size_limit.try(:to_mb), class: 'form-control', min: 0
%span.help-block#repository_size_limit_help_block
= size_limit_message_for_group(@group)
......@@ -7,7 +7,7 @@
= form_errors(@group)
= render 'shared/group_form', f: f
= render 'repository_size_limit_setting', f: f
= render 'shared/repository_size_limit_setting', form: f, type: :group
.form-group
.col-sm-offset-2.col-sm-10
......
......@@ -37,13 +37,7 @@
= f.label :default_branch, "Default Branch", class: 'label-light'
= f.select(:default_branch, @project.repository.branch_names, {}, {class: 'select2 select-wide'})
- if current_user.admin?
.form-group
= f.label :repository_size_limit, class: 'label-light' do
Repository size limit (MB)
= f.number_field :repository_size_limit, value: f.object.repository_size_limit.try(:to_mb), class: 'form-control', min: 0
%span.help-block#repository_size_limit_help_block
= size_limit_message(@project)
= render 'shared/repository_size_limit_setting', form: f, type: :project
.form-group
= f.label :tag_list, "Tags", class: 'label-light'
......
- return unless current_user.admin? && License.feature_available?(:repository_size_limit)
- form = local_assigns.fetch(:form)
- type = local_assigns.fetch(:type)
- label_class = (type == :project) ? 'label-light' : 'control-label'
.form-group
= form.label :repository_size_limit, class: label_class do
Repository size limit (MB)
- if type == :project
= form.number_field :repository_size_limit, value: form.object.repository_size_limit.try(:to_mb), class: 'form-control', min: 0
%span.help-block#repository_size_limit_help_block
= size_limit_message(@project)
- elsif type == :group
.col-sm-10
= form.number_field :repository_size_limit, value: form.object.repository_size_limit.try(:to_mb), class: 'form-control', min: 0
%span.help-block#repository_size_limit_help_block
= size_limit_message_for_group(@group)
......@@ -2,19 +2,26 @@ FactoryGirl.define do
factory :gitlab_license, class: "Gitlab::License" do
starts_at { Date.today - 1.month }
expires_at { Date.today + 11.months }
notify_users_at { |l| l.expires_at }
notify_admins_at { |l| l.expires_at }
licensee do
{ "Name" => generate(:name) }
end
restrictions do
{
add_ons: {
'GitLab_FileLocks' => 1,
'GitLab_Auditor_User' => 1
}
},
plan: plan
}
end
notify_users_at { |l| l.expires_at }
notify_admins_at { |l| l.expires_at }
transient do
plan License::STARTER_PLAN
end
trait :trial do
restrictions do
......@@ -24,7 +31,11 @@ FactoryGirl.define do
end
factory :license do
data { build(:gitlab_license).export }
transient do
plan nil
end
data { build(:gitlab_license, plan: plan).export }
end
factory :trial_license, class: License do
......
......@@ -322,8 +322,50 @@ describe Project, models: true do
end
end
describe '#size_limit_enabled?' do
let(:project) { create(:empty_project) }
context 'when repository_size_limit is not configured' do
it 'is disabled' do
expect(project.size_limit_enabled?).to be_falsey
end
end
context 'when repository_size_limit is configured' do
before do
project.update_attributes(repository_size_limit: 1024)
end
context 'with an EES license' do
let!(:license) { create(:license, plan: License::STARTER_PLAN) }
it 'is enabled' do
expect(project.size_limit_enabled?).to be_truthy
end
end
context 'with an EEP license' do
let!(:license) { create(:license, plan: License::PREMIUM_PLAN) }
it 'is enabled' do
expect(project.size_limit_enabled?).to be_truthy
end
end
context 'without a License' do
before do
License.destroy_all
end
it 'is disabled' do
expect(project.size_limit_enabled?).to be_falsey
end
end
end
end
describe '#service_desk_enabled?' do
let!(:license) { create(:license, data: build(:gitlab_license, restrictions: { plan: License::PREMIUM_PLAN }).export) }
let!(:license) { create(:license, plan: License::PREMIUM_PLAN) }
let(:namespace) { create(:namespace) }
subject(:project) { build(:empty_project, :private, namespace: namespace, service_desk_enabled: true) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment