From 52706462de9dc26b0e2f259ea2c44518fa4375d7 Mon Sep 17 00:00:00 2001 From: unset Date: Fri, 24 May 2024 15:17:57 -0400 Subject: [PATCH 1/4] Add frontend changes for MVC for advanced scoped tokens This MR adds the frontend changes required to enable using advanced_scopes feature Changelog: added --- .../components/access_token_table_app.vue | 6 +++++- .../access_tokens/components/constants.js | 5 +++++ app/views/shared/access_tokens/_form.html.haml | 8 ++++++++ .../components/access_token_table_app_spec.js | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/access_tokens/components/access_token_table_app.vue b/app/assets/javascripts/access_tokens/components/access_token_table_app.vue index 974cbeee5f94cb..36189127d669b2 100644 --- a/app/assets/javascripts/access_tokens/components/access_token_table_app.vue +++ b/app/assets/javascripts/access_tokens/components/access_token_table_app.vue @@ -6,6 +6,7 @@ import { __, sprintf } from '~/locale'; import DomElementListener from '~/vue_shared/components/dom_element_listener.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import UserDate from '~/vue_shared/components/user_date.vue'; +import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import { EVENT_SUCCESS, FIELDS, FORM_SELECTOR, INITIAL_PAGE, PAGE_SIZE } from './constants'; export default { @@ -26,6 +27,7 @@ export default { directives: { GlTooltip: GlTooltipDirective, }, + mixins: [glFeatureFlagsMixin()], lastUsedHelpLink: helpPagePath('/user/profile/personal_access_tokens.md', { anchor: 'view-the-last-time-a-token-was-used', }), @@ -69,7 +71,9 @@ export default { if (!this.showRole) { ignoredFields.push('role'); } - + if (!this.glFeatures.advancedTokenScopes) { + ignoredFields.push('advancedScopes'); + } return FIELDS.filter(({ key }) => !ignoredFields.includes(key)); }, showPagination() { diff --git a/app/assets/javascripts/access_tokens/components/constants.js b/app/assets/javascripts/access_tokens/components/constants.js index 9cd7cb5bb3a401..072b2cd928da70 100644 --- a/app/assets/javascripts/access_tokens/components/constants.js +++ b/app/assets/javascripts/access_tokens/components/constants.js @@ -21,6 +21,11 @@ export const FIELDS = [ label: __('Scopes'), sortable: true, }, + { + key: 'advancedScopes', + label: s__('AccessTokens|Advanced scopes'), + tdClass: 'gl-py-3!', + }, { key: 'createdAt', label: s__('AccessTokens|Created'), diff --git a/app/views/shared/access_tokens/_form.html.haml b/app/views/shared/access_tokens/_form.html.haml index 79c4bfca63072f..b6114c2e0e4dcf 100644 --- a/app/views/shared/access_tokens/_form.html.haml +++ b/app/views/shared/access_tokens/_form.html.haml @@ -41,6 +41,14 @@ = link_to _("Learn more."), help_path, target: '_blank', rel: 'noopener noreferrer' = render 'shared/tokens/scopes_form', prefix: prefix, description_prefix: description_prefix, token: token, scopes: scopes, f: f + - if Feature.enabled?(:advanced_token_scopes, current_user) + - unless resource + .form-group + = f.label :name, _('Advanced scopes'), class: 'label-bold' + = f.text_area :advanced_scopes, class: 'form-control gl-form-input gl-form-input-xl', required: false, :'aria-describedby' => 'access_token_help_text' + %span.form-text.text-muted#access_token_help_text= _("Set advanced scopes for the access token") + + .gl-mt-3 = f.submit s_('AccessTokens|Create %{type}') % { type: type }, data: { testid: 'create-token-button' }, pajamas_button: true = render Pajamas::ButtonComponent.new(button_options: { type: 'reset', class: 'gl-ml-2 js-toggle-button' }) do diff --git a/spec/frontend/access_tokens/components/access_token_table_app_spec.js b/spec/frontend/access_tokens/components/access_token_table_app_spec.js index 09b269bbcdd62d..5aa800c0442491 100644 --- a/spec/frontend/access_tokens/components/access_token_table_app_spec.js +++ b/spec/frontend/access_tokens/components/access_token_table_app_spec.js @@ -51,6 +51,7 @@ describe('~/access_tokens/components/access_token_table_app', () => { initialActiveAccessTokens: defaultActiveAccessTokens, noActiveTokensMessage, showRole, + glFeatures: { advancedTokenScopes: false }, ...props, }, }); @@ -269,4 +270,20 @@ describe('~/access_tokens/components/access_token_table_app', () => { expect(findPagination().exists()).toBe(true); }); }); + + describe('when advancedTokenScopes feature flag is enabled', () => { + it('should include the advanced token scopes header', () => { + createComponent({ glFeatures: { advancedTokenScopes: true } }); + const headers = findHeaders(); + expect(headers.wrappers.map((header) => header.text())).toStrictEqual([ + __('Token name'), + __('Scopes'), + s__('AccessTokens|Advanced scopes'), + s__('AccessTokens|Created'), + 'Last Used', + __('Expires'), + __('Action'), + ]); + }); + }); }); -- GitLab From 847fa90a4c76bc126fe51177a971708f346cd048 Mon Sep 17 00:00:00 2001 From: unset Date: Fri, 24 May 2024 15:20:34 -0400 Subject: [PATCH 2/4] Add translations to gitlab pot --- locale/gitlab.pot | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 55106685d626f6..0bb05d655511b6 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -2678,6 +2678,9 @@ msgstr "" msgid "AccessTokens|Add a %{type}" msgstr "" +msgid "AccessTokens|Advanced scopes" +msgstr "" + msgid "AccessTokens|Are you sure?" msgstr "" @@ -4622,6 +4625,9 @@ msgstr "" msgid "Advanced export options" msgstr "" +msgid "Advanced scopes" +msgstr "" + msgid "AdvancedSearch|Could not fetch index entities. Please try again later." msgstr "" @@ -48765,6 +48771,9 @@ msgstr "" msgid "Set a password on your account to pull or push via %{protocol}." msgstr "" +msgid "Set advanced scopes for the access token" +msgstr "" + msgid "Set due date" msgstr "" -- GitLab From 83caf69cb5d80762cbd9553e9b07e6c5d5d7a819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Veillette-Potvin?= Date: Mon, 27 May 2024 19:26:50 +0000 Subject: [PATCH 3/4] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Alex Buijs --- app/views/shared/access_tokens/_form.html.haml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/views/shared/access_tokens/_form.html.haml b/app/views/shared/access_tokens/_form.html.haml index b6114c2e0e4dcf..e8430dc04df753 100644 --- a/app/views/shared/access_tokens/_form.html.haml +++ b/app/views/shared/access_tokens/_form.html.haml @@ -41,13 +41,11 @@ = link_to _("Learn more."), help_path, target: '_blank', rel: 'noopener noreferrer' = render 'shared/tokens/scopes_form', prefix: prefix, description_prefix: description_prefix, token: token, scopes: scopes, f: f - - if Feature.enabled?(:advanced_token_scopes, current_user) - - unless resource - .form-group - = f.label :name, _('Advanced scopes'), class: 'label-bold' - = f.text_area :advanced_scopes, class: 'form-control gl-form-input gl-form-input-xl', required: false, :'aria-describedby' => 'access_token_help_text' - %span.form-text.text-muted#access_token_help_text= _("Set advanced scopes for the access token") - + - if Feature.enabled?(:advanced_token_scopes, current_user) && !resource + .form-group + = f.label :name, _('Advanced scopes'), class: 'label-bold' + = f.text_area :advanced_scopes, class: 'form-control gl-form-input gl-form-input-xl', required: false, 'aria-describedby': 'access_token_help_text' + %span.form-text.text-muted#access_token_help_text= _("Set advanced scopes for the access token") .gl-mt-3 = f.submit s_('AccessTokens|Create %{type}') % { type: type }, data: { testid: 'create-token-button' }, pajamas_button: true -- GitLab From 2db205168bfb1645a36a419f27105b9eaf1d804c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Veillette-Potvin?= Date: Fri, 5 Jul 2024 19:28:55 +0000 Subject: [PATCH 4/4] Adapt to new model --- .../access_tokens/components/access_token_table_app.vue | 2 +- app/assets/javascripts/access_tokens/components/constants.js | 2 +- app/views/shared/access_tokens/_form.html.haml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/access_tokens/components/access_token_table_app.vue b/app/assets/javascripts/access_tokens/components/access_token_table_app.vue index 36189127d669b2..181ad1c390457e 100644 --- a/app/assets/javascripts/access_tokens/components/access_token_table_app.vue +++ b/app/assets/javascripts/access_tokens/components/access_token_table_app.vue @@ -72,7 +72,7 @@ export default { ignoredFields.push('role'); } if (!this.glFeatures.advancedTokenScopes) { - ignoredFields.push('advancedScopes'); + ignoredFields.push('personalAccessTokenAdvancedScopes'); } return FIELDS.filter(({ key }) => !ignoredFields.includes(key)); }, diff --git a/app/assets/javascripts/access_tokens/components/constants.js b/app/assets/javascripts/access_tokens/components/constants.js index 072b2cd928da70..cf3106ae785d10 100644 --- a/app/assets/javascripts/access_tokens/components/constants.js +++ b/app/assets/javascripts/access_tokens/components/constants.js @@ -22,7 +22,7 @@ export const FIELDS = [ sortable: true, }, { - key: 'advancedScopes', + key: 'personalAccessTokenAdvancedScopes', label: s__('AccessTokens|Advanced scopes'), tdClass: 'gl-py-3!', }, diff --git a/app/views/shared/access_tokens/_form.html.haml b/app/views/shared/access_tokens/_form.html.haml index e8430dc04df753..1296018d1e60fe 100644 --- a/app/views/shared/access_tokens/_form.html.haml +++ b/app/views/shared/access_tokens/_form.html.haml @@ -44,7 +44,7 @@ - if Feature.enabled?(:advanced_token_scopes, current_user) && !resource .form-group = f.label :name, _('Advanced scopes'), class: 'label-bold' - = f.text_area :advanced_scopes, class: 'form-control gl-form-input gl-form-input-xl', required: false, 'aria-describedby': 'access_token_help_text' + = f.text_area :personal_access_token_advanced_scopes, class: 'form-control gl-form-input gl-form-input-xl', required: false, 'aria-describedby': 'access_token_help_text' %span.form-text.text-muted#access_token_help_text= _("Set advanced scopes for the access token") .gl-mt-3 -- GitLab