CQWP & Audiencing – The Bug:
CQWP supports filtering data based on user's audience groups. E.g If you configure web part to fetch items from /mysite/pages list, it would apply audience rules and fetch you pages belonging to audience groups you are part of ( any one of it). This works in conjunction with other features of the web part
a) Query: User can select queries such as Title contains 'xyz'
b) Sort Order
c) Item Limit
However the order it applies is the cause of concern. As you would see in the image, audience rule gets set after ItemLimit rule is applied.
{
protected override void OnInit(EventArgs e)
{
this.ProcessDataDelegate += new ProcessData(ProcessData);
base.OnInit(e);
}
{
//Store user selected ItemLimit and set it to -1. This is equivalent to user not setting any item limit
userSelectedItemLimit = this.ItemLimit;
this.ItemLimit = -1;
base.CreateChildControls();
}
// ProcessData is called after all rules are applied, including audience rule and before
private new DataTable ProcessData(DataTable dt)
{
// Reset the itemlimit to whatever user selected
this.ItemLimit = userSelectedItemLimit;
if (userSelectedItemLimit > 0)
{
//If number of rows greater than than the user given item limit
while (dt.Rows.Count > userSelectedItemLimit)
{
//Removing the rest of the rows
dt.Rows.RemoveAt(dt.Rows.Count - 1);
}
}
return dt;
}
}
1. Set ItemLimit = -1, forcing CQWP to avoid applying item limit. This ensures all results eligible for users, after applying audience rules are available.
2. CQWP allows you to hookup your event delegate called 'ProcessData' which gets called just before the xslt is applied. In ProcessData delegate, manually trim down the results to the user set ItemLimit.
Now all users would see the itemlimit number of items as long as enough data exists.