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
59216076
Commit
59216076
authored
Dec 20, 2017
by
Matija Čupić
Committed by
Phil Hughes
Dec 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Reset Pipeline Minutes / Pipeline Quota in the Admin UI"
parent
51cd05e9
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
259 additions
and
1 deletion
+259
-1
app/views/admin/groups/_form.html.haml
app/views/admin/groups/_form.html.haml
+4
-0
changelogs/unreleased-ee/3973-reset-pipeline-minutes-pipeline-quota-in-the-admin-ui.yml
...reset-pipeline-minutes-pipeline-quota-in-the-admin-ui.yml
+5
-0
config/routes/admin.rb
config/routes/admin.rb
+2
-0
ee/app/controllers/ee/admin/groups_controller.rb
ee/app/controllers/ee/admin/groups_controller.rb
+10
-0
ee/app/controllers/ee/admin/users_controller.rb
ee/app/controllers/ee/admin/users_controller.rb
+10
-0
ee/app/services/clear_namespace_shared_runners_minutes_service.rb
...ervices/clear_namespace_shared_runners_minutes_service.rb
+12
-0
ee/app/views/admin/users/_limits.html.haml
ee/app/views/admin/users/_limits.html.haml
+4
-1
ee/app/views/namespaces/_shared_runners_minutes_setting_reset.html.haml
...amespaces/_shared_runners_minutes_setting_reset.html.haml
+6
-0
spec/ee/spec/controllers/ee/admin/groups_controller_spec.rb
spec/ee/spec/controllers/ee/admin/groups_controller_spec.rb
+41
-0
spec/ee/spec/controllers/ee/admin/users_controller_spec.rb
spec/ee/spec/controllers/ee/admin/users_controller_spec.rb
+41
-0
spec/ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb
.../spec/features/admin/admin_reset_pipeline_minutes_spec.rb
+89
-0
spec/ee/spec/services/clear_namespace_shared_runners_minutes_service_spec.rb
...es/clear_namespace_shared_runners_minutes_service_spec.rb
+35
-0
No files found.
app/views/admin/groups/_form.html.haml
View file @
59216076
...
...
@@ -22,6 +22,10 @@
-
if
@group
.
shared_runner_minutes_supported?
=
render
'namespaces/shared_runners_minutes_setting'
,
f:
f
-
unless
@group
.
new_record?
.form-group
.col-sm-offset-2.col-sm-10
=
render
'namespaces/shared_runners_minutes_setting_reset'
,
link_reset_minutes:
admin_group_reset_runners_minutes_path
(
@group
)
-
if
@group
.
new_record?
.form-group
...
...
changelogs/unreleased-ee/3973-reset-pipeline-minutes-pipeline-quota-in-the-admin-ui.yml
0 → 100644
View file @
59216076
---
title
:
Add reset pipeline minutes button to admin overview of groups and users
merge_request
:
3656
author
:
type
:
added
config/routes/admin.rb
View file @
59216076
...
...
@@ -16,6 +16,7 @@ namespace :admin do
put
:unlock
put
:confirm
post
:impersonate
post
:reset_runners_minutes
patch
:disable_two_factor
delete
'remove/:email_id'
,
action:
'remove_email'
,
as:
'remove_email'
end
...
...
@@ -44,6 +45,7 @@ namespace :admin do
scope
(
as: :group
)
do
put
:members_update
post
:reset_runners_minutes
get
:edit
,
action: :edit
get
'/'
,
action: :show
patch
'/'
,
action: :update
...
...
ee/app/controllers/ee/admin/groups_controller.rb
View file @
59216076
module
EE
module
Admin
module
GroupsController
def
reset_runners_minutes
group
if
ClearNamespaceSharedRunnersMinutesService
.
new
(
@group
).
execute
redirect_to
[
:admin
,
@group
],
notice:
'Group pipeline minutes were successfully reset.'
else
flash
.
now
[
:error
]
=
'There was an error resetting group pipeline minutes.'
render
"edit"
end
end
private
def
allowed_group_params
...
...
ee/app/controllers/ee/admin/users_controller.rb
View file @
59216076
module
EE
module
Admin
module
UsersController
def
reset_runners_minutes
user
if
ClearNamespaceSharedRunnersMinutesService
.
new
(
@user
.
namespace
).
execute
redirect_to
[
:admin
,
@user
],
notice:
'User pipeline minutes were successfully reset.'
else
flash
.
now
[
:error
]
=
'There was an error resetting user pipeline minutes.'
render
"edit"
end
end
private
def
allowed_user_params
...
...
ee/app/services/clear_namespace_shared_runners_minutes_service.rb
0 → 100644
View file @
59216076
class
ClearNamespaceSharedRunnersMinutesService
<
BaseService
def
initialize
(
namespace
)
@namespace
=
namespace
end
def
execute
NamespaceStatistics
.
where
(
namespace:
@namespace
).
update_all
(
shared_runners_seconds:
0
,
shared_runners_seconds_last_reset:
Time
.
now
)
end
end
ee/app/views/admin/users/_limits.html.haml
View file @
59216076
...
...
@@ -2,4 +2,7 @@
=
namespace_form
.
hidden_field
:id
%fieldset
%legend
Limits
=
render
"namespaces/shared_runners_minutes_setting"
,
f:
namespace_form
=
render
'namespaces/shared_runners_minutes_setting'
,
f:
namespace_form
.form-group.append-bottom-0
.col-sm-offset-2.col-sm-10
=
render
'namespaces/shared_runners_minutes_setting_reset'
,
link_reset_minutes:
reset_runners_minutes_admin_user_path
(
@user
),
css_class:
'append-bottom-0'
ee/app/views/namespaces/_shared_runners_minutes_setting_reset.html.haml
0 → 100644
View file @
59216076
-
css_class
=
local_assigns
.
fetch
(
:css_class
,
''
)
.bs-callout.clearfix.prepend-top-0
{
class:
css_class
}
%h4
=
s_
(
"SharedRunnersMinutesSettings|Reset used pipeline minutes"
)
%p
=
s_
(
"SharedRunnersMinutesSettings|By resetting the pipeline minutes for this namespace, the currently used minutes will be set to zero."
)
=
link_to
s_
(
"SharedRunnersMinutesSettings|Reset pipeline minutes"
),
link_reset_minutes
,
method: :post
,
class:
"btn btn-default"
spec/ee/spec/controllers/ee/admin/groups_controller_spec.rb
0 → 100644
View file @
59216076
require
'spec_helper'
describe
Admin
::
GroupsController
do
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:group
)
{
create
(
:group
)
}
before
do
sign_in
(
admin
)
end
describe
'POST #reset_runner_minutes'
do
subject
{
post
:reset_runners_minutes
,
id:
group
}
before
do
allow_any_instance_of
(
ClearNamespaceSharedRunnersMinutesService
)
.
to
receive
(
:execute
).
and_return
(
clear_runners_minutes_service_result
)
end
context
'when the reset is successful'
do
let
(
:clear_runners_minutes_service_result
)
{
true
}
it
'redirects to group path'
do
subject
expect
(
response
).
to
redirect_to
(
admin_group_path
(
group
))
expect
(
response
).
to
set_flash
[
:notice
]
end
end
context
'when the reset is not successful'
do
let
(
:clear_runners_minutes_service_result
)
{
false
}
it
'redirects back to group edit page'
do
subject
expect
(
response
).
to
render_template
(
:edit
)
expect
(
response
).
to
set_flash
.
now
[
:error
]
end
end
end
end
spec/ee/spec/controllers/ee/admin/users_controller_spec.rb
0 → 100644
View file @
59216076
require
'spec_helper'
describe
Admin
::
UsersController
do
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
admin
)
end
describe
'POST #reset_runner_minutes'
do
subject
{
post
:reset_runners_minutes
,
id:
user
}
before
do
allow_any_instance_of
(
ClearNamespaceSharedRunnersMinutesService
)
.
to
receive
(
:execute
).
and_return
(
clear_runners_minutes_service_result
)
end
context
'when the reset is successful'
do
let
(
:clear_runners_minutes_service_result
)
{
true
}
it
'redirects to group path'
do
subject
expect
(
response
).
to
redirect_to
(
admin_user_path
(
user
))
expect
(
response
).
to
set_flash
[
:notice
]
end
end
context
'when the reset is not successful'
do
let
(
:clear_runners_minutes_service_result
)
{
false
}
it
'redirects back to group edit page'
do
subject
expect
(
response
).
to
render_template
(
:edit
)
expect
(
response
).
to
set_flash
.
now
[
:error
]
end
end
end
end
spec/ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb
0 → 100644
View file @
59216076
require
'spec_helper'
describe
'Reset namespace pipeline minutes'
do
let
(
:admin
)
{
create
(
:admin
)
}
before
do
sign_in
(
admin
)
end
shared_examples
'resetting pipeline minutes'
do
context
'when namespace has namespace statistics'
do
before
do
namespace
.
create_namespace_statistics
(
shared_runners_seconds:
100
)
end
it
'resets pipeline minutes'
do
click_link
'Reset pipeline minutes'
expect
(
page
).
to
have_selector
(
'.flash-notice'
)
expect
(
current_path
).
to
include
(
namespace
.
name
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_seconds
).
to
eq
(
0
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_seconds_last_reset
).
to
be_like_time
(
Time
.
now
)
end
end
end
shared_examples
'rendering error'
do
context
'when resetting pipeline minutes fails'
do
before
do
allow_any_instance_of
(
ClearNamespaceSharedRunnersMinutesService
).
to
receive
(
:execute
).
and_return
(
false
)
end
it
'renders edit page with an error'
do
click_link
'Reset pipeline minutes'
expect
(
current_path
).
to
include
(
namespace
.
name
)
expect
(
page
).
to
have_selector
(
'.flash-error'
)
end
end
end
describe
'for user namespace'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:namespace
)
{
user
.
namespace
}
before
do
visit
admin_user_path
(
user
)
click_link
'Edit'
end
it
'reset pipeline minutes button is visible'
do
expect
(
page
).
to
have_link
(
'Reset pipeline minutes'
,
href:
reset_runners_minutes_admin_user_path
(
user
))
end
include_examples
"resetting pipeline minutes"
include_examples
"rendering error"
end
describe
'when creating a new group'
do
before
do
visit
admin_groups_path
page
.
within
'#content-body'
do
click_link
"New group"
end
end
it
'does not display reset pipeline minutes callout'
do
expect
(
page
).
not_to
have_link
(
'Reset pipeline minutes'
)
end
end
describe
'for group namespace'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:namespace
)
{
group
}
before
do
visit
admin_group_path
(
group
)
click_link
'Edit'
end
it
'reset pipeline minutes button is visible'
do
expect
(
page
).
to
have_link
(
'Reset pipeline minutes'
,
href:
admin_group_reset_runners_minutes_path
(
group
))
end
include_examples
"resetting pipeline minutes"
include_examples
"rendering error"
end
end
spec/ee/spec/services/clear_namespace_shared_runners_minutes_service_spec.rb
0 → 100644
View file @
59216076
require
'spec_helper'
describe
ClearNamespaceSharedRunnersMinutesService
do
describe
'#execute'
do
subject
{
described_class
.
new
(
namespace
).
execute
}
context
'when project has namespace_statistics'
do
let
(
:namespace
)
{
create
(
:namespace
,
:with_used_build_minutes_limit
)
}
it
'clears counters'
do
subject
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_seconds
).
to
eq
(
0
)
end
it
'resets timer'
do
subject
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_seconds_last_reset
).
to
be_like_time
(
Time
.
now
)
end
it
'successfully clears minutes'
do
expect
(
subject
).
to
be_truthy
end
end
context
'when project does not have namespace_statistics'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
it
'successfully clears minutes'
do
expect
(
subject
).
to
be_truthy
end
end
end
end
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