Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
574b9c67
Commit
574b9c67
authored
Jan 20, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address MB to Bytes convertion on update/create services
parent
01e551fe
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
246 additions
and
4 deletions
+246
-4
app/controllers/admin/application_settings_controller.rb
app/controllers/admin/application_settings_controller.rb
+3
-1
app/services/application_settings/base_service.rb
app/services/application_settings/base_service.rb
+9
-0
app/services/application_settings/create_service.rb
app/services/application_settings/create_service.rb
+0
-0
app/services/application_settings/update_service.rb
app/services/application_settings/update_service.rb
+14
-0
app/services/base_service.rb
app/services/base_service.rb
+7
-0
app/services/groups/create_service.rb
app/services/groups/create_service.rb
+3
-0
app/services/groups/update_service.rb
app/services/groups/update_service.rb
+3
-0
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+3
-0
app/services/projects/update_service.rb
app/services/projects/update_service.rb
+3
-0
spec/controllers/admin/application_settings_controller_spec.rb
...controllers/admin/application_settings_controller_spec.rb
+30
-0
spec/models/ee/group_spec.rb
spec/models/ee/group_spec.rb
+1
-1
spec/models/project_spec.rb
spec/models/project_spec.rb
+2
-2
spec/services/application_settings/update_service_spec.rb
spec/services/application_settings/update_service_spec.rb
+69
-0
spec/services/groups/create_service_spec.rb
spec/services/groups/create_service_spec.rb
+25
-0
spec/services/groups/update_service_spec.rb
spec/services/groups/update_service_spec.rb
+25
-0
spec/services/projects/create_service_spec.rb
spec/services/projects/create_service_spec.rb
+24
-0
spec/services/projects/update_service_spec.rb
spec/services/projects/update_service_spec.rb
+25
-0
No files found.
app/controllers/admin/application_settings_controller.rb
View file @
574b9c67
...
@@ -5,7 +5,9 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
...
@@ -5,7 +5,9 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
end
end
def
update
def
update
if
@application_setting
.
update_attributes
(
application_setting_params
)
result
=
::
ApplicationSettings
::
UpdateService
.
new
(
@application_setting
,
current_user
,
application_setting_params
).
execute
if
result
[
:status
]
==
:success
redirect_to
admin_application_settings_path
,
redirect_to
admin_application_settings_path
,
notice:
'Application settings saved successfully'
notice:
'Application settings saved successfully'
else
else
...
...
app/services/application_settings/base_service.rb
0 → 100644
View file @
574b9c67
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
end
end
app/services/application_settings/create_service.rb
0 → 100644
View file @
574b9c67
app/services/application_settings/update_service.rb
0 → 100644
View file @
574b9c67
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
)
if
application_setting
.
update
(
params
)
success
else
error
(
'Application settings could not be updated'
)
end
end
end
end
app/services/base_service.rb
View file @
574b9c67
...
@@ -46,6 +46,13 @@ class BaseService
...
@@ -46,6 +46,13 @@ 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
,
...
...
app/services/groups/create_service.rb
View file @
574b9c67
...
@@ -12,6 +12,9 @@ module Groups
...
@@ -12,6 +12,9 @@ module Groups
return
@group
return
@group
end
end
# Repository size limit comes as MB from the view
assign_repository_size_limit_as_bytes
(
@group
)
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
@group
.
errors
.
add
(
:parent_id
,
'manage access required to create subgroup'
)
@group
.
errors
.
add
(
:parent_id
,
'manage access required to create subgroup'
)
...
...
app/services/groups/update_service.rb
View file @
574b9c67
...
@@ -12,6 +12,9 @@ module Groups
...
@@ -12,6 +12,9 @@ module Groups
end
end
end
end
# Repository size limit comes as MB from the view
assign_repository_size_limit_as_bytes
(
group
)
group
.
assign_attributes
(
params
)
group
.
assign_attributes
(
params
)
begin
begin
...
...
app/services/projects/create_service.rb
View file @
574b9c67
...
@@ -22,6 +22,9 @@ module Projects
...
@@ -22,6 +22,9 @@ module Projects
return
@project
return
@project
end
end
# Repository size limit comes as MB from the view
assign_repository_size_limit_as_bytes
(
@project
)
# Set project name from path
# Set project name from path
if
@project
.
name
.
present?
&&
@project
.
path
.
present?
if
@project
.
name
.
present?
&&
@project
.
path
.
present?
# if both name and path set - everything is ok
# if both name and path set - everything is ok
...
...
app/services/projects/update_service.rb
View file @
574b9c67
...
@@ -13,6 +13,9 @@ module Projects
...
@@ -13,6 +13,9 @@ module Projects
end
end
end
end
# Repository size limit comes as MB from the view
assign_repository_size_limit_as_bytes
(
project
)
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
)
...
...
spec/controllers/admin/application_settings_controller_spec.rb
View file @
574b9c67
...
@@ -6,6 +6,36 @@ describe Admin::ApplicationSettingsController do
...
@@ -6,6 +6,36 @@ describe Admin::ApplicationSettingsController do
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:user
)
{
create
(
:user
)}
let
(
:user
)
{
create
(
:user
)}
describe
'PUT #update'
do
before
do
sign_in
(
admin
)
end
context
'with valid params'
do
subject
{
put
:update
,
application_setting:
{
repository_size_limit:
'100'
}
}
it
'redirect to application settings page'
do
is_expected
.
to
redirect_to
(
admin_application_settings_path
)
end
it
'set flash notice'
do
is_expected
.
to
set_flash
[
:notice
].
to
(
'Application settings saved successfully'
)
end
end
context
'with invalid params'
do
subject!
{
put
:update
,
application_setting:
{
repository_size_limit:
'-100'
}
}
it
'render show template'
do
is_expected
.
to
render_template
(
:show
)
end
it
'assigned @application_settings has errors'
do
expect
(
assigns
(
:application_setting
).
errors
[
:repository_size_limit
]).
to
be_present
end
end
end
describe
'GET #usage_data with no access'
do
describe
'GET #usage_data with no access'
do
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
...
...
spec/models/ee/group_spec.rb
View file @
574b9c67
...
@@ -100,7 +100,7 @@ describe Group, models: true do
...
@@ -100,7 +100,7 @@ describe Group, models: true do
it
'returns the value set locally'
do
it
'returns the value set locally'
do
group
.
update_attribute
(
:repository_size_limit
,
75
)
group
.
update_attribute
(
:repository_size_limit
,
75
)
expect
(
group
.
actual_size_limit
).
to
eq
(
75
.
megabytes
)
expect
(
group
.
actual_size_limit
).
to
eq
(
75
)
end
end
end
end
...
...
spec/models/project_spec.rb
View file @
574b9c67
...
@@ -573,13 +573,13 @@ describe Project, models: true do
...
@@ -573,13 +573,13 @@ describe Project, models: true do
group
=
create
(
:group
,
repository_size_limit:
100
)
group
=
create
(
:group
,
repository_size_limit:
100
)
project
.
update_attribute
(
:namespace_id
,
group
.
id
)
project
.
update_attribute
(
:namespace_id
,
group
.
id
)
expect
(
project
.
actual_size_limit
).
to
eq
(
100
.
megabytes
)
expect
(
project
.
actual_size_limit
).
to
eq
(
100
)
end
end
it
'returns the value set locally'
do
it
'returns the value set locally'
do
project
.
update_attribute
(
:repository_size_limit
,
75
)
project
.
update_attribute
(
:repository_size_limit
,
75
)
expect
(
project
.
actual_size_limit
).
to
eq
(
75
.
megabytes
)
expect
(
project
.
actual_size_limit
).
to
eq
(
75
)
end
end
end
end
...
...
spec/services/application_settings/update_service_spec.rb
0 → 100644
View file @
574b9c67
require
'spec_helper'
describe
ApplicationSettings
::
UpdateService
,
services:
true
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:setting
)
{
ApplicationSetting
.
create_from_defaults
}
let
(
:service
)
{
described_class
.
new
(
setting
,
user
,
opts
)
}
describe
'#execute'
do
context
'common params'
do
let
(
:opts
)
{
{
home_page_url:
'http://foo.bar'
}
}
it
'properly updates settings with given params'
do
service
.
execute
expect
(
setting
.
home_page_url
).
to
eql
(
opts
[
:home_page_url
])
end
end
context
'with valid params'
do
let
(
:opts
)
{
{
repository_size_limit:
'100'
}
}
it
'returns success params'
do
result
=
service
.
execute
expect
(
result
).
to
eql
(
status: :success
)
end
end
context
'with invalid params'
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
)
end
end
context
'repository_size_limit assignment as Bytes'
do
let
(
:service
)
{
described_class
.
new
(
setting
,
user
,
opts
)
}
context
'when param present'
do
let
(
:opts
)
{
{
repository_size_limit:
'100'
}
}
it
'converts from MB to Bytes'
do
service
.
execute
expect
(
setting
.
reload
.
repository_size_limit
).
to
eql
(
100
*
1024
*
1024
)
end
end
context
'when param not present'
do
let
(
:opts
)
{
{
repository_size_limit:
''
}
}
it
'does not update due to invalidity'
do
service
.
execute
expect
(
setting
.
reload
.
repository_size_limit
).
to
be_zero
end
it
'assign nil value'
do
service
.
execute
expect
(
setting
.
repository_size_limit
).
to
be_nil
end
end
end
end
end
spec/services/groups/create_service_spec.rb
View file @
574b9c67
...
@@ -40,4 +40,29 @@ describe Groups::CreateService, '#execute', services: true do
...
@@ -40,4 +40,29 @@ describe Groups::CreateService, '#execute', services: true do
end
end
end
end
end
end
context
'repository_size_limit assignment as Bytes'
do
let
(
:admin_user
)
{
create
(
:user
,
admin:
true
)
}
let
(
:service
)
{
described_class
.
new
(
admin_user
,
group_params
.
merge
(
opts
))
}
context
'when param present'
do
let
(
:opts
)
{
{
repository_size_limit:
'100'
}
}
it
'assign repository_size_limit as Bytes'
do
group
=
service
.
execute
expect
(
group
.
repository_size_limit
).
to
eql
(
100
*
1024
*
1024
)
end
end
context
'when param not present'
do
let
(
:opts
)
{
{
repository_size_limit:
''
}
}
it
'assign nil value'
do
group
=
service
.
execute
expect
(
group
.
repository_size_limit
).
to
be_nil
end
end
end
end
end
spec/services/groups/update_service_spec.rb
View file @
574b9c67
...
@@ -38,6 +38,31 @@ describe Groups::UpdateService, services: true do
...
@@ -38,6 +38,31 @@ describe Groups::UpdateService, services: true do
end
end
end
end
context
'repository_size_limit assignment as Bytes'
do
let
(
:group
)
{
create
(
:group
,
:public
,
repository_size_limit:
0
)
}
let
(
:service
)
{
described_class
.
new
(
group
,
user
,
opts
)
}
context
'when param present'
do
let
(
:opts
)
{
{
repository_size_limit:
'100'
}
}
it
'converts from MB to Bytes'
do
service
.
execute
expect
(
group
.
reload
.
repository_size_limit
).
to
eql
(
100
*
1024
*
1024
)
end
end
context
'when param not present'
do
let
(
:opts
)
{
{
repository_size_limit:
''
}
}
it
'assign nil value'
do
service
.
execute
expect
(
group
.
reload
.
repository_size_limit
).
to
be_nil
end
end
end
context
"unauthorized visibility_level validation"
do
context
"unauthorized visibility_level validation"
do
let!
(
:service
)
{
described_class
.
new
(
internal_group
,
user
,
visibility_level:
99
)
}
let!
(
:service
)
{
described_class
.
new
(
internal_group
,
user
,
visibility_level:
99
)
}
before
do
before
do
...
...
spec/services/projects/create_service_spec.rb
View file @
574b9c67
...
@@ -98,6 +98,30 @@ describe Projects::CreateService, '#execute', services: true do
...
@@ -98,6 +98,30 @@ describe Projects::CreateService, '#execute', services: true do
end
end
end
end
context
'repository_size_limit assignment as Bytes'
do
let
(
:admin_user
)
{
create
(
:user
,
admin:
true
)
}
context
'when param present'
do
let
(
:opts
)
{
{
repository_size_limit:
'100'
}
}
it
'assign repository_size_limit as Bytes'
do
project
=
create_project
(
admin_user
,
opts
)
expect
(
project
.
repository_size_limit
).
to
eql
(
100
*
1024
*
1024
)
end
end
context
'when param not present'
do
let
(
:opts
)
{
{
repository_size_limit:
''
}
}
it
'assign nil value'
do
project
=
create_project
(
admin_user
,
opts
)
expect
(
project
.
repository_size_limit
).
to
be_nil
end
end
end
context
'restricted visibility level'
do
context
'restricted visibility level'
do
before
do
before
do
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
])
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
])
...
...
spec/services/projects/update_service_spec.rb
View file @
574b9c67
...
@@ -127,6 +127,31 @@ describe Projects::UpdateService, services: true do
...
@@ -127,6 +127,31 @@ describe Projects::UpdateService, services: true do
end
end
end
end
context
'repository_size_limit assignment as Bytes'
do
let
(
:admin_user
)
{
create
(
:user
,
admin:
true
)
}
let
(
:project
)
{
create
(
:empty_project
,
repository_size_limit:
0
)
}
context
'when param present'
do
let
(
:opts
)
{
{
repository_size_limit:
'100'
}
}
it
'converts from MB to Bytes'
do
update_project
(
project
,
admin_user
,
opts
)
expect
(
project
.
reload
.
repository_size_limit
).
to
eql
(
100
*
1024
*
1024
)
end
end
context
'when param not present'
do
let
(
:opts
)
{
{
repository_size_limit:
''
}
}
it
'assign nil value'
do
update_project
(
project
,
admin_user
,
opts
)
expect
(
project
.
reload
.
repository_size_limit
).
to
be_nil
end
end
end
it
'returns an error result when record cannot be updated'
do
it
'returns an error result when record cannot be updated'
do
result
=
update_project
(
project
,
admin
,
{
name:
'foo&bar'
})
result
=
update_project
(
project
,
admin
,
{
name:
'foo&bar'
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment