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

[Solved] showing grid data role based

4 Answers 133 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.
Gerard Eikelboom
Top achievements
Rank 1
Gerard Eikelboom asked on 31 Mar 2011, 12:50 PM
Hi,
we are now implmenting sequirity in our application and one of the things is that I want to show data only when the user has a specific role.
We make use of the std asp.net role provider.
I have alreay implemented such for commands Edit /Delete in my grid. That works good.
columns.Command(commands =>
              {
             if (User.IsInRole("Administrator")) commands.Edit().ButtonType(GridButtonType.Image);
             if (User.IsInRole("Administrator")) commands.Delete().ButtonType(GridButtonType.Image);

I hope it's possible.

Regards,
Gerard Eikelboom

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 31 Mar 2011, 01:09 PM
Hello Gerard Eikelboom,

 I am not sure what you mean by "show data only when the user has a specific role". Could you please clarify?

Regards,
Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 31 Mar 2011, 01:19 PM
Atanas,
What I mean is when my Grid is initialised I get the data:
.DataBinding(dataBinding => dataBinding.Ajax().Select("_GetUsers", "User"))

What I normal do in my controller class when I want users to have permission based on a role to see it:
[Authorize(Roles="Administrator")]
       [GridAction]
       public ActionResult _GetUsers()
So only administrators have permission to go into that action.
I cannot do that with a GridAction because I get the error The requested Url did not return JSON.
Althought it's not showing data, so that's ok.

So, I wonder if you can handle it in the Grid itself, like you can with the command buttons (first piece of code)

Regards,
Gerard
0
Atanas Korchev
Telerik team
answered on 31 Mar 2011, 01:45 PM
Hi Gerard Eikelboom,

 No, the grid cannot handle this. What you can do is show the grid only when the user has rights:

<% if (User.IsInRole("Administrator")) { %>

<%= Html.Telerik().Grid() %>

<% } %>

Regards,
Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 31 Mar 2011, 01:48 PM
Atanas,

Yes that's an option.
What I do now is handle it in my controller using my own written role provider implementation.
It's shows the grid but it returns an empty collection.
I will think about your option.

thanks,

Gerard Eikelboom
Tags
Grid
Asked by
Gerard Eikelboom
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gerard Eikelboom
Top achievements
Rank 1
Share this question
or