Commit 24836acd authored by Max Woolf's avatar Max Woolf

Backend reviewer suggestions applied

parent 6d982667
......@@ -17,6 +17,7 @@ class PersonalAccessTokensFinder
tokens = by_users(tokens)
tokens = by_impersonation(tokens)
tokens = by_state(tokens)
tokens = by_owner_type(tokens)
sort(tokens)
end
......@@ -32,6 +33,15 @@ class PersonalAccessTokensFinder
tokens
end
def by_owner_type(tokens)
case @params[:owner_type]
when 'human'
tokens.owner_is_human
else
tokens
end
end
def by_user(tokens)
return tokens unless @params[:user]
......
......@@ -49,7 +49,7 @@ module CredentialsInventoryActions
def filter_credentials
if show_personal_access_tokens?
::PersonalAccessTokensFinder.new({ users: users, impersonation: false, sort: 'id_desc' }).execute.owner_is_human
::PersonalAccessTokensFinder.new({ users: users, impersonation: false, sort: 'id_desc', owner_type: 'human' }).execute
elsif show_ssh_keys?
::KeysFinder.new({ users: users, key_type: 'ssh' }).execute
elsif show_project_access_tokens?
......
......@@ -17,6 +17,9 @@ RSpec.describe PersonalAccessTokensFinder do
let!(:active_impersonation_token) { create(:personal_access_token, :impersonation, user: user) }
let!(:expired_impersonation_token) { create(:personal_access_token, :expired, :impersonation, user: user) }
let!(:revoked_impersonation_token) { create(:personal_access_token, :revoked, :impersonation, user: user) }
let!(:project_bot) { create(:user, :project_bot) }
let!(:project_member) { create(:project_member, user: project_bot) }
let!(:project_access_token) { create(:personal_access_token, user: project_bot) }
subject { finder(params, current_user).execute }
......@@ -44,7 +47,7 @@ RSpec.describe PersonalAccessTokensFinder do
it do
is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token,
revoked_personal_access_token, expired_personal_access_token,
revoked_impersonation_token, expired_impersonation_token)
revoked_impersonation_token, expired_impersonation_token, project_access_token)
end
context 'when current_user is not an administrator' do
......@@ -59,7 +62,7 @@ RSpec.describe PersonalAccessTokensFinder do
it do
is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token,
revoked_personal_access_token, expired_personal_access_token,
revoked_impersonation_token, expired_impersonation_token)
revoked_impersonation_token, expired_impersonation_token, project_access_token)
end
describe 'with users' do
......@@ -98,14 +101,14 @@ RSpec.describe PersonalAccessTokensFinder do
params[:impersonation] = false
end
it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token) }
it { is_expected.to contain_exactly(active_personal_access_token, revoked_personal_access_token, expired_personal_access_token, project_access_token) }
describe 'with active state' do
before do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_personal_access_token) }
it { is_expected.to contain_exactly(active_personal_access_token, project_access_token) }
end
describe 'with inactive state' do
......@@ -146,7 +149,7 @@ RSpec.describe PersonalAccessTokensFinder do
params[:state] = 'active'
end
it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token) }
it { is_expected.to contain_exactly(active_personal_access_token, active_impersonation_token, project_access_token) }
end
describe 'with inactive state' do
......@@ -208,6 +211,14 @@ RSpec.describe PersonalAccessTokensFinder do
revoked_impersonation_token, expired_impersonation_token)
end
describe 'filtering human tokens' do
before do
params[:owner_type] = 'human'
end
it { is_expected.not_to include(project_access_token) }
end
describe 'without impersonation' do
before do
params[:impersonation] = false
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment