Checking whether the currently logged user belongs to a certain role in a filter becomes easier in 11.1.7

XAF Team Blog
12 September 2011

Prerequisites

I am confident that every user who utilized XAF’s Security module with the Complex Security strategy should have met this requirement at least once using XAF, for example, when you had to filter out a ListView to display records only for people from the Administrators role and hide them from the rest. Or, you wanted to make your favorite Appearance or Validation rule work only for people from the Users role? Sound familiar?

A good way to address such requirements is to implement a custom function criteria operator. Tolis recently demonstrated how it can be done in his recent blog post about applying security to the State Machine module. The first time I saw the blog, I thought that it would be nice to have such a function in XAF out-of-the-box. So, shortly thereafter, after seeing a discussion on the forum, I logged a corresponding feature request.

New built-in criteria function

This feature request was implemented in version 11.1.7, and that means that you can already make use of the new IsCurrentUserInRole function in your criteria. The function’s use is very simple. All that you need to do is to pass the name of the role as a parameter:

IsCurrentUserInRole(‘Administrators’)

I expect that this built-in criteria function will be no less popular than the CurrentUserId()  function and will also save you a lot of time, because the described requirements are quite common in business applications.

Future plans

While we are talking about custom criteria functions, a note about our future plans. Although XAF already provides a similar feature called Read-Only Parameters, we are gradually stepping away from it and moving towards custom criteria functions everywhere. This is because they provide more capabilities (e.g. they are supported by all DevExpress products and not only in XAF; functions can accept arguments whereas Read Only Parameters are constants, etc.). It is intended not only to optimize our support costs, but also to allow a faster evolution of our products.

Do you like this small improvement? Please let us know your opinion! Happy XAFing!Winking smile

Free DevExpress Products – Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We’ll be happy to follow-up.
christy pirumova
christy pirumova

Like it!

I also prefer to get rid of readonly params and use functions instead, it results in better performance

You are right about the problem being common :)

I've had the same request and have implemented a method in my business classes getting Role as a parameter (not just name, cos there is no uniqueness requirement on the role names) and returning a criteria to be applied to some collections

Though I have been applying the criteria in viewcontroller and I welcome a fact that now it can be done in any other ways also

12 September 2011
drew..
drew..

Years ago when i brought this up, and created my own function for xaf, it was suggested this was not a common function. Nice to see our knowledge base expanding to be more relevant to our everyday practices!

14 September 2011
Dennis (DevExpress)
Dennis Garavsky (DevExpress)

Thank you for the feedback, guys (and girls)!

15 September 2011

Please login or register to post comments.