This is a migrated thread and some comments may be shown as answers.

[Solved] Grid Editing based on user permissions

3 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marco Teodoro
Top achievements
Rank 1
Marco Teodoro asked on 08 Jun 2010, 03:13 PM
hello,

i´m would like to know if someone implement a validation logic to support grid editing base on user roles.

for instance: admin can create, read, update, and delete. But normal user will just be able to read. 

how have you done this. i have one view for each type of action but i don't like this because i need to replicate all the code from one view to another. 

also if i just want to add delete and read permission i need to maintain the data bind update action and use some javascript to remove the button from view in run time.

i hope and think that some of you have think in a better approach. 

best regards

3 Answers, 1 is accepted

Sort by
0
Brian Roth
Top achievements
Rank 1
answered on 08 Jun 2010, 05:57 PM
I actually just implemented logic for a similar situation yesterday.  My logic hides the command button column and the add new record button for users that don't have permission to edit or delete items.  If you have the roles set up in the standard Microsoft role provider, you can do something like this:

 
    <%= Html.Telerik().Grid<MyObject>()                  
        .Name("MyGrid")  
        .ToolBar(commands =>  
        {  
            // Hide the insert command if the user doesn't have access              
            if (User.IsInRole("admin")) commands.Insert();  
        })  
        .Columns(columns =>  
        {  
            //Command column with two commands           
            columns.Command(commands =>  
            {  
                commands.Delete();
                // Hide the edit button if the user doesn't have access
                if (User.IsInRole("admin")) commands.Edit();
            }) 
            // Hide the edit row if the user doesn't have access  
            .Visible(User.IsInRole("readAndDelete") || User.IsInRole("admin"));  
            columns.Bound(o => o.Name);  
        })  
    %>  

0
Carson
Top achievements
Rank 1
answered on 23 Feb 2011, 04:21 PM
What if I want to hide a command button based on item data, not user data?
I want to do something like:
<%= Html.Telerik().Grid<MyObject>()                 
        .Name("MyGrid") 
        .Columns(columns => 
        
            //Command column with two commands          
            columns.Command(commands => 
            
                // Hide the delete button if the item is referenced
                // by another database object.
                // Of course, this doesn't work. But, is there a way?
                if (o => o.Links.Count() < 1) commands.Delete();  
                 
                commands.Edit();
            })
            columns.Bound(o => o.Name); 
        }) 
    %>

Thanks,
Carson
0
mike
Top achievements
Rank 1
answered on 04 May 2011, 07:44 PM
This is great. Very helpful.
Tags
Grid
Asked by
Marco Teodoro
Top achievements
Rank 1
Answers by
Brian Roth
Top achievements
Rank 1
Carson
Top achievements
Rank 1
mike
Top achievements
Rank 1
Share this question
or