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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
c585004b
Commit
c585004b
authored
Dec 19, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restrict projects ci controller to project runners
parent
9bed8de9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
3 deletions
+39
-3
app/controllers/projects/settings/ci_cd_controller.rb
app/controllers/projects/settings/ci_cd_controller.rb
+7
-2
app/models/ci/runner.rb
app/models/ci/runner.rb
+6
-1
spec/controllers/projects/settings/ci_cd_controller_spec.rb
spec/controllers/projects/settings/ci_cd_controller_spec.rb
+11
-0
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+15
-0
No files found.
app/controllers/projects/settings/ci_cd_controller.rb
View file @
c585004b
...
@@ -68,8 +68,13 @@ module Projects
...
@@ -68,8 +68,13 @@ module Projects
def
define_runners_variables
def
define_runners_variables
@project_runners
=
@project
.
runners
.
ordered
@project_runners
=
@project
.
runners
.
ordered
@assignable_runners
=
current_user
.
ci_authorized_runners
@assignable_runners
=
current_user
.
assignable_for
(
project
).
ordered
.
page
(
params
[
:page
]).
per
(
20
)
.
ci_authorized_runners
.
assignable_for
(
project
)
.
ordered
.
belonging_to_any_project
.
page
(
params
[
:page
]).
per
(
20
)
@shared_runners
=
::
Ci
::
Runner
.
shared
.
active
@shared_runners
=
::
Ci
::
Runner
.
shared
.
active
@shared_runners_count
=
@shared_runners
.
count
(
:all
)
@shared_runners_count
=
@shared_runners
.
count
(
:all
)
...
...
app/models/ci/runner.rb
View file @
c585004b
...
@@ -27,9 +27,13 @@ module Ci
...
@@ -27,9 +27,13 @@ module Ci
scope
:paused
,
->
{
where
(
active:
false
)
}
scope
:paused
,
->
{
where
(
active:
false
)
}
scope
:online
,
->
{
where
(
'contacted_at > ?'
,
contact_time_deadline
)
}
scope
:online
,
->
{
where
(
'contacted_at > ?'
,
contact_time_deadline
)
}
scope
:ordered
,
->
{
order
(
id: :desc
)
}
scope
:ordered
,
->
{
order
(
id: :desc
)
}
scope
:belonging_to_project
,
->
(
project_id
)
{
scope
:belonging_to_project
,
->
(
project_id
)
{
joins
(
:runner_projects
).
where
(
ci_runner_projects:
{
project_id:
project_id
})
joins
(
:runner_projects
).
where
(
ci_runner_projects:
{
project_id:
project_id
})
}
}
scope
:belonging_to_any_project
,
->
{
joins
(
:runner_projects
)
}
scope
:belonging_to_group
,
->
(
project_id
)
{
scope
:belonging_to_group
,
->
(
project_id
)
{
project_groups
=
::
Group
.
joins
(
:projects
).
where
(
projects:
{
id:
project_id
})
project_groups
=
::
Group
.
joins
(
:projects
).
where
(
projects:
{
id:
project_id
})
hierarchy_groups
=
Gitlab
::
GroupHierarchy
.
new
(
project_groups
).
base_and_ancestors
hierarchy_groups
=
Gitlab
::
GroupHierarchy
.
new
(
project_groups
).
base_and_ancestors
...
@@ -46,7 +50,8 @@ module Ci
...
@@ -46,7 +50,8 @@ module Ci
# FIXME: That `to_sql` is needed to workaround a weird Rails bug.
# FIXME: That `to_sql` is needed to workaround a weird Rails bug.
# Without that, placeholders would miss one and couldn't match.
# Without that, placeholders would miss one and couldn't match.
where
(
locked:
false
)
where
(
locked:
false
)
.
where
.
not
(
"id IN (
#{
project
.
runners
.
select
(
:id
).
to_sql
}
)"
).
specific
.
where
.
not
(
"ci_runners.id IN (
#{
project
.
runners
.
select
(
:id
).
to_sql
}
)"
)
.
specific
end
end
validate
:tag_constraints
validate
:tag_constraints
...
...
spec/controllers/projects/settings/ci_cd_controller_spec.rb
View file @
c585004b
...
@@ -17,6 +17,17 @@ describe Projects::Settings::CiCdController do
...
@@ -17,6 +17,17 @@ describe Projects::Settings::CiCdController do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
render_template
(
:show
)
expect
(
response
).
to
render_template
(
:show
)
end
end
it
'sets assignable project runners'
do
group
=
create
(
:group
,
runners:
[
create
(
:ci_runner
)],
parent:
create
(
:group
))
group
.
add_master
(
user
)
project_runner
=
create
(
:ci_runner
,
projects:
[
create
(
:project
,
group:
group
)])
create
(
:ci_runner
,
:shared
)
get
:show
,
namespace_id:
project
.
namespace
,
project_id:
project
expect
(
assigns
(
:assignable_runners
)).
to
eq
[
project_runner
]
end
end
end
describe
'#reset_cache'
do
describe
'#reset_cache'
do
...
...
spec/models/ci/runner_spec.rb
View file @
c585004b
...
@@ -136,6 +136,21 @@ describe Ci::Runner do
...
@@ -136,6 +136,21 @@ describe Ci::Runner do
end
end
end
end
describe
'.belonging_to_any_project'
do
it
'returns the specific project runner'
do
# project
project_project
=
create
:project
project_runner
=
create
:ci_runner
,
:specific
,
projects:
[
project_project
]
# group
group
=
create
:group
create
:project
,
group:
group
create
:ci_runner
,
:specific
,
groups:
[
group
]
expect
(
described_class
.
belonging_to_any_project
).
to
eq
[
project_runner
]
end
end
describe
'.belonging_to_group'
do
describe
'.belonging_to_group'
do
it
'returns the specific group runner'
do
it
'returns the specific group runner'
do
# own
# own
...
...
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