Show Hide Content Blocks By Permission

Posted by Community Admin on 04-Aug-2018 00:27

Show Hide Content Blocks By Permission

All Replies

Posted by Community Admin on 08-Oct-2013 00:00

Hello,
I'd like to show hide my content blocks by permission, ie, certain users could see some content blocks while other roles or users can see all content blocks. Is this possible? If not, is there an alternative or the potential to expand widget?

Posted by Community Admin on 08-Oct-2013 00:00

Warning!! I did not test this.  I created a class file in a folder called Custom in the webapp root.  The public string Roles should allow you to enter a comma separated list of allowed roles from the advanced section of the widget. You will also need to go into the toolboxes and override the ContentBlock widget in the toolboxes area. (see Screen Shot)

using System;
using System.Linq;
using Telerik.Sitefinity.Modules.GenericContent.Web.UI;
using Telerik.Sitefinity.Security.Claims;
using Telerik.Sitefinity.Security;
 
namespace SitefinityWebApp.Custom
    public class ContentBlockOverride : ContentBlock
    
        protected string _roles = "Everyone";
        public string Roles
        
            get return this._roles;
            set this._roles = value;
        
 
        protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
        
            base.InitializeControls(container);
            bool inRole = false;
            RoleManager roleManager = RoleManager.GetManager();
            var identity = ClaimsManager.GetCurrentIdentity();
            string[] _roles = Roles.Split(',');
            var role = roleManager.GetRoles().Where(r => r.Name == _roles[0].Trim()).FirstOrDefault();
            if (role != null)
            
               inRole = roleManager.IsUserInRole(identity.UserId, role.Id);
            
 
            this.Visible = inRole;
        
    

Posted by Community Admin on 03-Jul-2014 00:00

Hi,

 I have one content block and one custom module widget on page to show news. I have to show only one of them based on,which type of news admin wants to show. If admin wants the news from content block then widget should be hidden and vice versa. Can anyone help me on this, how I can take admin's choice of which news section to choose and how to hide other news section based on his choice.

For better understanding of my question screenshot of page is attached here.

Thanks,

Tejal Satre

Posted by Community Admin on 07-Jul-2014 00:00

Hello Tejal,

For clarification and simplicity we have answered you in this forum thread which is more related to your question. Please, continue communication in it.

Regards,
Nikola Zagorchev
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed