Allow custom routes to be picked up by community links template #1258
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
❤️ 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:
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). Sincecurrent_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: