Deliver superior customer experiences with an AI-driven platform for creating and deploying cognitive chatbots
Deliver Awesome UI with the most complete toolboxes for .NET, Web and Mobile development
Automate UI, load and performance testing for web, desktop and mobile
A complete cloud platform for an app or your entire digital business
Detect and predict anomalies by automating machine learning to achieve higher asset uptime and maximized yield
Automate decision processes with a no-code business rules engine
Optimize data integration with high-performance connectivity
Connect to any cloud or on-premises data source using a standard interface
Build engaging multi-channel web and digital experiences with intuitive web content management
Personalize and optimize the customer experience across digital touchpoints
Build, protect and deploy apps across any platform and mobile device
The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
There have been quite a few requests for this particular example, and may I add, most of the angry posts regarding the developer’s manual were related to the lack of this sample. Admittedly, when I put the roadmap for this series in the manual I wasn’t going to tease you, but rather give you an idea what we are working on. Didn’t turn out that well, mostly because we couldn’t finish the samples on time – so my sincere apology to all of you. Anyhow, now that the political part of the post is over, lets dig into the code.
NOTE: Since this article is a sequential part of the series, you should make sure that you have read the first article named Simple implementation and set up your project as it was explained there. I will reference that project throughout this article.
The task in front of us is to add permissions to our products module. As opposed to other features that we were enabling on our products module, we will not need to do any modifications on the public side. In order to enable permissions we will have to do three simple things. Before I explain what exactly are we going to do, take a look at the Figure 1 to see the end result.
Figure 1: Permissions command (left) and PermissionsView (right) in the products module
So, as you can see from the Figure 1, once we are done with implementing permissions we will be able to define which roles can view, create, modify and delete products. We will also have the option to define which roles can set the permissions.
We’ll start by uncommenting the permissions command markup in the CommandPanel template. Open following file in your project: ~/Sitefinity/Admin/ControlTemplates/Products/CommandPanel.ascx
and uncomment the permissions command markup, represented by following lines:
If you have followed all the articles of this series, your command panel template should now look like this:
Now that we have enabled the permissionViewButton LinkButton, we need to attach some logic to its OnClick event which will change the ControlPanel mode to Permissions mode. Please open the following file located in your Telerik.Samples.Products project: Telerik.Samples.Products.WebControls.Admin.CommandPanel
To ease the process of development, we’ll reference the LinkButton through the property of container class, so that we can access it easily in the rest of our code (without performing recursive FindControls). Scroll down to the Container class located in the CommandPanel.cs file and add following lines to it:
Now that we can access PermissionsView button easily, let’s navigate to the CreateChildControls method of the CommandPanel class and set the behavior of the PermissionsViewButton. Add following lines of code at the end of CreateChildControls method, but before the Controls.Add(container):
In the first two lines, we are setting the command name and command that will execute when user clicks on the LinkButton. The last two lines are simply changing the css class of the PermissionsViewButton to “sel” (as in “selected”) when ControlPanel is in the Permissions mode. One last thing to do here – handle the CommandName “PermissionView” in the button_Command. Navigate to the button_Command event handler and add the case for PermissionView. When you are done, the code for button_Command should look like this:
And that ends our coding work – now that wasn’t that hard. Since the ControlPanel will now be using Permissions templates, the last thing we need to is provide these templates in the products folder by copying the from the Generic_Content folder (we can modify them later, of course). Please copy following files: ~/Sitefinity/Admin/ControlTemplates/Generic_Content/ControlPanelPermissions.ascx ~/Sitefinity/Admin/ControlTemplates/Generic_Content/App_LocalResources/ControlPanelPermissions.ascx.resx ~/Sitefinity/Admin/ControlTemplates/Generic_Content/App_LocalResources/PermissionsFAQText.txt
To these folders respectively: ~/Sitefinity/Admin/ControlTemplates/Products ~/Sitefinity/Admin/ControlTemplates/Products/App_LocalResources ~/Sitefinity/Admin/ControlTemplates/Products/App_LocalResources
And we are done. Go build your project, create few roles and users and test out the new permissions. All the permissions related work is done for you by the GenericContent module on which products module is based.
You can download the code for this project from here.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.