Skip to content

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

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.rb
index 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 My
def delete_link
link_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
+ end
end
end
end
diff --git a/app/controllers/my/access_tokens_controller.rb b/app/controllers/my/access_tokens_controller.rb
index 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_token
def dialog
@token_type = params[:token_type] || "api"
@@ -141,6 +142,25 @@ module My
redirect_to action: :index
end
+ 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_token
message = ical_destroy_info_message
@ical_token.destroy
diff --git a/config/locales/en.yml b/config/locales/en.yml
index d629f09d977..86238443393 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -634,6 +634,10 @@ en:
title: Token generated
header: The %{type} token has been generated
warning: 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.rb
index 4b16aa1271f..40a422bc93c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -872,6 +872,7 @@ Rails.application.routes.draw do
delete :revoke_api_key
delete :revoke_ical_token
delete :revoke_storage_token
+ delete :revoke_ical_meeting_token
end
end
diff --git a/spec/features/users/my/access_tokens_spec.rb b/spec/features/users/my/access_tokens_spec.rb
index 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 do
within("dialog#api-created-dialog") do
expect(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"
end
expect(page).to have_content("Testing Token")
@@ -100,8 +101,11 @@ RSpec.describe "my access tokens", :js do
User.current.reload
visit my_access_tokens_path
- # API token can be created again
within "#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 again
expect(page).to have_test_selector("api-token-add", text: "API Token")
end
end
@@ -235,6 +239,75 @@ RSpec.describe "my access tokens", :js do
end
end
+ 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" do
context "when no OAuth access is configured" do
it "shows notice about no existing tokens" do