Skip to content
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

Allow custom routes to be picked up by community links template #1258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

monotasker
Copy link

@monotasker monotasker commented Dec 6, 2024

❤️ Thank you for your contribution!

Description

Currently changes to routes via the COMMUNITIES_ROUTES config variable do not affect the urls in the "links" property of community record results. This PR offers a fix which allows the community links template to pick up custom routes from the config variable.

There are two challenges to solving this issue:

  1. The config variables are not available to the CommunityServiceConfig when it is being initialized
  2. The COMMUNITIES_ROUTES url templates use a different templating format than the links template does

I've attempted to solve #1 by delaying the actual creation of the link strings until after the app has been initialized and the config variables are available. Rather than building the link strings when CommunityServiceConfig is initialized, I move the link string construction into a factory class method. The service config links_item property becomes a callable instead of a static dictionary. That factory class method is then called during the dumping of records to result objects (when service.links_item_tpl is called and instantiates a CommunityLinksTemplate). Since current_app is available at that point, we can draw in the required COMMUNITIES_ROUTES variables.

I also include in the factory class some string conversion logic that converts the routes strings to the templating format used by the links template.

This may not be the ideal solution to this problem in the long run, but it does solve the problem and does so while allowing the COMMUNITIES_ROUTES to be a single source of truth for overridden routes.

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant