Permission on custom field in Sitefinity 4.x

Posted by Community Admin on 03-Aug-2018 17:55

Permission on custom field in Sitefinity 4.x

All Replies

Posted by Community Admin on 24-May-2011 00:00

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?

Posted by Community Admin on 27-May-2011 00:00

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

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 27-May-2011 00:00

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

Posted by Community Admin on 01-Jun-2011 00:00

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";
    
    
  

 2. Inside InitializeControls disable the TextBox - this.TextBoxControl.Enabled = false;, so it will not be editable. You can perform some additional checks like user's role here.

3. How to register the custom class. If it is a custom module you can inject it in the definition. If this is for an existing module, or you just want to use the UI you have to

 - create a custom field of type short text
 - go to Administration >> Settings >> ContentView >> Controls  >> [View you want to modify ] and change the type of the custom field

If you want a completely custom field control you need to create definition elements for it. Also conditional templates are used when you want to use the same control in several modes to have different way that the data is entered.

Greetings,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 03-Jun-2011 00:00

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? 

Posted by Community Admin on 08-Jun-2011 00:00

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

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed