Permission on custom field in Sitefinity 4.x
We need to add custom fields to existing and custom modules, also need different permission on those fields for different role, Sitefinity 4.0 document mentioned this as a new feature, but I could not find any document or guide to do this? Is this feasible in Sitefinity 4?
Hello Qian,
We do not have implementation for setting permissions based on a custom filed. This is in our TODO list. What you can do is creating a custom field control which editable are you disable based on the current role.
Regards,
Ivan Dimitrov
the Telerik team
Hi Ivan,
Thanks for the reply. I am having difficulty in following the sample code in the blog to create Custom field and I have followed the code of Image selector blog and it didn't work with 4.1 SP1.
Could you give some more detail steps on how to create custom field which can be used in Module backend? This seems to be the same fields we need to use in creating custom module by inserting these fields to the definition class.
Here seems to be the steps need to be done
1. Create the control ( .ascx file) Question here: I am not exactly sure why we need to create ConditionalTemplateContainer and sitefinity:ConditionalTemplate and how this is used? Do you have some documentation to explain this?
2. Create the corresponding .cs file
3. Create FieldDefinition class derived from TextFieldDefinition
4. Create FieldElement class derived from TextFieldDefinitionElement
The latter 2 parts do not seem to have custom code in them.
It would be great if you can give step by step example with explanation. I am seeing a lot of confusion in the forum and not be able to find a working example.
Thanks.
Qian
Hi Qian,
First, it depends on whether you need a completely custom field control or there is a built-in control that you can use. For example we have ChoiceField, TextField etc control swhich supports several modes of rendering. You can easily override this control and populate with with data then disable the text area of this field based on the users' role.
sample
1. Create a custom class that inherits from TextField ( if you have a custom filed control, you should be able to use it directly)
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Telerik.Sitefinity.Web.UI.Fields;
using
System.Web.UI;
namespace
Telerik.Sitefinity.Samples
public
class
TextFieldCustom : TextField
public
TextFieldCustom()
protected
override
void
InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
base
.InitializeControls(container);
this
.TextBoxControl.Enabled =
false
;
protected
override
string
LayoutTemplateName
get
return
TextFieldCustom.layoutTempalte;
public
override
IEnumerable<System.Web.UI.ScriptDescriptor> GetScriptDescriptors()
var descriptors =
base
.GetScriptDescriptors();
var descriptor = (ScriptControlDescriptor)descriptors.Last();
descriptor.Type =
typeof
(TextField).FullName;
return
descriptors;
private
const
string
layoutTempalte =
"Telerik.Sitefinity.Samples.Resources.TextField.ascx"
;
this
.TextBoxControl.Enabled =
false
;
, so it will not be editable. You can perform some additional checks like user's role here.In the early webinars and marketing material of Sitefinity 4 they stated that you will be able to restrict permissions down to the field level. Based on this thread that never happened. Granual permissions down to the field level was one of the main reasons we selected Sitefinity. We have a number of departments that are responsible for certain fields in content. We were planning to leverage workflow and granular permissions to automoate this process. Do you have a recommended workaround? When will this be implemented?
Hello Shawn,
I am not able to come up with another workaround. We will not be able to deliver permissions for custom fields before Q2. There is a pits that you can follow/vote
Best wishes,
Ivan Dimitrov
the Telerik team