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 ...@@ -5,9 +5,11 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
end end
def update 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, redirect_to admin_application_settings_path,
notice: 'Application settings saved successfully' notice: 'Application settings saved successfully'
else else
......
module ApplicationSettings module ApplicationSettings
class BaseService < ::BaseService class BaseService < ::BaseService
attr_accessor :application_setting, :current_user, :params
def initialize(application_setting, user, params = {}) def initialize(application_setting, user, params = {})
@application_setting, @current_user, @params = application_setting, user, params.dup @application_setting, @current_user, @params = application_setting, user, params.dup
end end
......
...@@ -2,13 +2,10 @@ module ApplicationSettings ...@@ -2,13 +2,10 @@ module ApplicationSettings
class UpdateService < ApplicationSettings::BaseService class UpdateService < ApplicationSettings::BaseService
def execute def execute
# Repository size limit comes as MB from the view # 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) @application_setting.update(@params)
success
else
error('Application settings could not be updated')
end
end end
end end
end end
...@@ -46,13 +46,6 @@ class BaseService ...@@ -46,13 +46,6 @@ class BaseService
private 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) def error(message, http_status = nil)
result = { result = {
message: message, message: message,
......
...@@ -13,7 +13,8 @@ module Groups ...@@ -13,7 +13,8 @@ module Groups
end end
# Repository size limit comes as MB from the view # 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) if @group.parent && !can?(current_user, :admin_group, @group.parent)
@group.parent = nil @group.parent = nil
......
...@@ -13,7 +13,8 @@ module Groups ...@@ -13,7 +13,8 @@ module Groups
end end
# Repository size limit comes as MB from the view # 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) group.assign_attributes(params)
......
...@@ -23,19 +23,9 @@ module Projects ...@@ -23,19 +23,9 @@ module Projects
end end
# Repository size limit comes as MB from the view # 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 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
# get namespace id # get namespace id
namespace_id = params[:namespace_id] namespace_id = params[:namespace_id]
...@@ -154,5 +144,24 @@ module Projects ...@@ -154,5 +144,24 @@ module Projects
service.save! service.save!
end end
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
end end
...@@ -14,7 +14,8 @@ module Projects ...@@ -14,7 +14,8 @@ module Projects
end end
# Repository size limit comes as MB from the view # 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_branch = params.delete(:default_branch)
new_repository_storage = params.delete(:repository_storage) new_repository_storage = params.delete(:repository_storage)
......
...@@ -20,9 +20,7 @@ describe ApplicationSettings::UpdateService, services: true do ...@@ -20,9 +20,7 @@ describe ApplicationSettings::UpdateService, services: true do
let(:opts) { { repository_size_limit: '100' } } let(:opts) { { repository_size_limit: '100' } }
it 'returns success params' do it 'returns success params' do
result = service.execute expect(service.execute).to eql(true)
expect(result).to eql(status: :success)
end end
end end
...@@ -30,9 +28,7 @@ describe ApplicationSettings::UpdateService, services: true do ...@@ -30,9 +28,7 @@ describe ApplicationSettings::UpdateService, services: true do
let(:opts) { { repository_size_limit: '-100' } } let(:opts) { { repository_size_limit: '-100' } }
it 'returns error params' do it 'returns error params' do
result = service.execute expect(service.execute).to eql(false)
expect(result).to eql(message: "Application settings could not be updated", status: :error)
end end
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