Hello,
In order to hide protected content row I submit a question and got the answer.
https://www.devexpress.com/Support/Center/Question/Details/T152763
C#using System;
using System.Linq;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.Data.Filtering;
using System.Collections.Generic;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Utils;
using DevExpress.ExpressApp.Layout;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Templates;
using DevExpress.Persistent.Validation;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Model.NodeGenerators;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.ExpressApp.Security;
namespace CL.Module.Controllers
{
// For more typical usage scenarios, be sure to check out http://documentation.devexpress.com/#Xaf/clsDevExpressExpressAppViewControllertopic.
public class HideProtectedContentRowsController : ViewController<ListView>
{
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
GridListEditor gridListEditor = View.Editor as GridListEditor;
if (gridListEditor != null)
{
gridListEditor.GridView.CustomRowFilter += GridView_CustomRowFilter;
}
}
void GridView_CustomRowFilter(object sender, DevExpress.XtraGrid.Views.Base.RowFilterEventArgs e)
{
GridView gridView = (GridView)sender;
object obj = gridView.GetRow(gridView.GetRowHandle(e.ListSourceRow));
if (!SecuritySystem.IsGranted(new ClientPermissionRequest(obj.GetType(), null, ObjectSpace.GetObjectHandle(obj), SecurityOperations.Read)))
{
e.Visible = false;
e.Handled = true;
}
}
protected override void OnDeactivated()
{
base.OnDeactivated();
GridListEditor gridListEditor = View.Editor as GridListEditor;
if (gridListEditor != null)
{
gridListEditor.GridView.CustomRowFilter -= GridView_CustomRowFilter;
}
}
}
}
In my small sample CustomRowFilter is raised, but in my real project CustomRowFilter is not raised
Please find the attached SWF. Would you please tell me how to solve it?
Thanks
Wangbei
More information, If the view has Variants, the CustomRowFilter will not be raised.
Please find the attached SWF to see the debug procedure.
And also the small sample, which PayCard have Variants, and PayCardUsage do not have.
Hello Wangbei.
The project you posted seems to work correctly. I cannot determine why this controller doesn't work in your "real" project based on videos. However, I'd modify the controller as follows:
public class HideProtectedContentRowsController : ViewController<ListView> { protected override void OnActivated() { base.OnActivated(); GridListEditor gridListEditor = View.Editor as GridListEditor; if (gridListEditor != null) { if (gridListEditor.GridView != null) { } else { gridListEditor.ControlsCreated += gridListEditor_ControlsCreated; } } } protected void gridListEditor_ControlsCreated(object sender, EventArgs e) { ((GridListEditor)sender).GridView.CustomRowFilter += GridView_CustomRowFilter; } protected override void OnDeactivated() { base.OnDeactivated(); GridListEditor gridListEditor = View.Editor as GridListEditor; if (gridListEditor != null) { gridListEditor.GridView.CustomRowFilter -= GridView_CustomRowFilter; } } void GridView_CustomRowFilter(object sender, DevExpress.XtraGrid.Views.Base.RowFilterEventArgs e) { GridView gridView = (GridView)sender; IList list = gridView.DataSource as IList; if (list == null) return; object obj = list[e.ListSourceRow]; if (obj == null) return; if (!SecuritySystem.IsGranted(new ClientPermissionRequest(obj.GetType(), null, ObjectSpace.GetObjectHandle(obj), SecurityOperations.Read))) { e.Visible = false; e.Handled = true; } } }
If this doesn't help, please provide us with a project that replicates the issue, so we can build and debug it locally.
I have an idea. If the list view operates in Server Mode, handling this event has no effect. Refer to the Server Mode Limitations article.
Thanks Michael,
The listviews are not in Server Mode. It's View Variant. I use your new View Controller. It's still not work.
Please find the attached video of debug.
BRGDS/Wangbei
Attached the small sample use the new View Variant.
Thank you for the updated project and video. In fact, it seems to work correctly. The CustomRowFilter is raised when it should and rows are filtered according to criteria and security rules you defined. Since John is granted the full Read access permission for the PayCard type, the IsGranted method returns True for all rows in the PayCard list view. Would you please explain in detail what the issue is?
P. S. Note that if you set a breakpoint at the beginning of the GridView_CustomRowFilter method (not inside the if operator branch), you'll see that the event handler is called for all rows.
Thanks Michael,
I will check my sample again.
BRGDS/Wangbei
Hello Michael,
Sorry. It's caused by Server Mode Limitations. Thanks.
And would you please give me another way to hide the entire row of Protected Content if the Solution is in Server Mode?
BRGDS/Wangbei
In my real project, I need Server Mode to speed up the program. Attached is the Screenshot.
Another information, in my test, even in Sever Mode CustomRowFilter is raised in nest list view, but not in root listview.
If you wish to hide rows with a completely denied Read access in server mode, use integrated security system mode (Client-Side Security - Integrated Mode) instead of handling the CustomRowFilter event.
As for nested list views, they operate in client mode regardless of the global DataAccessMode (UseServerMode) option. To change mode for a nested list view, set the DataAccessMode (UseServerMode) property of the list view model.
Thanks Michael,
As I mentioned in before question.
https://www.devexpress.com/Support/Center/Question/Details/T152763
(Client-Side Security - Integrated Mode) will cause calculation problem.
Thanks!
BRGDS/Wangbei
If I understand your response in T152763 correctly, the issue is solved and the project Anatol provided already uses the integrated security. Let me know if you need additional assistance.
Hello Michael,
Yes T152763 solved calculation problem using custom provider. Which will cause many update work for my delivered projects. Now five of my project face this problem.
So I still intend to get a better way to hide entire row of protected content in UI level for server mode. If it could be done, update of my current project will be easy. I have over hundreds of calculation field to handle. I still do not know the performance which need test.
BRGDS/Wangbei
I'm afraid there's no simpler solution. As it is mentioned in the Server Mode Limitations article, the CustomRowFilter event doesn't work in server mode and the grid doesn't provide other means to filter data by a custom code-based criterion.
Thanks Michael.