1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to give rights to News section category wise?

How to give rights to News section category wise?

2 posts, 0 answered
  1. Nisha
    Nisha avatar
    17 posts
    Registered:
    17 Jun 2009
    23 Jul 2009
    Link to this post
    hi,
        I am using a CustomNewsView control to display the news on the site.The site requirment is that , only the specified user can have aceess to add/create/edit/delete the news in specific category. Every news category has a seperate user to create/modify it.  The user can have rights only to the category  that is given to him.
        Is it possible to give rights to user only to specific category of the News section. Waiting for reply.

    Thank you
    Nisha
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Jul 2009
    Link to this post
    Hi Nisha,

    The set some restrictions over categories you need to create a custom view and replace the default one.
    Then you need to override CategoriesTreeView_NodeDataBound method and add custom logic for restricting the categories.

    Sample code:

    using System; 
    using System.Collections; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.Cms.Engine.WebControls.Admin; 
    using Telerik.News.WebControls.Admin; 
    using Telerik.Cms.Engine; 
    using Telerik.Security; 
     
    /// <summary> 
    /// Summary description for CustomNewsCategoriesView 
    /// </summary> 
    public class CustomNewsCategoriesView : CategoriesView<NewsControlPanel> 
        public CustomNewsCategoriesView() 
        { 
        } 
     
        public override string LayoutTemplatePath 
        { 
            get 
            { 
                return"~/Sitefinity/Admin/ControlTemplates/News/CategoriesView.ascx"; 
            } 
        } 
     
        public override Type AssemblyInfo 
        { 
            get 
            { 
                return typeof(NewsControlPanel); 
            } 
            set 
            { 
                base.AssemblyInfo = value; 
            } 
        } 
     
        protected override string LayoutTemplateName 
        { 
            get 
            { 
                return "CategoriesView"
            } 
        } 
        public override string Name 
        { 
            get 
            { 
                return "CategoriesView"
            } 
            set 
            { 
                base.Name = value; 
            } 
        } 
     
        public override Type LocalizationAssemblyInfo 
        { 
            get 
            { 
                return typeof(NewsControlPanel); 
            } 
            set 
            { 
                base.LocalizationAssemblyInfo = value; 
            } 
        } 
     
        protected override void CategoriesTreeView_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) 
        { 
            base.CategoriesTreeView_NodeDataBound(sender, e); 
            ICategory category = (ICategory)e.Node.DataItem; 
            IList categoryTree = this.Host.Manager.GetCategoriesTree(category); 
     
            if(UserManager.IsCurrentUserInRole("administrators") && e.Node.Text.Equals("a")) 
            { 
                e.Node.Visible = false
            } 
        } 
     
        protected override void RedirectOnOpenContent(string filterExpr) 
        { 
            NavigateHostCommand<NewsItemsView>(filterExpr); 
        } 
       
     


    For the grid view - when all items are listed we use client side binding with web services. There you can add logic for disabling editing or deleting of the items.

    Sample code:

      protected void Page_Load(object sender, EventArgs e) 
        { 
            if (Telerik.Security.UserManager.IsCurrentUserInRole("userGroup")) 
            { 
                ClientTemplate cTemplae = FindControlRecursive(GridTemplates, "test"as ClientTemplate; 
                cTemplae.Visible = false
            } 
                 
             
        } 
        private Control FindControlRecursive(Control root, string id) 
        { 
            if (root.ID == id) 
            { 
                return root; 
            } 
     
            foreach (Control c in root.Controls) 
            { 
                Control t = FindControlRecursive(c, id); 
                if (t != null
                { 
                    return t; 
                } 
            } 
     
            return null
        }  


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered