AI OnAI Off
Hi!
This is my best guess without actually implementing anything myself.
You should create your own sub class for IFrameComponentAttribute and override the method CreateComponentDefinition().
Call base.CreateComponentDefinition(componentType) and add your restrictions the AllowedRoles property.
Please let us know if it works and share the code!
Hi Fredrik!
Thanks for the advice, it worked. Here is the code:
public class IFrameComponentWithAuthorization : IFrameComponentAttribute
{
public string AllowedRoles { get; set; }
public override IComponentDefinition CreateComponentDefinition(Type attributedType)
{
var componentDefinition = base.CreateComponentDefinition(attributedType);
if (AllowedRoles != null)
{
var allowedRoles = AllowedRoles.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();
typeof(PluggableComponentDefinitionBase).GetProperty("AllowedRoles").SetValue(componentDefinition, allowedRoles, null);
}
return componentDefinition;
}
}
And the widget:
[IFrameComponentWithAuthorization(Url = "~/modules/Translation/Views/TranslationGadget.aspx",
ReloadOnContextChange = true, PlugInAreas = "/episerver/cms/mainnavigation", Title = "My Translation",
Categories = "cms", AllowedRoles = "Administrators, TranslationEditors", MinHeight = 130, MaxHeight = 500)]
public partial class TranslationGadget: Page
{
...
}
Thank you!
Hi!
This feature has now been added to the base attribute and will be released within a few weeks.
I have created the following widget:
[IFrameComponent(Url = "~/modules/Translation/Views/MyTranslationWidget.aspx",
ReloadOnContextChange = true,
PlugInAreas = "/episerver/cms/mainnavigation",
Title = "My Translation",
Categories = "cms",
MinHeight = 130,
MaxHeight = 500)]
public partial class MyTranslationWidget : Page
{
...
}
How to show it only to specific user groups?