diff --git a/app/assets/javascripts/vue_shared/access_tokens/components/access_token_table.vue b/app/assets/javascripts/vue_shared/access_tokens/components/access_token_table.vue index 9489e927a1bddd9bb293fb29d30249fafa8500e4..939c073ca42e175e125361440f27b3d42421b160 100644 --- a/app/assets/javascripts/vue_shared/access_tokens/components/access_token_table.vue +++ b/app/assets/javascripts/vue_shared/access_tokens/components/access_token_table.vue @@ -80,7 +80,7 @@ export default { if (this.action === REVOKE) { this.revokeToken(this.selectedToken.id); } else if (this.action === ROTATE) { - this.rotateToken(this.selectedToken.id, this.selectedToken.expiresAt); + this.rotateToken(this.selectedToken.id); } }, isExpiring(expiresAt) { diff --git a/app/assets/javascripts/vue_shared/access_tokens/stores/access_tokens.js b/app/assets/javascripts/vue_shared/access_tokens/stores/access_tokens.js index e6e3d2ff49b33acf34508ad49256eba9a35ca44a..92489025fdf32e953b3bf44a2778cac6b26525a5 100644 --- a/app/assets/javascripts/vue_shared/access_tokens/stores/access_tokens.js +++ b/app/assets/javascripts/vue_shared/access_tokens/stores/access_tokens.js @@ -10,7 +10,7 @@ import { import { joinPaths } from '~/lib/utils/url_utility'; import { s__ } from '~/locale'; import { SORT_OPTIONS, DEFAULT_SORT } from '~/access_tokens/constants'; -import { serializeParams, update15DaysFromNow } from '../utils'; +import { serializeParams, update15DaysFromNow, oneYearFromNow } from '../utils'; /** * @typedef {{type: string, value: {data: string, operator: string}}} Filter @@ -183,7 +183,7 @@ export const useAccessTokens = defineStore('accessTokens', { * @param {number} tokenId * @param {string} expiresAt */ - async rotateToken(tokenId, expiresAt) { + async rotateToken(tokenId) { this.alert?.dismiss(); this.alert = null; this.busy = true; @@ -191,7 +191,7 @@ export const useAccessTokens = defineStore('accessTokens', { try { const url = this.urlRotate.replace(':id', this.id); const { data } = await axios.post(joinPaths(url, `${tokenId}`, 'rotate'), { - expires_at: expiresAt, + expires_at: oneYearFromNow(), }); this.token = data.token; // Reset pagination because after rotation the token may appear on a different page. diff --git a/app/assets/javascripts/vue_shared/access_tokens/utils.js b/app/assets/javascripts/vue_shared/access_tokens/utils.js index 5e58a2857a2f9afdd0849b2d1234a52938a69200..722bc7230bae744e12697ad4f76a6501bdf94ddc 100644 --- a/app/assets/javascripts/vue_shared/access_tokens/utils.js +++ b/app/assets/javascripts/vue_shared/access_tokens/utils.js @@ -47,6 +47,13 @@ export function fifteenDaysFromNow() { return toISODateFormat(nDaysAfter(new Date(), 15)); } +/** + * Returns a date that is 365 days in the future based on current time in ISO format ('YYYY-MM-DD') + */ +export function oneYearFromNow() { + return toISODateFormat(nDaysAfter(new Date(), 365)); +} + /** * Replace the 'DATE_HOLDER' string with a date 15 days in the future based on current time. */ diff --git a/spec/frontend/vue_shared/access_tokens/stores/access_tokens_spec.js b/spec/frontend/vue_shared/access_tokens/stores/access_tokens_spec.js index e08b25cc9457da5e4e47bfb4c74f718bf105d137..5252943dbe4a8b842dfd3a237e36f4431fd68425 100644 --- a/spec/frontend/vue_shared/access_tokens/stores/access_tokens_spec.js +++ b/spec/frontend/vue_shared/access_tokens/stores/access_tokens_spec.js @@ -445,12 +445,12 @@ describe('useAccessTokens store', () => { }); it('rotates the token', async () => { - await store.rotateToken(1, '2025-01-01'); + await store.rotateToken(1); expect(mockAxios.history.post).toHaveLength(1); expect(mockAxios.history.post[0]).toEqual( expect.objectContaining({ - data: '{"expires_at":"2025-01-01"}', + data: '{"expires_at":"2021-07-06"}', url: 'http://localhost/api/v4/groups/3/service_accounts/235/personal_access_tokens/1/rotate', }), );