discourse/spec/support
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
..
versioning Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
bookmarkable_helper.rb FIX: Allow .ics for polymorphic bookmarks (#16694) 2022-05-11 09:29:24 +10:00
common_basic_reviewable_serializer.rb DEV: Include pending reviewables in the main tab in the user menu (#18471) 2022-10-05 12:30:02 +03:00
concurrency.rb Revert "FIX: Redis fallback handler refactoring (#8771)" (#8776) 2020-01-24 09:20:17 +11:00
diagnostics_helper.rb DEV: use #frozen_string_literal: true on all spec 2019-04-30 10:27:42 +10:00
discourse_event_helper.rb DEV: Refactor user_badge_granted DiscourseEvent logic (#17579) 2022-07-22 09:06:02 +08:00
fake_logger.rb Build(deps-dev): Bump rspec-rails from 5.1.2 to 6.0.0 (#18534) 2022-10-12 20:25:49 +02:00
fake_s3.rb DEV: Run some specs with fake S3 implementation instead of stubs 2022-06-28 21:27:52 +02:00
fast_image_helpers.rb FIX: remove 'crawl_images' site setting (#14646) 2021-10-19 17:12:29 +05:30
final_destination_helper.rb SECURITY: Expand and improve SSRF Protections (#18815) 2022-11-01 16:33:17 +00:00
helpers.rb DEV: Remove usages of enable_personal_messages (#18437) 2022-10-05 10:50:20 +10:00
imap_helper.rb DEV: Move imap_helper to spec/support directory (#14776) 2021-10-29 20:46:25 +02:00
integration_helpers.rb FEATURE: Allow using invites when DiscourseConnect SSO is enabled (#12419) 2021-03-19 10:20:10 +10:00
match_html_matcher.rb FIX: Make Oneboxer#apply insert block Oneboxes correctly (#11449) 2020-12-14 17:49:37 +02:00
mock_git_importer.rb SECURITY: Expand and improve SSRF Protections (#18815) 2022-11-01 16:33:17 +00:00
negated_matcher.rb DEV: Don’t use `change { … }.by(0)` in specs 2022-07-26 10:34:15 +02:00
onebox_helpers.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
rate_limit_matcher.rb DEV: use #frozen_string_literal: true on all spec 2019-04-30 10:27:42 +10:00
session_controller_helper_routes.rb FEATURE: Centralized 2FA page (#15377) 2022-02-17 12:12:59 +03:00
shared_examples_for_stats_cacheable.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
sidekiq_helpers.rb DEV: Change Topic Timer from enqueue_at scheduled jobs to incrementally executed jobs (#11698) 2021-01-19 13:30:58 +10:00
site_settings_helpers.rb DEV: use #frozen_string_literal: true on all spec 2019-04-30 10:27:42 +10:00
system_helpers.rb FEATURE: Generic hashtag autocomplete lookup and markdown cooking (#18937) 2022-11-21 08:37:06 +10:00
test_second_factor_action.rb FEATURE: Add 2FA support to the Discourse Connect Provider protocol (#16386) 2022-04-13 15:04:09 +03:00
time_matcher.rb DEV: adds within_one_minute time matcher (#12109) 2021-02-17 10:52:49 +01:00
topic_guardian_can_see_consistency_check.rb DEV: Introduce TopicGuardian#can_see_topic_ids method (#18692) 2022-10-27 06:13:21 +08:00
uploads_helpers.rb DEV: TODO followups (#18936) 2022-11-09 07:48:05 +10:00
user_sidebar_tags_mixin.rb UX: Hide tags section in sidebar when user has no visible tags (#18539) 2022-10-13 08:37:28 +08:00
webauthn_integration_helpers.rb DEV: stop freezing frozen strings 2020-04-30 16:48:53 +10:00