Commit c504b0bb authored by Reuben Pereira's avatar Reuben Pereira

Fix display of relative/absolute time in PAT and deploy token tables

In both tables, the expires time was always being displayed in
relative format. This changes it to respect the
User#time_display_relative setting.

Changelog: fixed
parent 738210f6
......@@ -51,7 +51,7 @@
= _('Expired')
- else
%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
%span.token-never-expires-label= _('Never')
- if project
......
......@@ -20,7 +20,7 @@
%td
- if token.expires?
%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
%span.token-never-expires-label= _('Never')
%td= token.scopes.present? ? token.scopes.join(', ') : _('no scopes selected')
......
......@@ -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(: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
project.add_maintainer(user)
......
......@@ -17141,9 +17141,6 @@ msgstr ""
msgid "Improves Git cloning performance."
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."
msgstr ""
......
......@@ -42,7 +42,7 @@ RSpec.describe 'Admin > Users > Impersonation Tokens', :js do
click_on "Create impersonation token"
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('read_user')
expect(PersonalAccessTokensFinder.new(impersonation: true).execute.count).to equal(1)
......@@ -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).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
......
......@@ -18,11 +18,11 @@ RSpec.describe 'Group Repository settings' do
before do
stub_container_registry_config(enabled: true)
visit group_settings_repository_path(group)
end
it_behaves_like 'a deploy token in settings' do
let(:entity_type) { 'group' }
let(:page_path) { group_settings_repository_path(group) }
end
end
......
......@@ -56,7 +56,7 @@ RSpec.describe 'Profile > Personal Access Tokens', :js do
click_on "Create personal access token"
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('read_user')
expect(created_personal_access_token).not_to be_empty
......@@ -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).not_to have_text(impersonation_token.name)
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
describe "inactive tokens" do
......
......@@ -65,7 +65,7 @@ RSpec.describe 'Project > Settings > Access Tokens', :js do
click_on 'Create project access token'
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('read_api')
expect(active_project_access_tokens).to have_text('Maintainer')
......@@ -156,6 +156,18 @@ RSpec.describe 'Project > Settings > Access Tokens', :js do
expect(active_project_access_tokens).to have_text(project_access_token.name)
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
describe 'inactive tokens' do
......
......@@ -31,11 +31,11 @@ RSpec.describe 'Projects > Settings > Repository settings' do
before do
stub_container_registry_config(enabled: true)
stub_feature_flags(ajax_new_deploy_token: project)
visit project_settings_repository_path(project)
end
it_behaves_like 'a deploy token in settings' do
let(:entity_type) { 'project' }
let(:page_path) { project_settings_repository_path(project) }
end
end
......
# frozen_string_literal: true
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
expect(page).to have_content(deploy_token.name)
expect(page).to have_content('read_repository')
expect(page).to have_content('read_registry')
expect(page).to have_content('in 4 days')
end
end
it 'add a new deploy token' do
visit page_path
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_username', with: 'deployer'
......@@ -24,4 +31,18 @@ RSpec.shared_examples 'a deploy token in settings' do
expect(page).to have_selector("input[name='deploy-token'][readonly='readonly']")
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
......@@ -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(: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
project.add_maintainer(user)
......@@ -140,7 +139,6 @@ RSpec.describe 'shared/access_tokens/_table.html.haml' do
# Expiry
expect(rendered).to have_content 'Expired', count: 2
expect(rendered).to have_content 'In 4 days'
# Revoke buttons
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