JSON Recipe Deployment Step, Tenant Feature Profiles - This week in Orchard (14/10/2021)

Gábor Domonkos's avatar
Multi-tenancy, Documentation, This week in Orchard, Recipes

A new extension method to encode redirect URLs, documentation for the image Shortcode, a new JSON Recipe deployment step, and a nice demo about the Tenant Feature Profiles feature! Don't forget to check out our current post to know more!

Orchard Core updates

JSON Recipe Deployment Step

The only way before being able to execute a custom JSON recipe step was to create a file with the recipe inside and execute the recipe. Now it's much easier, you can just paste JSON, and then you have the Monaco IntelliSense inside the editor.

To try this out, set up your site using any recipe and make sure you have the Deployment feature enabled (Configuration -> Features). Now head to Configuration -> Import/Export -> Deployment Plans and add a new deployment plan. Hit the Add Step button to add a new step to it and find the one called JSON Recipe that exports a JSON Recipe. Here we would like to disable the OrchardCore.Templates feature when someone imports this deployment package. If you execute your deployment plan, you will see that the recipe contains one step with the JSON content that we have just provided in the JSON Recipe deployment plan.

The new JSON Recipe deployment step

Document [image] Shortcode

The documentation of Orchard Core has a nice page about Shortcodes. Shortcodes are small pieces of code wrapped into [brackets] that can add some behavior to content editors, like embedding media files. Shortcodes can be implemented by enabling the Shortcode Templates feature or through code. And now, this page has a new section that describes how you can use the image Shortcode that renders an image from the site's media library.

image shortcode documentation

Encode redirect URLs

If you publish a content item (a blog post for example) with a permalink that contains non-English characters, the redirect goes to a URL where the non-English characters are encoded. Like /Admin/Contents/ContentItems/Ελληνας-ϰαὶ-δὴ-ϰαὶ-γράμματα and of course we are getting a page not found message. The fix was for that to encode the redirect URLs.

Encode redirect URLs

It has been merged but after a while, it had to be changed because the EscapeUriString method has been deprecated in .NET 6. and it was not building anymore. It was removed because it was not used correctly by users, and it was apparently buggy. The solution is there is a new custom method in Orchard Core called EscapeLocationHeader because it's a custom escape for the location headers. It's using GetComponents with custom parameters to do that. The idea is that anytime you do a redirect, the server will not accept custom characters because it contains non escaped characters, and it needs to be escaped. But not all of them need to be escaped, just the query strings, the parts that are not like slashes and equals.

The new EscapeLocationHeader method

So, if you are using the this.LocalRedirect(returnUrl, true) or the this.Redirect(returnUrl, true) extension methods, it will use the EscapeLocationHeader method to correctly escape the URL.

Using the new LocalRedirect extension method

Demos

Tenant Feature Profiles

We had a demo a few weeks ago about a feature that is about through app settings/configuration adds the ability to restrict the features and/or themes that are available to either a tenant and/or all tenants or a mix of both. This time we will see the final, merged version of this feature that you can check out any time if you clone the main branch of Orchard Core!

First of all, set up your site and enable the Tenants and the Tenant Feature Profiles features, which provides a way to manage available features for each tenant. Now head to the new option under Configuration called Tenant Feature Profiles where you can add feature profiles. Here you can set the rules that you want to use. By default, you can have an Include and an Exclude rule. By using these you can easily say that I don't want to allow the given feature for the assigned tenants or I want to allow my custom feature to the given tenants. The Expression contains the name of the feature but it can include stars like OrchardCore.*Templates that will match the OrchardCore.Templates, OrchardCore.AdminTemplates and OrchardCore.ShortCodes.Templates feature as well. Let's say that we don't want to allow the TheAgencyTheme and the features with names to start with OrchardCore. and end with .Templates.

Adding a new feature profile

Now let's create a tenant with these rules. To do that, navigate to Configuration -> Tenants and hit the Add Tenant button. The first thing that you may notice here is the new Feature Profile dropdown where you can optionally specify which feature profile should be applied to this tenant (as you can read the hint). We have one, called restricted profile, let's select that one.

Adding a new tenant with a feature profile

And it's time to set up our tenant to see what are the available features there. If you search for the text templates, you will see that the search returned no results. If you navigate to Design -> Themes and try to find the TheAgency theme, you will see that the theme is not there in the list.

The excluded templates features

Note that the Tenant Feature Profiles feature is only available for the default tenant naturally. And that's not all of that! If you would like to see more, don't forget to check out this recording on YouTube!

News from the community

.NET Community Standup - What's new in Orchard Core

The .NET Community Standups are weekly live shows, hosted by the .NET team, are casual sessions full of community content, demos, Q&A, and discussions around what's happening in .NET. Last week you could see Sébastien Ros showing you the latest improvements and features of Orchard Core. If you are new to Orchard Core or you if are a developer who hasn't worked with Orchard Core in a long time or just wants to see a nice overview about what Orchard Core can provides you with version 1.0, head to YouTube now for the recording!

Orchard Dojo Newsletter

Lombiq's Orchard Dojo Newsletter has 228 subscribers! We have started this newsletter to inform the community around Orchard with the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post is published to Orchard Dojo, including This week in Orchard of course.

Do you know of other Orchard enthusiasts who you think would like to read our weekly articles? Tell them to subscribe here!

If you are interested in more news around Orchard and the details of the topics above, don't forget to check out the recording of this week's Orchard meeting!

No Comments

Add a Comment