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

Handle internal server error on mention sanitization request

Kabiru Mwenja22cc675c2491
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index c8978df026b..ce975eb36b8 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -141,6 +141,9 @@ class WorkPackages::ActivitiesTabController < ApplicationController
def sanitize_restricted_mentions
render plain: sanitized_journal_notes
+ rescue StandardError => e
+ handle_internal_server_error(e)
+ respond_with_turbo_streams
end
def toggle_reaction # rubocop:disable Metrics/AbcSize
@@ -226,7 +229,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
end
def sanitized_journal_notes
- WorkPackages::ActivitiesTab::RestrictedMentionsSanitizer.new(@work_package, journal_params[:notes]).call
+ WorkPackages::ActivitiesTab::RestrictedMentionsSanitizer.sanitize(@work_package, journal_params[:notes])
end
def journal_params
diff --git a/app/services/work_packages/activities_tab/restricted_mentions_sanitizer.rb b/app/services/work_packages/activities_tab/restricted_mentions_sanitizer.rb
index 5dee938a469..7e02e3dab6a 100644
--- a/app/services/work_packages/activities_tab/restricted_mentions_sanitizer.rb
+++ b/app/services/work_packages/activities_tab/restricted_mentions_sanitizer.rb
@@ -29,6 +29,10 @@
#++
class WorkPackages::ActivitiesTab::RestrictedMentionsSanitizer
+ def self.sanitize(work_package, notes)
+ new(work_package, notes).call
+ end
+
def initialize(work_package, notes)
@work_package = work_package
@notes = notes
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts
index b11b91f03b0..e52a34b903a 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/restricted-comment.controller.ts
@@ -29,6 +29,7 @@
*/
import { Controller } from '@hotwired/stimulus';
+import { renderStreamMessage } from '@hotwired/turbo';
import type IndexController from './index.controller';
export default class RestrictedCommentController extends Controller {
@@ -89,10 +90,16 @@ export default class RestrictedCommentController extends Controller {
},
});
- const sanitizedNotes = await response.text();
- this.ckEditorInstance.setData(sanitizedNotes);
+ const sanitizedNotesResponse = await response.text();
+
+ if (response.ok) {
+ this.ckEditorInstance.setData(sanitizedNotesResponse);
+ } else {
+ renderStreamMessage(sanitizedNotesResponse);
+ throw new Error(`Failed to sanitize restricted mentions. Response status: ${response.status}`);
+ }
} catch (error) {
- console.error(`Failed to sanitize restricted mentions: ${error}`);
+ console.error(error);
}
}
}
diff --git a/spec/features/activities/work_package/restricted_visibility_comments_spec.rb b/spec/features/activities/work_package/restricted_visibility_comments_spec.rb
index 2f52ff9030b..2fc80533844 100644
--- a/spec/features/activities/work_package/restricted_visibility_comments_spec.rb
+++ b/spec/features/activities/work_package/restricted_visibility_comments_spec.rb
@@ -248,5 +248,23 @@ RSpec.describe "Work package comments with restricted visibility",
.to contain_exactly("Project Admin", "Restricted Viewer", "Restricted ViewerCommenter")
end
end
+
+ context "with a server error" do
+ before do
+ allow(WorkPackages::ActivitiesTab::RestrictedMentionsSanitizer).to receive(:sanitize)
+ .and_raise(RuntimeError, "Something went wrong!!!")
+ end
+
+ it "shows an error message" do
+ activity_tab.type_comment("@Restricted")
+ page.first(".mention-list-item", text: "Restricted Viewer").click
+
+ activity_tab.check_restricted_visibility_comment_checkbox
+
+ page.within_test_selector("op-primer-flash-message") do
+ expect(page).to have_text("Something went wrong!!!")
+ end
+ end
+ end
end
end