OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[48619] Fixed "my" feature spec for api tokens
Andreas Pfohlfe0b946da04c
diff --git a/app/components/my/access_token/new_access_token_component.html.erb b/app/components/my/access_token/new_access_token_component.html.erbindex 0104f24f92f..e7eaae379dc 100644--- a/app/components/my/access_token/new_access_token_component.html.erb+++ b/app/components/my/access_token/new_access_token_component.html.erb@@ -36,7 +36,7 @@ See COPYRIGHT and LICENSE files for more details.size: :large)) do |dialog|- dialog.with_show_button(scheme: :primary, mt: 3) do |button|+ dialog.with_show_button(scheme: :primary, mt: 3, test_selector: "api-token-add") do |button|button.with_leading_visual_icon(icon: :plus)I18n.t("my.access_token.new_access_token_dialog_show_button_text")enddiff --git a/app/components/my/access_token/new_access_token_form_component.html.erb b/app/components/my/access_token/new_access_token_form_component.html.erbindex d889ca9d157..90c080753f0 100644--- a/app/components/my/access_token/new_access_token_form_component.html.erb+++ b/app/components/my/access_token/new_access_token_form_component.html.erb@@ -64,7 +64,7 @@ See COPYRIGHT and LICENSE files for more details.I18n.t("button_cancel")end- footer.with_component(Primer::ButtonComponent.new(scheme: :primary, type: :submit)) do+ footer.with_component(Primer::ButtonComponent.new(scheme: :primary, type: :submit, test_selector: "create-api-token-button")) doI18n.t("my.access_token.new_access_token_dialog_submit_button_text")endenddiff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rbindex 6a6f6c87d74..527891665ef 100644--- a/app/controllers/my_controller.rb+++ b/app/controllers/my_controller.rb@@ -158,7 +158,7 @@ class MyController < ApplicationControllerredirect_to action: "access_token"end- # Create a new API key+ # rubocop:disable Metrics/AbcSizedef generate_api_keyresult = APITokens::CreateService.new(user: current_user).call(token_name: params[:token_api][:token_name])@@ -181,22 +181,28 @@ class MyController < ApplicationControllerrespond_with_turbo_streamsendend+ # rubocop:enable Metrics/AbcSize+ # rubocop:disable Metrics/AbcSizedef revoke_api_keyresult = APITokens::DeleteService.new(user: current_user, model: @api_token).call+ # rubocop:disable Rails/ActionControllerFlashBeforeRenderresult.on_success do- flash.now[:info] = t("my.access_token.notice_api_token_revoked")+ flash[:info] = t("my.access_token.notice_api_token_revoked")endresult.on_failure doRails.logger.error "Failed to revoke api token ##{current_user.id}: #{e}"- flash.now[:error] = t("my.access_token.failed_to_revoke_token", error: e.message)+ flash[:error] = t("my.access_token.failed_to_revoke_token", error: e.message)end+ # rubocop:enable Rails/ActionControllerFlashBeforeRenderredirect_to action: "access_token"end+ # rubocop:enable Metrics/AbcSize+def revoke_ical_tokenmessage = ical_destroy_info_message@ical_token.destroydiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 820e337ee02..455e0403490 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -432,11 +432,11 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}token_name_blank: "Please provide an API token name"token_name_in_use: "This API token name is already in use, please select a different one"new_access_token_dialog_title: "Create new API token"- new_access_token_dialog_show_button_text: "API Token"+ new_access_token_dialog_show_button_text: "API token"new_access_token_dialog_text_field_placeholder_text: "My API token"new_access_token_dialog_text_field_label: "Name"new_access_token_dialog_submit_button_text: "Create"- new_access_token_dialog_text: "This token will allow third-party applications to communicate with your instance. To generate a new API token please introduce a token name."+ new_access_token_dialog_text: "This token will allow third-party applications to communicate with your instance. To differentiate the new API token, please give it a name."new_access_token_dialog_attention_text: "Treat API tokens like passwords. Anyone with this link will have access to information from this instance, share it only with trusted users."failed_to_reset_token: "Failed to reset access token: %{error}"failed_to_create_token: "Failed to create access token: %{error}"diff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rbindex af11f256d7c..2f39f345cf6 100644--- a/spec/controllers/my_controller_spec.rb+++ b/spec/controllers/my_controller_spec.rb@@ -353,18 +353,18 @@ RSpec.describe MyController doit "revoke specific ical tokens" doexpect(user.ical_tokens).to contain_exactly(- ical_token_for_query, another_ical_token_for_query, ical_token_for_another_query- )+ ical_token_for_query, another_ical_token_for_query, ical_token_for_another_query+ )delete :revoke_ical_token, params: { id: another_ical_token_for_query.id }expect(user.ical_tokens.reload).to contain_exactly(- ical_token_for_query, ical_token_for_another_query- )+ ical_token_for_query, ical_token_for_another_query+ )expect(user.ical_tokens.reload).not_to contain_exactly(- ical_token_for_another_query- )+ ical_token_for_another_query+ )expect(flash[:info]).to be_presentexpect(flash[:error]).not_to be_presentdiff --git a/spec/features/users/my_spec.rb b/spec/features/users/my_spec.rbindex 53ff55f7994..0e309461ed2 100644--- a/spec/features/users/my_spec.rb+++ b/spec/features/users/my_spec.rb@@ -152,14 +152,20 @@ RSpec.describe "my", :js, :with_cuprite dofind_test_selector("api-token-add").clickend+ expect(page).to have_test_selector("new-access-token-dialog")++ # create API token+ fill_in "token_api[token_name]", with: "Testing Token"+ find_test_selector("create-api-token-button").click+expect(page).to have_content "A new API token has been generated. Your access token is"User.current.reloadvisit my_access_token_path- # only one API token can be created+ # multiple API tokens can be createdwithin "#api-token-section" do- expect(page).not_to have_test_selector("api-token-add", text: "API token")+ expect(page).to have_test_selector("api-token-add", text: "API token")end# revoke API token