More in this section

Forums / Developing with Sitefinity / Expose information based on Username or Roles

Expose information based on Username or Roles

8 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    28 Aug 2008
    Link to this post
    Hi,

    I need to develop one Generic Module that expose d'information based on Roles or Username. I have read some user solutions, like create one new provider and secure by differential Roles, but is realistic for small organisations or provider, but could you imagine more than >200 providers?in one module.
    Could you explain how to build one Generic Module that expose the information in the Admin Dashboard based on Username/Roles. It's a personalized Module where each user have own personal information and it's not able to see other user information.

    Any others experiences in this way?

    Regards
  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    01 Sep 2008
    Link to this post
    Hi Pierre,

    While we do have Personalization framework (which is unfortunately pending to be documented), the bigger problem is in the Generic Content API at the moment. We are working on the new advanced Generic Content API which should be released in Sitefinity 4.0. Once we implement the new API and document about the Personalization Framework, the solution to your problem will be quite trivial. In the meantime...

    I suggest you add one or two new metafields to your Generic Content module ("OwnerUsername" and "OwnerRole" - make them invisible and set them programmatically). Then, you should extend the DefaultProvider of Generic Content module (Telerik.Cms.Engine.Data.Providers.DefaultProvider) and implement several new GetContent methods which will return content based on the username and role. Essentially, you would be adding the personalization feature to the Generic Content module. While not the simplest thing to do I don't think you would have any problems in doing so.

    I hope you'll find this information helpful. Let us know if there is anything else we can do for you.

    Regards,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    01 Sep 2008
    Link to this post
    Hi Ivan,

    Could you help us to extend the Telerik.Cms.Engine.Data. Providers.DefaultProvider in dev blog for User and Roles or helping with some code in this way. Thanks.
    .
  4. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    01 Sep 2008
    Link to this post
    Hi Pierre,

    We will surely have some samples in the Developers Manual soon, but until then... it is really nothing complicated. Here are the steps you should do:

    1. Create a new class in App_Code folder - name it e.g. PersonalizedGCProvider
    2. Inherit from Telerik.Cms.Engine.Data.Providers.DefaultProvider class
    3. Add one method to that class e.g. GetUsersContent(string userName)
    4. Call one of the base GetContent methods and create the MetaFilter for user name based on the parameter you've received - then return the list of IContent objects that base class returned you. Here is the list of GetContent method overloads you can use:
    http://www.sitefinity.com/help/developer-manual/content-items-get.html
    Choose the one you find most suitable.
    5. In the web.config replace the provider with your new provider. For example if you want this for Generic_Content this is how it should look like (more or less):
    <add name="Generic_Content"   
                 urlRewriteFormat="[Publication_Date]/[Title].aspx"   
                 urlDateTimeFormat="yy-MM-dd"   
                 urlWhitespaceChar="_"   
                 visible="True"   
                 defaultMetaField="Name"   
                 securityProviderName=""   
                 allowLocalization="False"   
                 allowVersioning="True"   
                 allowWorkflow="False"   
                 allowComments="true"   
                 commentsModeration="true"   
                 versioningProviderName=""   
                 connectionStringName="GenericContentConnection"   
                 type="PersonalizedGCProvider, App_Code"/> 

    I hope you'll find this information helpful. If you get stuck somewhere along the way, send us the code you come up with and we'll take a look.

    Kind regards,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    01 Sep 2008
    Link to this post

    Hi,

    Great, I understand the steps but i need some complementary help to obtain the result. Could you help me with the app_code. Regards

     

     

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    02 Sep 2008
    Link to this post
    Hi Pierre,

    Here is an example that we created for you.

    public partial class newprovider : Telerik.Cms.Engine.Data.Providers.DefaultProvider 
        protected IList GetUsersContent(string userName) 
        { 
            // create list that contains filters 
            List<Telerik.Cms.Engine.IMetaSearchInfo> filter = new List<Telerik.Cms.Engine.IMetaSearchInfo>(); 
            // add a new filter to the list 
            filter.Add(new Telerik.Cms.Engine.MetaSearchInfo(Telerik.Cms.Engine.MetaValueTypes.ShortText, "Name""Name", Telerik.Cms.Engine.SearchCondition.Like)); 
            // get content items filtered by specified filters and ordered descendingly 
            IList listOfContentItems = base.GetContent(0, 0, "Name DESC"string.Empty, nullnull, filter); 
            return listOfContentItems; 
        } 
    }
     
    It is really difficult for us to figure out how you want this works without even a scratch. So, we need to see your code and we are not able to provide you with an entire custom solution. We will be pleased to assist you with particular questions and ordinary samples.

    Hope this gives you some light.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    12 Sep 2008
    Link to this post
    Hi Ivan,

    I tried but I'm not able to make. I searching to create a custom provider to use in the News Module or breaking news as sample. This custom provider that implement one solution like sent is able to allow to see the articles only for the owner of this article in Admin side. The user are allowed to post news, but can't see or modify the post make by others user in the same provider only other role can see. We use 2 roles Writers, Editors. Writers can post but only see our post, Editors can see all post. 
    You have suggest to crete one metafields to store the owner (Name) as hidden and define programmatically when the news is created using some codebehind. After implement the new provider as app_code and some getcontent passing the Userowner as variable. Could you help me little more. How can pass the Name (metafields) to GetUsersContent(string userName)
    I don't understand how my standard generic module can demand this. I need override some standard class?

    Regards
  8. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    17 Sep 2008
    Link to this post
    Hi Pierre,

    You can pass the metafield value to the GetContent method with a filter. Please take a look at the source we have provided:
    filter.Add(new Telerik.Cms.Engine.MetaSearchInfo(Telerik.Cms.Engine.MetaValueTypes.ShortText, "Name""Name", Telerik.Cms.Engine.SearchCondition.Like));  

    You pass the filter to the GetContent method:

    IList listOfContentItems = base.GetContent(0, 0,
        "Name DESC"
    string.Empty,
         null
    nullfilter);  

    Best wishes,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
8 posts, 0 answered