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

Hide commands/toolbar based on db-based role management

1 Answer 355 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 12 Jan 2016, 06:44 AM

Hello, 

the AuthorizeAttribute does for well initial authorization and authentication and for actions that return views, but it doesn't work for grid commands such as save. Well it actually prevent the saving process, but the routing to the error-action doesn't work properly, because the save-command doesn't expect a view to be returned.

 

Rather than redirecting I'd like to hide commands/toolbar-items based on the role a user has in our database, but so far I only found an option like this based on AD-roles. Is there any way for me to do this?

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 14 Jan 2016, 04:41 PM
Hello Oliver,

Unfortunately, there is no built-in way to manage the toolbar and command buttons' visibility, depending on the user role. A possible way to achieve the desired behavior is to make the Grid configuration dependent on a boolean flag, for example:


@{
    var userCanEdit = false;
}
 
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()   
    .Name("Grid")   
    .Columns(columns => {       
        columns.Bound(p => p.ProductName);
        if (userCanEdit)
        {
            columns.Command(command => command.Destroy()).Width(110);
        }
    })
    .ToolBar(toolbar => {
        if (userCanEdit)
        {
            toolbar.Create();
            toolbar.Save();
        }
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell).Enabled(userCanEdit))
)


Regards,
Dimo
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Oliver
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or