שגיאת רישיות ב-Route ב-private_messages_group

סיכום מבוסס בינה מלאכותית

The discussion addresses a bug where private message inboxes for groups fail to load due to a capitalization error in the URL. RGJ reports that clicking a notification for a group like ExampleGroup attempts to load /topics/private-messages-group/username/examplegroup.json, which fails because the group name is lowercase. The issue arises from ListController::generate_message_route not handling case-insensitive group name lookups. angus suggests the problem may be in the post alerter, but notes that notifications created in the console work correctly. techAPJ clarifies that the correct fix is to allow case-insensitive group name matching in URL parameters, referencing a commit that implements this change. The issue is confirmed to be related to the URL generation for private message groups, and the community acknowledges the bug and the proposed solution.

I am not very familiar with private group inboxes and I’m not sure how to reproduce this but the following is happening:

  • A private message inbox has been set up for a group, let’s call it ExampleGroup.
  • A member of that group gets a notification ‘there are 6 messages in your examplegroup inbox’
  • Clicking that notification tries to load /topics/private-messages-group/username/examplegroup.json
  • This gives an error

I think this is happening because there is no group called examplegroup. The group is called ExampleGroup.

ListController::generate_message_route does this:

group = Group.find_by(name: params[:group_name])

changing this to

group = Group.find_by(name: params[:group_name])
group = Group.where('lower(name) = ?', params[:group_name].downcase).first unless group

seems to resolve the issue. But I’m sure that is not the actual problem. Somewhere the parameter is converted to lower case where it should not be (I think…).

Does anyone have any suggestion where to look?

3 לייקים

If you just create notifications directly in the console, the link respects capitalization (this works even if the data is fake)

Notification.create!(
  user_id: 1,
  notification_type: Notification.types[:group_message_summary],
  data: { inbox_count: 5, group_name: "MyGroup", group_id: 41, username: 'angus' }.to_json
)

The issue may on the creation side of things, i.e. in the post alerter: discourse/app/services/post_alerter.rb at main · discourse/discourse · GitHub

However, I can’t seem to repro this one.

לייק 1

Thanks for your help! But that’s not the correct link,

it’s not /u/username/messages/group/groupname
but /topics/private-messages-group/username/groupname.

I cannot find where the last one is coming from and how to generate it.

2 לייקים

I believe the correct fix here is to not require capitalized group name in URL params. Done via:

https://github.com/discourse/discourse/commit/af6d0342b642feac3a5e359d13c854d2a80145b6

Note that browsing to /u/username/messages/group/groupname will fire an AJAX request to /topics/private-messages-group/username/groupname, so what @angus did above to debug this issue does look correct.

Thanks for reporting this issue @RGJ :+1:

5 לייקים