locked
Filter entity rows by e => this.Application.User.IsInRole(e.Title + " User"); RRS feed

  • Question

  • In my application I allow the user to create link tiles, which when inserted generate a Role (since permissions cannot be create at run time). This way my portal application can remain dynamic. However when trying to filter the tile entities in the datasource filter method I get some error about not being able to use the IsInRole method. 

    After some digging I decided to give expression trees a try, and this is what I came up with:

    partial void TileLinks_Filter(ref Expression<Func<TileLink, bool>> filter) { // filter = e => e.IntegerProperty == 0; ParameterExpression p = Expression.Parameter(typeof(TileLink), "e"); MemberExpression ti = Expression.Property(p, "Title"); MethodInfo m2 = typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) }); Type t = this.Application.User.GetType(); MethodInfo m = t.GetMethod("IsInRole"); Expression filterExpression = Expression.IsTrue(Expression.Call(Expression.Call(m2, ti, Expression.Constant(" User")), m)); filter = Expression.Lambda<Func<TileLink, bool>>(filterExpression, p);

    // e => this.Application.User.IsInRole(e.Title + " User"); this is what I would like to do }

    This however does not work, and I am left with this very odd error message.

    Method 'Boolean IsInRole(System.String)' declared on type 'System.Security.Claims.ClaimsPrincipal' cannot be called with instance of type 'System.String'

    Please help me filter my data based on dynamically generated roles!


    Wednesday, June 11, 2014 9:33 PM

Answers

  • In my application I allow the user to create homepage tiles, which when inserted generate a Role. This way my portal application can remain dynamic. However when trying to filter the tile entities in the datasource filter method I get some error about not being able to use the IsInRole method.

    According to your description above, I'm thinking whether you need use permission on your side.

    A permission is a kind of security indirection that many application frameworks use. A permission is a security dependency more closely related to a particular functionaly whereas a role is just a collection of permissions.

    Here is the reference for you:

    How do I filter records based on the users role

    Hope it helps.

    Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Angie Xu Monday, June 23, 2014 1:36 AM
    Thursday, June 19, 2014 3:01 AM

All replies

  • In my application I allow the user to create homepage tiles, which when inserted generate a Role. This way my portal application can remain dynamic. However when trying to filter the tile entities in the datasource filter method I get some error about not being able to use the IsInRole method.

    According to your description above, I'm thinking whether you need use permission on your side.

    A permission is a kind of security indirection that many application frameworks use. A permission is a security dependency more closely related to a particular functionaly whereas a role is just a collection of permissions.

    Here is the reference for you:

    How do I filter records based on the users role

    Hope it helps.

    Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Angie Xu Monday, June 23, 2014 1:36 AM
    Thursday, June 19, 2014 3:01 AM
  • Permissions cannot be generated dynamically. They are created by the LightSwitch design time user interface in the applications properties. The whole point here is to restrict access to dynamic content.

    Regards, Christopher Maduro

    Friday, August 29, 2014 3:29 PM