Skip to content

Define user @mention criterion for work package comments with restricted visibility #18409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

akabiru
Copy link
Member

@akabiru akabiru commented Mar 22, 2025

Ticket

https://community.openproject.org/wp/60988

What are you trying to accomplish?

  • It should not be possible to @mention users who will not be able to view the comment with restricted visibilty (i.e, the drop-down needs to exclude users without the requisite permissions)
  • If a user who does not have the permissions to view restricted-visibility comments is mentioned in a regular comment and the 'Restrict visibility' checkbox is then checked, the @mention is turned into plain text. Unchecking the "Restrict visibility" checkbox will not re-convert previously stripped @mentions back to links.
  • Cover edit case

Screenshots

restricted-mentions.mp4

What approach did you choose and why?

Introduce a sanitization endpoint on the server side that converts users mentions that do not have restricted visibility permissions- the functionality is further applied in create/update of comments.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@akabiru akabiru changed the title Define @mention criterion for restricted comments- blueprint Define @mention criterion for work package comments with restricted visibility Mar 22, 2025
@akabiru akabiru changed the title Define @mention criterion for work package comments with restricted visibility Define user @mention criterion for work package comments with restricted visibility Mar 22, 2025
akabiru added 10 commits March 24, 2025 20:15
MentionableOnWorkPackageFilter does not depend solely on permissions, rather on project membership
whilst RestrictedMentionableOnWorkPackageFilter depends solely on a permission- hence we cannot
easily reuse the `User.allowed_members_on_work_package(action, project)` method that would indeed be
more concise- it's possible this can be revisitted in the near future
The downside is that if the user has both an edit editor open and one adding a comment, the restriction prevails
so they would not be able to mention non restricted users. Unless they close out the restricted editor. This is mainly
because we are using a singular function to retrieve the mentions- the could be a better way that I didn't yet think about
but my reckoning is this is a rare edge case- and I much prefer the secure by default approach
@akabiru akabiru force-pushed the implementation/60988-define-mention-criterion-for-work-package-comments-with-restricted-visibility branch from b557b50 to 5d34f9b Compare March 25, 2025 20:17
@akabiru akabiru added this to the 15.5.x milestone Mar 25, 2025
@akabiru akabiru self-assigned this Mar 25, 2025
# See COPYRIGHT and LICENSE files for more details.
# ++

class Queries::Principals::Filters::RestrictedMentionableOnWorkPackageFilter <
Copy link
Member Author

@akabiru akabiru Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulferts I did not manage to easily extend the current MentionableOnWorkPackageFilter:

d00cda7 MentionableOnWorkPackageFilter does not depend solely on permissions, rather on project membership whilst RestrictedMentionableOnWorkPackageFilter depends primarily on a permission- hence we cannot easily reuse the User.allowed_members_on_work_package(action, project) method that would indeed be more concise- it's possible this can be revisited in the near future

Copy link
Member Author

@akabiru akabiru Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, we will not be able to use the User.allowed_members_on_work_package(action, project) on the restricted filter too after all in it's current shape, as it excludes Groups- which are valid mentions. The resulting query is also much simpler. This perhaps explains why the MentionableOnWorkPackageFilter did also not use it.

cc75dc1

@akabiru akabiru marked this pull request as ready for review March 26, 2025 07:00
@akabiru akabiru requested a review from ulferts March 26, 2025 07:00
Once more relying on the User.allowed_members_* helper did not fit the bill as we need to
also include Groups in mentionables which are direct decendants of Principal- the resulting
query is also much simpler and loosely decoupled- so I favour retaining this approach for
the time being.

Follows: d00cda7
@akabiru akabiru force-pushed the implementation/60988-define-mention-criterion-for-work-package-comments-with-restricted-visibility branch from 941c26c to cc75dc1 Compare March 26, 2025 13:39
@akabiru akabiru requested a review from Kharonus March 28, 2025 08:04
@akabiru akabiru requested a review from Kharonus April 1, 2025 04:30
@akabiru
Copy link
Member Author

akabiru commented Apr 3, 2025

Gentle nudge @Kharonus to have another look :)

@akabiru akabiru modified the milestones: 15.5.x, 16.0.x Apr 3, 2025
@akabiru akabiru requested a review from brunopagno April 3, 2025 07:27
Copy link
Member

@Kharonus Kharonus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can approve from my perspective.

Question is, is this enough :D As I have few insight in most of the previous discussions around restricted visibility for comments and the underlying permissions.

@akabiru
Copy link
Member Author

akabiru commented Apr 3, 2025

I can approve from my perspective.

Question is, is this enough :D As I have few insight in most of the previous discussions around restricted visibility for comments and the underlying permissions.

Thanks! Still a useful perspective, @brunopagno / @ulferts can top up the review before merge. There's no huge rush on it albeit going stale.

Copy link
Contributor

@brunopagno brunopagno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes look good, nothing called my attention as potentially problematic. So all good there.

But when I was testing locally I was able to get an error like this (likely caused by the state of my local environment):

image

It happened because I got a POST 500 on /work_packages/41/activities/sanitize_restricted_mentions.

I think we need to make sure the errors are not exposed to the client.

@akabiru
Copy link
Member Author

akabiru commented Apr 4, 2025

The code changes look good, nothing called my attention as potentially problematic. So all good there.

But when I was testing locally I was able to get an error like this (likely caused by the state of my local environment):

image

It happened because I got a POST 500 on /work_packages/41/activities/sanitize_restricted_mentions.

I think we need to make sure the errors are not exposed to the client.

Really nice catch! It would seem the try, catch does not work as intended- will add a test case for this 👍🏾

Comment on lines 82 to 95
try {
const response = await fetch(sanitizePath, {
method: 'POST',
body: JSON.stringify({ journal: { notes: editorData } }),
headers: {
'X-CSRF-Token': csrfToken,
'Content-Type': 'application/json',
},
});

const sanitizedNotes = await response.text();
this.ckEditorInstance.setData(sanitizedNotes);
} catch (error) {
console.error(`Failed to sanitize restricted mentions: ${error}`);
Copy link
Contributor

@brunopagno brunopagno Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akabiru now that you pointed out this is indeed wrong. The try catch block will capture exceptions, but not responses with errors. I think we need to explicitly handle with a response.ok check here.

Copy link
Member Author

@akabiru akabiru Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @brunopagno - handled in 22cc675 via primer banner. I would have wished to display the error closer to the comment box- and perhaps even transition the ckeditor input into an error state, but it doesn't seem like we have this convention atm (with ckeditor input)- perhaps an enhancement to discuss with UX and apply in the future.

The screenshot is from manual testing by raising an StandardError

Screenshot 2025-04-04 at 4 33 36 PM

@akabiru akabiru requested a review from brunopagno April 4, 2025 14:01
Copy link
Contributor

@brunopagno brunopagno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great 🎉

@akabiru akabiru merged commit 8784355 into dev Apr 4, 2025
18 checks passed
@akabiru akabiru deleted the implementation/60988-define-mention-criterion-for-work-package-comments-with-restricted-visibility branch April 4, 2025 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants