discourse/spec/requests
Martin Brennan d3f02a1270
FEATURE: Generic hashtag autocomplete lookup and markdown cooking (#18937)
This commit fleshes out and adds functionality for the new `#hashtag` search and
lookup system, still hidden behind the `enable_experimental_hashtag_autocomplete`
feature flag.

**Serverside**

We have two plugin API registration methods that are used to define data sources
(`register_hashtag_data_source`) and hashtag result type priorities depending on
the context (`register_hashtag_type_in_context`). Reading the comments in plugin.rb
should make it clear what these are doing. Reading the `HashtagAutocompleteService`
in full will likely help a lot as well.

Each data source is responsible for providing its own **lookup** and **search**
method that returns hashtag results based on the arguments provided. For example,
the category hashtag data source has to take into account parent categories and
how they relate, and each data source has to define their own icon to use for the
hashtag, and so on.

The `Site` serializer has two new attributes that source data from `HashtagAutocompleteService`.
There is `hashtag_icons` that is just a simple array of all the different icons that
can be used for allowlisting in our markdown pipeline, and there is `hashtag_context_configurations`
that is used to store the type priority orders for each registered context.

When sending emails, we cannot render the SVG icons for hashtags, so
we need to change the HTML hashtags to the normal `#hashtag` text.

**Markdown**

The `hashtag-autocomplete.js` file is where I have added the new `hashtag-autocomplete`
markdown rule, and like all of our rules this is used to cook the raw text on both the clientside
and on the serverside using MiniRacer. Only on the server side do we actually reach out to
the database with the `hashtagLookup` function, on the clientside we just render a plainer
version of the hashtag HTML. Only in the composer preview do we do further lookups based
on this.

This rule is the first one (that I can find) that uses the `currentUser` based on a passed
in `user_id` for guardian checks in markdown rendering code. This is the `last_editor_id`
for both the post and chat message. In some cases we need to cook without a user present,
so the `Discourse.system_user` is used in this case.

**Chat Channels**

This also contains the changes required for chat so that chat channels can be used
as a data source for hashtag searches and lookups. This data source will only be
used when `enable_experimental_hashtag_autocomplete` is `true`, so we don't have
to worry about channel results suddenly turning up.

------

**Known Rough Edges**

- Onebox excerpts will not render the icon svg/use tags, I plan to address that in a follow up PR
- Selecting a hashtag + pressing the Quote button will result in weird behaviour, I plan to address that in a follow up PR
- Mixed hashtag contexts for hashtags without a type suffix will not work correctly, e.g. #ux which is both a category and a channel slug will resolve to a category when used inside a post or within a [chat] transcript in that post. Users can get around this manually by adding the correct suffix, for example ::channel. We may get to this at some point in future
- Icons will not show for the hashtags in emails since SVG support is so terrible in email (this is not likely to be resolved, but still noting for posterity)
- Additional refinements and review fixes wil
2022-11-21 08:37:06 +10:00
..
admin FIX: Ensure moderators_manage_categories_and_groups is respected (#18884) 2022-11-11 11:06:05 +00:00
api FEATURE: Generic hashtag autocomplete lookup and markdown cooking (#18937) 2022-11-21 08:37:06 +10:00
about_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
application_controller_spec.rb Revert "Revert "FEATURE: Preload resources via link header (#18475)" (#18511)" (#18531) 2022-10-11 20:11:44 -03:00
associate_accounts_controller_spec.rb DEV: Automatically require 'rails_helper' in all specs (#16077) 2022-03-01 17:50:50 +00:00
badges_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
bookmarks_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
bootstrap_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
categories_controller_spec.rb FIX: Welcome topic should be hidden on the /categories page as well (#18869) 2022-11-07 09:24:55 -07:00
clicks_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
composer_messages_controller_spec.rb FEATURE: add composer warning when user haven't been seen in a long time (#18340) 2022-09-27 22:06:40 +05:30
csp_reports_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
directory_columns_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
directory_items_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
do_not_disturb_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
drafts_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
email_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
embed_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
exceptions_controller_spec.rb FEATURE: Add page title to 404 pages (#16846) 2022-05-17 18:37:43 +03:00
export_csv_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
extra_locales_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
finish_installation_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
forums_controller_spec.rb DEV: New readonly mode. Only applies to non-staff (#16243) 2022-05-17 13:06:08 -05:00
groups_controller_spec.rb DEV: Remove remaining hardcoded ids (#18735) 2022-10-25 15:29:09 +08:00
hashtags_controller_spec.rb FEATURE: Generic hashtag autocomplete lookup and markdown cooking (#18937) 2022-11-21 08:37:06 +10:00
inline_onebox_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
invites_controller_spec.rb FIX: Invite redemption error if user had already redeemed (#19070) 2022-11-17 15:51:58 +10:00
list_controller_spec.rb UX: Hide welcome topic from admins as well if not edited (#18807) 2022-11-01 16:17:17 -06:00
metadata_controller_spec.rb DEV: Automatically require 'rails_helper' in all specs (#16077) 2022-03-01 17:50:50 +00:00
notifications_controller_spec.rb DEV: Include pending reviewables in the main tab in the user menu (#18471) 2022-10-05 12:30:02 +03:00
offline_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
omniauth_callbacks_controller_spec.rb Use service account credentials for fetching google hd groups (#18329) 2022-10-13 16:04:42 +01:00
onebox_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
permalinks_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
post_action_users_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
post_actions_controller_spec.rb FEATURE: Introduce personal_message_enabled_groups setting (#18042) 2022-09-26 13:58:40 +10:00
post_readers_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
posts_controller_spec.rb FIX: Exclude hidden topic posts and small actions from the RSS feed. (#18649) 2022-10-18 15:19:54 -03:00
presence_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
published_pages_controller_spec.rb DEV: Rename secure_media to secure_uploads (#18376) 2022-09-29 09:24:33 +10:00
push_notification_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
qunit_controller_spec.rb DEV: Add test-site-settings to asset pipeline (#18935) 2022-11-08 11:54:25 +10:00
reviewable_claimed_topics_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
reviewables_controller_spec.rb DEV: Fix mocha deprecations (#18828) 2022-11-02 10:47:59 +01:00
robots_txt_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
safe_mode_controller_spec.rb DEV: Automatically require 'rails_helper' in all specs (#16077) 2022-03-01 17:50:50 +00:00
search_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
session_controller_spec.rb UX: better email login pages (#19058) 2022-11-17 13:09:39 +05:30
similar_topics_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
site_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
sitemap_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
static_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
steps_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
stylesheets_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
svg_sprite_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
tag_groups_controller_spec.rb DEV: Automatically require 'rails_helper' in all specs (#16077) 2022-03-01 17:50:50 +00:00
tags_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
theme_javascripts_controller_spec.rb DEV: Fix a theme_js spec (#19043) 2022-11-16 16:12:17 +08:00
topics_controller_spec.rb FIX: Remove public topic invite functionality (#18488) 2022-10-10 19:21:51 +03:00
uploads_controller_multisite_spec.rb DEV: Rename secure_media to secure_uploads (#18376) 2022-09-29 09:24:33 +10:00
uploads_controller_spec.rb DEV: Rename secure_media to secure_uploads (#18376) 2022-09-29 09:24:33 +10:00
user_actions_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
user_api_keys_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
user_avatars_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
user_badges_controller_spec.rb SECURITY: Restrict display of topic titles associated with user badges (#18768) 2022-10-27 11:26:14 +08:00
user_status_controller_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
users_controller_spec.rb FEATURE: API to update user's discourse connect external id (#19085) 2022-11-18 11:37:21 -03:00
users_email_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
webhooks_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
wizard_controller_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00