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
Revocation and tests for ical meeting tokens
Klaus Zanders1848c02e360a
diff --git a/app/components/my/access_token/api/row_component.rb b/app/components/my/access_token/api/row_component.rbindex a1ec1bc648d..4c8c6e7cd4c 100644--- a/app/components/my/access_token/api/row_component.rb+++ b/app/components/my/access_token/api/row_component.rb@@ -59,13 +59,22 @@ module Mydef delete_linklink_to "",{- action: :revoke_api_key,+ action: delete_action,access_token_id: api_token.id},method: :delete,data: { confirm: t("my_account.access_tokens.simple_revoke_confirmation"), test_selector: "api-token-revoke" },class: "icon icon-delete"end++ private++ def delete_action+ case model+ when Token::API then :revoke_api_key+ when Token::ICalMeeting then :revoke_ical_meeting_token+ end+ endendendenddiff --git a/app/controllers/my/access_tokens_controller.rb b/app/controllers/my/access_tokens_controller.rbindex f40bc527064..422dcb882ef 100644--- a/app/controllers/my/access_tokens_controller.rb+++ b/app/controllers/my/access_tokens_controller.rb@@ -50,7 +50,8 @@ module My:generate_api_key,:revoke_api_key,:revoke_ical_token,- :revoke_storage_token+ :revoke_storage_token,+ :revoke_ical_meeting_tokendef dialog@token_type = params[:token_type] || "api"@@ -141,6 +142,25 @@ module Myredirect_to action: :indexend+ def revoke_ical_meeting_token # rubocop:disable Metrics/AbcSize+ ical_meeting_token = current_user.ical_meeting_tokens.find(params[:access_token_id])+ result = APITokens::DeleteService.new(user: current_user, model: ical_meeting_token).call++ # rubocop:disable Rails/ActionControllerFlashBeforeRender+ result.on_success do+ flash[:notice] = t("my.access_token.revocation.ical_meeting.notice_success")+ end++ result.on_failure do |r|+ error = r.errors.map(&:message).join("; ")+ Rails.logger.error("Failed to revoke ical meeting token ##{current_user.id}: #{error}")+ flash[:error] = t("my.access_token.ical_meeting.notice_failure", error:)+ end+ # rubocop:enable Rails/ActionControllerFlashBeforeRender++ redirect_to action: :index+ end+def revoke_ical_tokenmessage = ical_destroy_info_message@ical_token.destroydiff --git a/config/locales/en.yml b/config/locales/en.ymlindex d629f09d977..86238443393 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -634,6 +634,10 @@ en:title: Token generatedheader: The %{type} token has been generatedwarning: Note that this is the only time you will see this token, make sure to copy it now.+ revocation:+ ical_meeting:+ notice_success: "The iCalendar meeting subscription has been revoked successfully."+ notice_failure: "Failed to revoke iCalendar meeting subscription: %{error}"errors: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"@@ -1645,8 +1649,7 @@ en:cant_exceed_work: "cannot be higher than Work."must_be_set_when_work_is_set: "required when Work is set."must_be_set_when_work_and_percent_complete_are_set: "required when Work and % Complete are set."- must_be_set_to_zero_hours_when_work_is_set_and_percent_complete_is_100p:- >-+ must_be_set_to_zero_hours_when_work_is_set_and_percent_complete_is_100p: >-must be 0h when Work is set and % Complete is 100%.must_be_empty_when_work_is_empty_and_percent_complete_is_100p: >-must be empty when Work is empty and % Complete is 100%.@@ -2085,33 +2088,9 @@ en:date:abbr_day_names: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]- abbr_month_names:- [- ~,- "Jan",- "Feb",- "Mar",- "Apr",- "May",- "Jun",- "Jul",- "Aug",- "Sep",- "Oct",- "Nov",- "Dec",- ]+ abbr_month_names: [~, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]abbr_week: "Wk"- day_names:- [- "Sunday",- "Monday",- "Tuesday",- "Wednesday",- "Thursday",- "Friday",- "Saturday",- ]+ day_names: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]formats:# Use the strftime parameters for formats.# When no format has been given, it uses default.diff --git a/config/routes.rb b/config/routes.rbindex 4b16aa1271f..40a422bc93c 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -872,6 +872,7 @@ Rails.application.routes.draw dodelete :revoke_api_keydelete :revoke_ical_tokendelete :revoke_storage_token+ delete :revoke_ical_meeting_tokenendenddiff --git a/spec/features/users/my/access_tokens_spec.rb b/spec/features/users/my/access_tokens_spec.rbindex ad64046ae41..281ad992c05 100644--- a/spec/features/users/my/access_tokens_spec.rb+++ b/spec/features/users/my/access_tokens_spec.rb@@ -76,6 +76,7 @@ RSpec.describe "my access tokens", :js dowithin("dialog#api-created-dialog") doexpect(page).to have_content "The Access token token has been generated"+ expect(page).to have_field("openproject_api_access_token", with: %r{[a-f0-9]{64}}, readonly: true)click_on "Close"endexpect(page).to have_content("Testing Token")@@ -100,8 +101,11 @@ RSpec.describe "my access tokens", :js doUser.current.reloadvisit my_access_tokens_path- # API token can be created againwithin "#api-token-component" do+ # make sure the token is not there anymore+ expect(page).to have_no_content("Testing Token")++ # API token can be created againexpect(page).to have_test_selector("api-token-add", text: "API Token")endend@@ -235,6 +239,75 @@ RSpec.describe "my access tokens", :js doendend+ describe "iCal Meeting tokens" do+ context "when iCal access is disabled via global settings", with_settings: { ical_enabled: false } do+ it "shows notice about disabled token" do+ visit my_access_tokens_path++ within "#ical_meeting-token-component" do+ expect(page).to have_content("iCalendar meeting subscriptions are not enabled by the administrator. Please contact your administrator to use this feature.")+ expect(page).not_to have_test_selector("ical_meeting-token-add", text: "Subscribe to calendar")+ end+ end+ end++ context "when iCal access is enabled via global settings", with_settings: { ical_enabled: true } do+ it "iCal tokens can be generated and revoked" do+ visit my_access_tokens_path++ expect(page).to have_no_content("iCalendar meeting subscriptions are not enabled by the administrator. Please contact your administrator to use this feature.")++ within "#ical_meeting-token-component" do+ expect(page).to have_test_selector("ical_meeting-token-add", text: "Subscribe to calendar")+ find_test_selector("ical_meeting-token-add").click+ end++ expect(page).to have_test_selector("new-access-token-dialog")++ # create iCal meeting token+ fill_in "token_ical_meeting[token_name]", with: "Testing Token"+ find_test_selector("create-api-token-button").click++ within("dialog#ical_meeting-created-dialog") do+ expect(page).to have_content "The iCal Meeting subscription token has been generated"+ expect(page).to have_field("openproject_api_access_token",+ with: %r{http://localhost:\d+/meetings/ical/[a-f0-9]{64}.ics},+ readonly: true)+ click_on "Close"+ end+ expect(page).to have_content("Testing Token")++ User.current.reload+ visit my_access_tokens_path++ # multiple iCal meeting tokens can be created+ within "#ical_meeting-token-component" do+ expect(page).to have_test_selector("ical_meeting-token-add", text: "Subscribe to calendar")+ end++ # revoke iCal meeting token+ within "#ical_meeting-token-component" do+ accept_confirm do+ find_test_selector("api-token-revoke").click+ end+ end++ expect(page).to have_content I18n.t("my.access_token.revocation.ical_meeting.notice_success")++ User.current.reload+ visit my_access_tokens_path++ within "#ical_meeting-token-component" do+ # make sure the token is not there anymore+ expect(page).to have_no_content("Testing Token")++ # API token can be created again+ expect(page).to have_test_selector("ical_meeting-token-add", text: "Subscribe to calendar")+ end+ end+ end+ end+describe "OAuth tokens" docontext "when no OAuth access is configured" doit "shows notice about no existing tokens" do