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
00ab8d72
Commit
00ab8d72
authored
Sep 03, 2021
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow user owns_runner? callsite
Tidies up policy to not have AR methods, adds specs
parent
c79b6851
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
3 deletions
+60
-3
app/models/user.rb
app/models/user.rb
+8
-0
app/policies/ci/runner_policy.rb
app/policies/ci/runner_policy.rb
+3
-3
spec/models/user_spec.rb
spec/models/user_spec.rb
+49
-0
No files found.
app/models/user.rb
View file @
00ab8d72
...
...
@@ -1615,6 +1615,8 @@ class User < ApplicationRecord
true
end
# TODO Please check all callers and remove allow_cross_joins_across_databases,
# when https://gitlab.com/gitlab-org/gitlab/-/issues/336436 is done.
def
ci_owned_runners
@ci_owned_runners
||=
begin
project_runners
=
Ci
::
RunnerProject
...
...
@@ -1631,6 +1633,12 @@ class User < ApplicationRecord
end
end
def
owns_runner?
(
runner
)
::
Gitlab
::
Database
.
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/336436'
)
do
ci_owned_runners
.
exists?
(
runner
.
id
)
end
end
def
notification_email_for
(
notification_group
)
# Return group-specific email address if present, otherwise return global notification email address
notification_group
&
.
notification_email_for
(
self
)
||
notification_email
...
...
app/policies/ci/runner_policy.rb
View file @
00ab8d72
...
...
@@ -5,9 +5,9 @@ module Ci
with_options
scope: :subject
,
score:
0
condition
(
:locked
,
scope: :subject
)
{
@subject
.
locked?
}
# rubocop: disable CodeReuse/ActiveRecord
condition
(
:owned_runner
)
{
@user
.
ci_owned_runners
.
exists?
(
@subject
.
id
)
}
# rubocop: enable CodeReuse/ActiveRecor
d
condition
(
:owned_runner
)
do
@user
.
owns_runner?
(
@subject
)
en
d
rule
{
anonymous
}.
prevent_all
...
...
spec/models/user_spec.rb
View file @
00ab8d72
...
...
@@ -3635,6 +3635,11 @@ RSpec.describe User do
it
'loads all the runners in the tree of groups'
do
expect
(
user
.
ci_owned_runners
).
to
contain_exactly
(
runner
,
group_runner
)
end
it
'returns true for owns_runner?'
do
expect
(
user
.
owns_runner?
(
runner
)).
to
eq
(
true
)
expect
(
user
.
owns_runner?
(
group_runner
)).
to
eq
(
true
)
end
end
end
...
...
@@ -3647,6 +3652,10 @@ RSpec.describe User do
it
'loads the runners in the group'
do
expect
(
user
.
ci_owned_runners
).
to
contain_exactly
(
group_runner
)
end
it
'returns true for owns_runner?'
do
expect
(
user
.
owns_runner?
(
group_runner
)).
to
eq
(
true
)
end
end
end
...
...
@@ -3655,6 +3664,10 @@ RSpec.describe User do
it
'loads the runner belonging to the project'
do
expect
(
user
.
ci_owned_runners
).
to
contain_exactly
(
runner
)
end
it
'returns true for owns_runner?'
do
expect
(
user
.
owns_runner?
(
runner
)).
to
eq
(
true
)
end
end
end
...
...
@@ -3667,6 +3680,10 @@ RSpec.describe User do
it
'loads the runners of the project'
do
expect
(
user
.
ci_owned_runners
).
to
contain_exactly
(
project_runner
)
end
it
'returns true for owns_runner?'
do
expect
(
user
.
owns_runner?
(
project_runner
)).
to
eq
(
true
)
end
end
context
'when the user is a developer'
do
...
...
@@ -3677,6 +3694,10 @@ RSpec.describe User do
it
'does not load any runner'
do
expect
(
user
.
ci_owned_runners
).
to
be_empty
end
it
'returns false for owns_runner?'
do
expect
(
user
.
owns_runner?
(
project_runner
)).
to
eq
(
false
)
end
end
context
'when the user is a reporter'
do
...
...
@@ -3687,6 +3708,10 @@ RSpec.describe User do
it
'does not load any runner'
do
expect
(
user
.
ci_owned_runners
).
to
be_empty
end
it
'returns false for owns_runner?'
do
expect
(
user
.
owns_runner?
(
project_runner
)).
to
eq
(
false
)
end
end
context
'when the user is a guest'
do
...
...
@@ -3697,6 +3722,10 @@ RSpec.describe User do
it
'does not load any runner'
do
expect
(
user
.
ci_owned_runners
).
to
be_empty
end
it
'returns false for owns_runner?'
do
expect
(
user
.
owns_runner?
(
project_runner
)).
to
eq
(
false
)
end
end
end
...
...
@@ -3709,6 +3738,10 @@ RSpec.describe User do
it
'does not load the runners of the group'
do
expect
(
user
.
ci_owned_runners
).
to
be_empty
end
it
'returns false for owns_runner?'
do
expect
(
user
.
owns_runner?
(
runner
)).
to
eq
(
false
)
end
end
context
'when the user is a developer'
do
...
...
@@ -3719,6 +3752,10 @@ RSpec.describe User do
it
'does not load any runner'
do
expect
(
user
.
ci_owned_runners
).
to
be_empty
end
it
'returns false for owns_runner?'
do
expect
(
user
.
owns_runner?
(
runner
)).
to
eq
(
false
)
end
end
context
'when the user is a reporter'
do
...
...
@@ -3729,6 +3766,10 @@ RSpec.describe User do
it
'does not load any runner'
do
expect
(
user
.
ci_owned_runners
).
to
be_empty
end
it
'returns false for owns_runner?'
do
expect
(
user
.
owns_runner?
(
runner
)).
to
eq
(
false
)
end
end
context
'when the user is a guest'
do
...
...
@@ -3739,6 +3780,10 @@ RSpec.describe User do
it
'does not load any runner'
do
expect
(
user
.
ci_owned_runners
).
to
be_empty
end
it
'returns false for owns_runner?'
do
expect
(
user
.
owns_runner?
(
runner
)).
to
eq
(
false
)
end
end
end
...
...
@@ -3746,6 +3791,10 @@ RSpec.describe User do
it
'does not load any runner'
do
expect
(
user
.
ci_owned_runners
).
to
be_empty
end
it
'returns false for owns_runner?'
do
expect
(
user
.
owns_runner?
(
create
(
:ci_runner
))).
to
eq
(
false
)
end
end
context
'with runner in a personal project'
do
...
...
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