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
40f2bc10
Commit
40f2bc10
authored
Mar 11, 2021
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize Deploy Key Presenter
This commit optimizes the deploy key presenter.
parent
3dcc435c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
17 deletions
+117
-17
app/presenters/projects/settings/deploy_keys_presenter.rb
app/presenters/projects/settings/deploy_keys_presenter.rb
+54
-15
config/feature_flags/development/optimize_deploy_keys_presenter.yml
...ture_flags/development/optimize_deploy_keys_presenter.yml
+8
-0
spec/presenters/projects/settings/deploy_keys_presenter_spec.rb
...resenters/projects/settings/deploy_keys_presenter_spec.rb
+55
-2
No files found.
app/presenters/projects/settings/deploy_keys_presenter.rb
View file @
40f2bc10
...
...
@@ -14,12 +14,20 @@ module Projects
@key
||=
DeployKey
.
new
.
tap
{
|
dk
|
dk
.
deploy_keys_projects
.
build
}
end
# It includes:
# - The deploy keys enabled in the project.
def
enabled_keys
strong_memoize
(
:enabled_keys
)
do
project
.
deploy_keys
.
with_projects
end
end
# NOTE: This method is redundant. Use `available_project_keys` and `available_public_keys` instead.
# It includes:
# - Enabled deploy keys in projects that can be accessed by the user.
# - Instance-level public deploy keys.
# It excludes:
# - The deploy keys enabled in the project.
def
available_keys
strong_memoize
(
:available_keys
)
do
current_user
...
...
@@ -29,22 +37,46 @@ module Projects
end
end
# It includes:
# - Enabled deploy keys in projects that can be accessed by the user.
# It excludes:
# - The deploy keys enabled in the project
def
available_project_keys
strong_memoize
(
:available_project_keys
)
do
current_user
.
project_deploy_keys
.
id_not_in
(
enabled_keys
.
select
(
:id
))
.
with_projects
if
Feature
.
enabled?
(
:optimize_deploy_keys_presenter
,
project
,
default_enabled: :yaml
)
strong_memoize
(
:available_project_keys
)
do
current_user
.
project_deploy_keys
.
with_projects
-
enabled_keys
end
else
strong_memoize
(
:legacy_available_project_keys
)
do
current_user
.
project_deploy_keys
.
id_not_in
(
enabled_keys
.
select
(
:id
))
.
with_projects
end
end
end
# It includes:
# - Instance-level public deploy keys.
# It excludes:
# - The deploy keys enabled in the project.
def
available_public_keys
strong_memoize
(
:available_public_keys
)
do
DeployKey
.
are_public
.
id_not_in
(
enabled_keys
.
select
(
:id
))
.
id_not_in
(
available_project_keys
.
select
(
:id
))
.
with_projects
if
Feature
.
enabled?
(
:optimize_deploy_keys_presenter
,
project
,
default_enabled: :yaml
)
strong_memoize
(
:available_public_keys
)
do
DeployKey
.
are_public
.
with_projects
-
enabled_keys
end
else
strong_memoize
(
:legacy_available_public_keys
)
do
# This also excludes "Enabled deploy keys in projects that can be accessed by the user".
# However, this means we are filtering out a public key that enabled
# in the other project, which should be also available for this project.
# We should expose the public keys that has not been enabled on the project yet.
DeployKey
.
are_public
.
id_not_in
(
enabled_keys
.
select
(
:id
))
.
id_not_in
(
available_project_keys
.
select
(
:id
))
.
with_projects
end
end
end
...
...
@@ -78,10 +110,17 @@ module Projects
# rubocop: disable CodeReuse/ActiveRecord
def
user_readable_project_ids
project_ids
=
(
available_keys
+
available_project_keys
+
available_public_keys
)
.
flat_map
{
|
deploy_key
|
deploy_key
.
deploy_keys_projects
.
map
(
&
:project_id
)
}
.
compact
.
uniq
project_ids
=
if
Feature
.
enabled?
(
:optimize_deploy_keys_presenter
,
project
,
default_enabled: :yaml
)
(
available_project_keys
+
available_public_keys
)
.
flat_map
{
|
deploy_key
|
deploy_key
.
deploy_keys_projects
.
map
(
&
:project_id
)
}
.
compact
.
uniq
else
(
available_keys
+
available_project_keys
+
available_public_keys
)
.
flat_map
{
|
deploy_key
|
deploy_key
.
deploy_keys_projects
.
map
(
&
:project_id
)
}
.
compact
.
uniq
end
current_user
.
authorized_projects
(
Gitlab
::
Access
::
GUEST
).
id_in
(
project_ids
).
pluck
(
:id
)
end
...
...
config/feature_flags/development/optimize_deploy_keys_presenter.yml
0 → 100644
View file @
40f2bc10
---
name
:
optimize_deploy_keys_presenter
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56305/diffs
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/324143
milestone
:
'
13.10'
type
:
development
group
:
group::release
default_enabled
:
false
spec/presenters/projects/settings/deploy_keys_presenter_spec.rb
View file @
40f2bc10
...
...
@@ -3,17 +3,70 @@
require
'spec_helper'
RSpec
.
describe
Projects
::
Settings
::
DeployKeysPresenter
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
,
refind:
true
)
{
create
(
:project
)
}
let_it_be
(
:other_project
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
subject
(
:presenter
)
do
described_class
.
new
(
project
,
current_user:
user
)
end
before_all
do
project
.
add_maintainer
(
user
)
other_project
.
add_maintainer
(
user
)
end
it
'inherits from Gitlab::View::Presenter::Simple'
do
expect
(
described_class
.
superclass
).
to
eq
(
Gitlab
::
View
::
Presenter
::
Simple
)
end
describe
'deploy key groups'
do
let_it_be
(
:deploy_key
)
{
create
(
:deploy_key
,
projects:
[
project
])
}
let_it_be
(
:other_deploy_key
)
{
create
(
:deploy_key
,
projects:
[
other_project
])
}
let_it_be
(
:public_deploy_key
)
{
create
(
:deploy_key
,
public:
true
)
}
let_it_be
(
:unrelated_project
)
{
create
(
:project
,
:private
)
}
let_it_be
(
:unrelated_deploy_key
)
{
create
(
:deploy_key
,
projects:
[
unrelated_project
])
}
shared_examples_for
'correct behavior'
do
context
'with enabled keys'
do
it
'returns correct deploy keys'
do
expect
(
presenter
.
enabled_keys
).
to
eq
([
deploy_key
])
expect
(
presenter
.
enabled_keys_size
).
to
eq
(
1
)
end
end
context
'with available keys'
do
it
'returns correct deploy keys'
do
expect
(
presenter
.
available_keys
).
to
eq
([
other_deploy_key
,
public_deploy_key
])
end
end
context
'with available project keys'
do
it
'returns correct deploy keys'
do
expect
(
presenter
.
available_project_keys
).
to
eq
([
other_deploy_key
])
expect
(
presenter
.
available_project_keys_size
).
to
eq
(
1
)
end
end
context
'with available public keys'
do
it
'returns correct deploy keys'
do
expect
(
presenter
.
available_public_keys
).
to
eq
([
public_deploy_key
])
expect
(
presenter
.
available_public_keys_size
).
to
eq
(
1
)
end
end
end
it_behaves_like
'correct behavior'
context
'when optimize_deploy_keys_presenter feature flag is disabled'
do
before
do
stub_feature_flags
(
optimize_deploy_keys_presenter:
false
)
end
it_behaves_like
'correct behavior'
end
end
describe
'#enabled_keys'
do
let!
(
:deploy_key
)
{
create
(
:deploy_key
,
public:
true
)
}
...
...
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