Commit b0cc24b0 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'tech-debit-repository-size-limit-fix' into 'master'

Refactoring for repository size limit MB to Byte conversion module

See merge request !1094
parents d5549025 0fa7c880
......@@ -5,9 +5,11 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
end
def update
result = ::ApplicationSettings::UpdateService.new(@application_setting, current_user, application_setting_params).execute
successful = ApplicationSettings::UpdateService
.new(@application_setting, current_user, application_setting_params)
.execute
if result[:status] == :success
if successful
redirect_to admin_application_settings_path,
notice: 'Application settings saved successfully'
else
......
module ApplicationSettings
class BaseService < ::BaseService
attr_accessor :application_setting, :current_user, :params
def initialize(application_setting, user, params = {})
@application_setting, @current_user, @params = application_setting, user, params.dup
end
......
......@@ -2,13 +2,10 @@ module ApplicationSettings
class UpdateService < ApplicationSettings::BaseService
def execute
# Repository size limit comes as MB from the view
assign_repository_size_limit_as_bytes(application_setting)
limit = @params.delete(:repository_size_limit)
@application_setting.repository_size_limit = (limit.to_i.megabytes if limit.present?)
if application_setting.update(params)
success
else
error('Application settings could not be updated')
end
@application_setting.update(@params)
end
end
end
......@@ -46,13 +46,6 @@ class BaseService
private
def assign_repository_size_limit_as_bytes(model)
repository_size_limit = @params.delete(:repository_size_limit)
new_value = repository_size_limit.to_i.megabytes if repository_size_limit.present?
model.repository_size_limit = new_value
end
def error(message, http_status = nil)
result = {
message: message,
......
......@@ -13,7 +13,8 @@ module Groups
end
# Repository size limit comes as MB from the view
assign_repository_size_limit_as_bytes(@group)
limit = params.delete(:repository_size_limit)
@group.repository_size_limit = (limit.to_i.megabytes if limit.present?)
if @group.parent && !can?(current_user, :admin_group, @group.parent)
@group.parent = nil
......
......@@ -13,7 +13,8 @@ module Groups
end
# Repository size limit comes as MB from the view
assign_repository_size_limit_as_bytes(group)
limit = @params.delete(:repository_size_limit)
group.repository_size_limit = (limit.to_i.megabytes if limit.present?)
group.assign_attributes(params)
......
......@@ -23,19 +23,9 @@ module Projects
end
# Repository size limit comes as MB from the view
assign_repository_size_limit_as_bytes(@project)
set_repository_size_limit_as_bytes
# Set project name from path
if @project.name.present? && @project.path.present?
# if both name and path set - everything is ok
elsif @project.path.present?
# Set project name from path
@project.name = @project.path.dup
elsif @project.name.present?
# For compatibility - set path from name
# TODO: remove this in 8.0
@project.path = @project.name.dup.parameterize
end
set_project_name_from_path
# get namespace id
namespace_id = params[:namespace_id]
......@@ -154,5 +144,24 @@ module Projects
service.save!
end
end
def set_repository_size_limit_as_bytes
limit = params.delete(:repository_size_limit)
@project.repository_size_limit = (limit.to_i.megabytes if limit.present?)
end
def set_project_name_from_path
# Set project name from path
if @project.name.present? && @project.path.present?
# if both name and path set - everything is ok
elsif @project.path.present?
# Set project name from path
@project.name = @project.path.dup
elsif @project.name.present?
# For compatibility - set path from name
# TODO: remove this in 8.0
@project.path = @project.name.dup.parameterize
end
end
end
end
......@@ -14,7 +14,8 @@ module Projects
end
# Repository size limit comes as MB from the view
assign_repository_size_limit_as_bytes(project)
limit = params.delete(:repository_size_limit)
project.repository_size_limit = (limit.to_i.megabytes if limit.present?)
new_branch = params.delete(:default_branch)
new_repository_storage = params.delete(:repository_storage)
......
......@@ -20,9 +20,7 @@ describe ApplicationSettings::UpdateService, services: true do
let(:opts) { { repository_size_limit: '100' } }
it 'returns success params' do
result = service.execute
expect(result).to eql(status: :success)
expect(service.execute).to eql(true)
end
end
......@@ -30,9 +28,7 @@ describe ApplicationSettings::UpdateService, services: true do
let(:opts) { { repository_size_limit: '-100' } }
it 'returns error params' do
result = service.execute
expect(result).to eql(message: "Application settings could not be updated", status: :error)
expect(service.execute).to eql(false)
end
end
......
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