Commit f758d839 authored by Nikola Milojevic's avatar Nikola Milojevic

Merge branch '336230-fix-pat-expires-time-display' into 'master'

Fix display of times in access token and deploy token tables

See merge request gitlab-org/gitlab!66262
parents 028c2cc8 c504b0bb
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
= _('Expired') = _('Expired')
- else - else
%span{ class: ('text-warning' if token.expires_soon?) } %span{ class: ('text-warning' if token.expires_soon?) }
= _('In %{time_to_now}') % { time_to_now: distance_of_time_in_words_to_now(token.expires_at) } = time_ago_with_tooltip(token.expires_at)
- else - else
%span.token-never-expires-label= _('Never') %span.token-never-expires-label= _('Never')
- if project - if project
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
%td %td
- if token.expires? - if token.expires?
%span{ class: ('text-warning' if token.expires_soon?) } %span{ class: ('text-warning' if token.expires_soon?) }
In #{distance_of_time_in_words_to_now(token.expires_at)} = time_ago_with_tooltip(token.expires_at)
- else - else
%span.token-never-expires-label= _('Never') %span.token-never-expires-label= _('Never')
%td= token.scopes.present? ? token.scopes.join(', ') : _('no scopes selected') %td= token.scopes.present? ? token.scopes.join(', ') : _('no scopes selected')
......
...@@ -18,7 +18,6 @@ RSpec.describe 'shared/access_tokens/_table.html.haml' do ...@@ -18,7 +18,6 @@ RSpec.describe 'shared/access_tokens/_table.html.haml' do
allow(view).to receive(:personal_access_token_expiration_enforced?).and_return(token_expiry_enforced?) allow(view).to receive(:personal_access_token_expiration_enforced?).and_return(token_expiry_enforced?)
allow(view).to receive(:show_profile_token_expiry_notification?).and_return(true) allow(view).to receive(:show_profile_token_expiry_notification?).and_return(true)
allow(view).to receive(:distance_of_time_in_words_to_now).and_return('4 days')
if project if project
project.add_maintainer(user) project.add_maintainer(user)
......
...@@ -17195,9 +17195,6 @@ msgstr "" ...@@ -17195,9 +17195,6 @@ msgstr ""
msgid "Improves Git cloning performance." msgid "Improves Git cloning performance."
msgstr "" msgstr ""
msgid "In %{time_to_now}"
msgstr ""
msgid "In case of pull mirroring, your user will be the author of all events in the activity feed that are the result of an update, like new branches being created or new commits being pushed to existing branches." msgid "In case of pull mirroring, your user will be the author of all events in the activity feed that are the result of an update, like new branches being created or new commits being pushed to existing branches."
msgstr "" msgstr ""
......
...@@ -42,7 +42,7 @@ RSpec.describe 'Admin > Users > Impersonation Tokens', :js do ...@@ -42,7 +42,7 @@ RSpec.describe 'Admin > Users > Impersonation Tokens', :js do
click_on "Create impersonation token" click_on "Create impersonation token"
expect(active_impersonation_tokens).to have_text(name) expect(active_impersonation_tokens).to have_text(name)
expect(active_impersonation_tokens).to have_text('In') expect(active_impersonation_tokens).to have_text('in')
expect(active_impersonation_tokens).to have_text('api') expect(active_impersonation_tokens).to have_text('api')
expect(active_impersonation_tokens).to have_text('read_user') expect(active_impersonation_tokens).to have_text('read_user')
expect(PersonalAccessTokensFinder.new(impersonation: true).execute.count).to equal(1) expect(PersonalAccessTokensFinder.new(impersonation: true).execute.count).to equal(1)
...@@ -59,6 +59,14 @@ RSpec.describe 'Admin > Users > Impersonation Tokens', :js do ...@@ -59,6 +59,14 @@ RSpec.describe 'Admin > Users > Impersonation Tokens', :js do
expect(active_impersonation_tokens).to have_text(impersonation_token.name) expect(active_impersonation_tokens).to have_text(impersonation_token.name)
expect(active_impersonation_tokens).not_to have_text(personal_access_token.name) expect(active_impersonation_tokens).not_to have_text(personal_access_token.name)
expect(active_impersonation_tokens).to have_text('in')
end
it 'shows absolute times' do
admin.update!(time_display_relative: false)
visit admin_user_impersonation_tokens_path(user_id: user.username)
expect(active_impersonation_tokens).to have_text(personal_access_token.expires_at.strftime('%b %d'))
end end
end end
......
...@@ -18,11 +18,11 @@ RSpec.describe 'Group Repository settings' do ...@@ -18,11 +18,11 @@ RSpec.describe 'Group Repository settings' do
before do before do
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
visit group_settings_repository_path(group)
end end
it_behaves_like 'a deploy token in settings' do it_behaves_like 'a deploy token in settings' do
let(:entity_type) { 'group' } let(:entity_type) { 'group' }
let(:page_path) { group_settings_repository_path(group) }
end end
end end
......
...@@ -56,7 +56,7 @@ RSpec.describe 'Profile > Personal Access Tokens', :js do ...@@ -56,7 +56,7 @@ RSpec.describe 'Profile > Personal Access Tokens', :js do
click_on "Create personal access token" click_on "Create personal access token"
expect(active_personal_access_tokens).to have_text(name) expect(active_personal_access_tokens).to have_text(name)
expect(active_personal_access_tokens).to have_text('In') expect(active_personal_access_tokens).to have_text('in')
expect(active_personal_access_tokens).to have_text('api') expect(active_personal_access_tokens).to have_text('api')
expect(active_personal_access_tokens).to have_text('read_user') expect(active_personal_access_tokens).to have_text('read_user')
expect(created_personal_access_token).not_to be_empty expect(created_personal_access_token).not_to be_empty
...@@ -85,6 +85,18 @@ RSpec.describe 'Profile > Personal Access Tokens', :js do ...@@ -85,6 +85,18 @@ RSpec.describe 'Profile > Personal Access Tokens', :js do
expect(active_personal_access_tokens).to have_text(personal_access_token.name) expect(active_personal_access_tokens).to have_text(personal_access_token.name)
expect(active_personal_access_tokens).not_to have_text(impersonation_token.name) expect(active_personal_access_tokens).not_to have_text(impersonation_token.name)
end end
context 'when User#time_display_relative is false' do
before do
user.update!(time_display_relative: false)
end
it 'shows absolute times for expires_at' do
visit profile_personal_access_tokens_path
expect(active_personal_access_tokens).to have_text(PersonalAccessToken.last.expires_at.strftime('%b %d'))
end
end
end end
describe "inactive tokens" do describe "inactive tokens" do
......
...@@ -65,7 +65,7 @@ RSpec.describe 'Project > Settings > Access Tokens', :js do ...@@ -65,7 +65,7 @@ RSpec.describe 'Project > Settings > Access Tokens', :js do
click_on 'Create project access token' click_on 'Create project access token'
expect(active_project_access_tokens).to have_text(name) expect(active_project_access_tokens).to have_text(name)
expect(active_project_access_tokens).to have_text('In') expect(active_project_access_tokens).to have_text('in')
expect(active_project_access_tokens).to have_text('api') expect(active_project_access_tokens).to have_text('api')
expect(active_project_access_tokens).to have_text('read_api') expect(active_project_access_tokens).to have_text('read_api')
expect(active_project_access_tokens).to have_text('Maintainer') expect(active_project_access_tokens).to have_text('Maintainer')
...@@ -156,6 +156,18 @@ RSpec.describe 'Project > Settings > Access Tokens', :js do ...@@ -156,6 +156,18 @@ RSpec.describe 'Project > Settings > Access Tokens', :js do
expect(active_project_access_tokens).to have_text(project_access_token.name) expect(active_project_access_tokens).to have_text(project_access_token.name)
end end
context 'when User#time_display_relative is false' do
before do
user.update!(time_display_relative: false)
end
it 'shows absolute times for expires_at' do
visit project_settings_access_tokens_path(project)
expect(active_project_access_tokens).to have_text(PersonalAccessToken.last.expires_at.strftime('%b %d'))
end
end
end end
describe 'inactive tokens' do describe 'inactive tokens' do
......
...@@ -31,11 +31,11 @@ RSpec.describe 'Projects > Settings > Repository settings' do ...@@ -31,11 +31,11 @@ RSpec.describe 'Projects > Settings > Repository settings' do
before do before do
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
stub_feature_flags(ajax_new_deploy_token: project) stub_feature_flags(ajax_new_deploy_token: project)
visit project_settings_repository_path(project)
end end
it_behaves_like 'a deploy token in settings' do it_behaves_like 'a deploy token in settings' do
let(:entity_type) { 'project' } let(:entity_type) { 'project' }
let(:page_path) { project_settings_repository_path(project) }
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'a deploy token in settings' do RSpec.shared_examples 'a deploy token in settings' do
it 'view deploy tokens' do it 'view deploy tokens', :js do
user.update!(time_display_relative: true)
visit page_path
within('.deploy-tokens') do within('.deploy-tokens') do
expect(page).to have_content(deploy_token.name) expect(page).to have_content(deploy_token.name)
expect(page).to have_content('read_repository') expect(page).to have_content('read_repository')
expect(page).to have_content('read_registry') expect(page).to have_content('read_registry')
expect(page).to have_content('in 4 days')
end end
end end
it 'add a new deploy token' do it 'add a new deploy token' do
visit page_path
fill_in 'deploy_token_name', with: 'new_deploy_key' fill_in 'deploy_token_name', with: 'new_deploy_key'
fill_in 'deploy_token_expires_at', with: (Date.today + 1.month).to_s fill_in 'deploy_token_expires_at', with: (Date.today + 1.month).to_s
fill_in 'deploy_token_username', with: 'deployer' fill_in 'deploy_token_username', with: 'deployer'
...@@ -24,4 +31,18 @@ RSpec.shared_examples 'a deploy token in settings' do ...@@ -24,4 +31,18 @@ RSpec.shared_examples 'a deploy token in settings' do
expect(page).to have_selector("input[name='deploy-token'][readonly='readonly']") expect(page).to have_selector("input[name='deploy-token'][readonly='readonly']")
end end
end end
context 'when User#time_display_relative is false', :js do
before do
user.update!(time_display_relative: false)
end
it 'shows absolute times for expires_at' do
visit page_path
within('.deploy-tokens') do
expect(page).to have_content(deploy_token.expires_at.strftime('%b %d'))
end
end
end
end end
...@@ -19,7 +19,6 @@ RSpec.describe 'shared/access_tokens/_table.html.haml' do ...@@ -19,7 +19,6 @@ RSpec.describe 'shared/access_tokens/_table.html.haml' do
allow(view).to receive(:personal_access_token_expiration_enforced?).and_return(token_expiry_enforced?) allow(view).to receive(:personal_access_token_expiration_enforced?).and_return(token_expiry_enforced?)
allow(view).to receive(:show_profile_token_expiry_notification?).and_return(true) allow(view).to receive(:show_profile_token_expiry_notification?).and_return(true)
allow(view).to receive(:distance_of_time_in_words_to_now).and_return('4 days')
if project if project
project.add_maintainer(user) project.add_maintainer(user)
...@@ -140,7 +139,6 @@ RSpec.describe 'shared/access_tokens/_table.html.haml' do ...@@ -140,7 +139,6 @@ RSpec.describe 'shared/access_tokens/_table.html.haml' do
# Expiry # Expiry
expect(rendered).to have_content 'Expired', count: 2 expect(rendered).to have_content 'Expired', count: 2
expect(rendered).to have_content 'In 4 days'
# Revoke buttons # Revoke buttons
expect(rendered).to have_link 'Revoke', href: 'path/', class: 'btn-danger-secondary', count: 1 expect(rendered).to have_link 'Revoke', href: 'path/', class: 'btn-danger-secondary', count: 1
......
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