More in this section

Forums / Developing with Sitefinity / Permissions on a custom module (not based on generic_content)

Permissions on a custom module (not based on generic_content)

12 posts, 0 answered
  1. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    21 Aug 2009
    Link to this post
    How can i implement permissions on a custom module that was created from scratch. One that does not inherit from the generic content module.

    Is that even possible?

    Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Aug 2009
    Link to this post
    Hi Andrew,

    It is possible. Generally the module does not inherit form GenericContent module. Your module manager inherits from ContentManager and use the content based modules functionality. The module inherits from WebModule or SecuredModule.

    In your case you should inherit from SecuredModule and implement ISecuredModule members.

     
            public override Telerik.Security.Permissions.ISecured SecurityRoot 
            { 
                get 
                { 
                    return this.SecurityRoots[Configuration.ConfigHelper.Handler.DefaultProvider]; 
                } 
            } 
     
            public override IDictionary<string, ISecured> SecurityRoots 
            { 
                get 
                { 
                    return MyManager.SecurityRoots; 
                } 
            } 

    Get the global permissions for your module

     public GlobalPermissions Permissions 
            { 
                get 
                { 
                    return (GlobalPermissions)MyManager.SecurityRoots[base.Provider.Name]; 
                } 
            } 

    Create abstract methods in the provider - for delete, create, view(get) etc.

    public abstract void DeleteItem(Guid id); 

    Add the methods to MyManager class

        public void DeleteItem(Guid id) 
            { 
                this.Provider.DeleteItem(id); 
            } 

    In your control panel add logic for getting the permissions and deleting an item


          Repeater MyItems = (Repeater)sender; 
     
     
    case "delete"
                        this.manager.GetPermission(this.ItemId, CrudRights.Modify).Demand(); 
                        IListItem item = this.manager.GetItem(new Guid(e.CommandArgument.ToString())); 
                        this.manager.DeleteItem(new Guid(e.CommandArgument.ToString())); 
                        MyItems.DataBind(); 
     
    .... 
       ... 
     
    private Guid ItemId; 


    Greetings,
    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.
  3. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    25 Aug 2009
    Link to this post
    Ok, so thanks for your response.
    I am afraid i need a little bit more info than that.
    I started putting in the code you provided but have some problems with it,
    First of all i don't have a 'manager' in my project.
    So i implemented a new class for that, here is the code from it:

    using System;  
    using Telerik.Cms.Engine;  
     
    public class ClubsManager : ContentManager   
    {  
        public ClubsManager()  
        {  
            //    
        }  

    What else should it have?

    Also with regards to the

    public override Telerik.Security.Permissions.ISecured SecurityRoot    
            {    
                get    
                {    
                    return this.SecurityRoots[Configuration.ConfigHelper.Handler.DefaultProvider];    
                }    
            }   

    Where does this ConfigHelper reside. What name space do i use here? Or do i have to implement it myself. If so what goes into this class?

    I have some more questions, but i think i need to first understand the above before i move on.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Aug 2009
    Link to this post
    Hi Andrew,

    1. If you inherit from ContentManager you will use all available methods and functionality that this class exposes. Your lines actually shows creating a derive class of ContentManager which means you are going to create a Generic Content based module.

    For non Generic Content based modules you should inherit from  ManagerBase<YourProvider>. As you see your <Type> is a provider which should inherits from ProviderBase.

    2. You should create your own class ConfigHelper that reads your module <provider> configuration section.

        public class ConfigHelper 
        { 
            private static SectionHandler handler = 
                (SectionHandler)ConfigurationManager.GetSection("telerik/yourModule"); 
     
            public static SectionHandler Handler 
            { 
                get 
                { 
                    return handler; 
                } 
            } 
        } 

    Regards,
    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.
  5. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    25 Aug 2009
    Link to this post
    1. I must have missunderstood what you said in your first response. :

    It is possible. Generally the module does not inherit form GenericContent module. Your module manager inherits from ContentManager and use the content based modules functionality. The module inherits from WebModule or SecuredModule

    i therefore inherited from the contentmanager. i will change that now.
    1a. It is unclear where the "ManagerBase" is? what is the namespace i need to use in this case.
    1b. Do i need to implement a provider? What would that look like?

    2. I am guessing i also need to imlement a Sectionhandler class, is that correct?

    is this it? :

    using System.Configuration;  
     
    namespace Cint.Clubs.Configuration  
    {  
        public class SectionHandler : ConfigurationSection  
        {  
            public SectionHandler()  
            {  
            }  
     
            [ConfigurationProperty("defaultProvider"), StringValidator]  
            public string DefaultProvider  
            {  
                get 
                {  
                    return (string)base["defaultProvider"];  
                }  
                set 
                {  
                    base["defaultProvider"] = value;  
                }  
            }  
     
        }  
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Aug 2009
    Link to this post
    Hi Andrew,

    Yes you need to implement SectionHandler that inherits from ConfigurationSection. The constructor in your code could be removed, because it is not used.

    Kind regards,
    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.
  7. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    25 Aug 2009
    Link to this post
    What about the ManagerBase<YourProvider>.
    Are there any examples of how to implement the provider class i need?
  8. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    25 Aug 2009
    Link to this post
    Now i have this:

    using System.Configuration.Provider;  
     
    public class ClubsProvider : ProviderBase  
    {  
    }  
     

    using System;  
    using Telerik;  
     
    public class ClubsManager : ManagerBase<ClubsProvider>  
    {  
        public ClubsManager()  
        {  
     
        }  
     
    }  
     

    But i get an error, saying i need to implement.

    abstract methods : ProviderName, DefaultSettings and ModuleName for the manager.

    What would the implementation for those look like?
  9. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    25 Aug 2009
    Link to this post
    I tried to overwrite the abstract methods with just anything to see if it will compile.
    Like this:

    using System;  
    using Telerik;  
    using Telerik.Cms.Engine;  
     
    public class ClubsManager : ManagerBase<ClubsProvider>  
    {  
        public ClubsManager()  
        {  
              
        }  
     
        protected override System.Configuration.ProviderSettingsCollection ProvidersSettings  
        {  
            get { throw new NotImplementedException(); }  
        }  
     
        public override string DefaultProvider  
        {  
            get { throw new NotImplementedException(); }  
        }  
     
        public override string ModuleName  
        {  
            get { throw new NotImplementedException(); }  
        }  
     

    But now i get an error saying:

    Error 2 'ClubsManager' does not contain a definition for 'SecurityRoots' 

    It apears to me that this would be one of the things that every single user of sitefinity wants to do.
    What would be the point of creating modules without this functionality.
    I am suprised there are not some simple guidlines or examples for this.
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    26 Aug 2009
    Link to this post
    Hi Andrew,

    You need to add a Dictionary for your Manager.


    public static Dictionary<String, ISecured> SecurityRoots 
            { 
                get 
                { 
                    if (securityRoots == null
                    { 
                        securityRoots = new Dictionary<String, ISecured>(ClubsManager.Providers.Count); 
                        foreach (string name in ClubsManager.Providers.Keys) 
                            securityRoots.Add(name, new GlobalPermissions(name)); 
                    } 
                    return securityRoots; 
                } 
            } 
     
     private static Dictionary<String, ISecured> securityRoots; 

    Also get a list of providers

      public static IDictionary<String, ListProvider> Providers 
            { 
                get 
                { 
                    if (providers == null
                        providers = new ClubsManager().GetProviders(); 
                    return providers; 
                } 
            } 


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    26 Aug 2009
    Link to this post
    Ivan,

    I tried adding the code. My whole application started timing out and now i get this error:

    HTTP Error 503. The service is unavailable.


    I am unable to run it at all now.

    I have created a ticket (238162 ) and attached my app_code files there. Could you please have a look?
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    27 Aug 2009
    Link to this post
    Hello Andrew,

    The module should not be a problem, but I will look into the ticket and see whether the code causes any errors.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
12 posts, 0 answered