authorization rules on Binding navigator and filteredbindinglistauthorization rules on Binding navigator and filteredbindinglist
Old forum URL: forums.lhotka.net/forums/t/899.aspx
dean posted on Monday, August 14, 2006
I have a form bound to a filteredbindinglist (with a binding navigator). The ReadWriteAuthorization form control does not seem to be working in this situation.
I could be totally wrong in this analysis but it seems that:
The applyauthorizationrules(control as control) sub in ReadWriteAuthorization.vb checks to see if the datasource is either a businessbase or a iReadonly object. In this case the datasource is the filtered binding list so it fails to identify anything to apply the rules to. Unfortunately my understanding of generics prevents me from figuring out what we do want to check for here.
Can anyone comment on this? Has anyone successfully used the readwriteauthorization when the form is bound to a collection?
Dean
dean replied on Friday, August 18, 2006
I have altered this method from the ReadWriteAuthorization control. It seems to be working now.
Basically I checked for a ibindinglist datasource and if it is use the bindingsource.current property to retreive the businessbase object.
Warning: I have not extensively tested this. But it is working in the situation outlined above and in the situtation where a bus base object is the datasource.
Comments?
Private Sub ApplyAuthorizationRules(ByVal control As Control)
For Each binding As Binding In Control.DataBindings
' get the BindingSource if appropriate
If TypeOf binding.DataSource Is BindingSource Then
Dim bs As BindingSource = CType(binding.DataSource, BindingSource)
' get the BusinessObject if appropriate
'-----
' My change - check if ibindinglist and if current object is businessbase
If TypeOf bs.DataSource Is IBindingList AndAlso TypeOf bs.Current Is Csla2.Core.BusinessBase Then
Dim ds As Csla2.Core.BusinessBase = _
CType(bs.Current, Csla2.Core.BusinessBase)
' get the object property name
Dim propertyName As String = _
binding.BindingMemberInfo.BindingField
ApplyReadRules(control, binding, propertyName, _
ds.CanReadProperty(propertyName))
ApplyWriteRules(control, binding, propertyName, _
ds.CanWriteProperty(propertyName))
'-----
ElseIf TypeOf bs.DataSource Is Csla2.Core.BusinessBase Then
Dim ds As Csla2.Core.BusinessBase = _
CType(bs.DataSource, Csla2.Core.BusinessBase)
' get the object property name
Dim propertyName As String = _
binding.BindingMemberInfo.BindingField
ApplyReadRules(control, binding, propertyName, _
ds.CanReadProperty(propertyName))
ApplyWriteRules(control, binding, propertyName, _
ds.CanWriteProperty(propertyName))
ElseIf TypeOf bs.DataSource Is Csla2.Core.IReadOnlyObject Then
Dim ds As Csla2.Core.IReadOnlyObject = _
CType(bs.DataSource, Csla2.Core.IReadOnlyObject)
' get the object property name
Dim propertyName As String = _
binding.BindingMemberInfo.BindingField
ApplyReadRules(control, binding, propertyName, _
ds.CanReadProperty(propertyName))
End If
End If
Next
End SubRockfordLhotka replied on Monday, August 21, 2006
This seems like a good enhancement to the control. I think a complete solution would need to take into account that you could have a collection of readonly objects too - so the overall structure needs to be slightly different to accomodate all four scenarios.
I'll add this to the list of things to fix in 2.1.1 (I'm really not doing more changes to 2.1!!)
Curelom replied on Tuesday, October 24, 2006
I've made a modification that seems to also work c# version
if (binding.DataSource is BindingSource)
{
BindingSource bs =
(
BindingSource)binding.DataSource;
// get the BusinessObject if appropriate
//////////////////////////////////////////////////////
//modification to allow for binding to lists
Csla.Security.
IAuthorizeReadWrite ds;
if (bs.DataSource is IBindingList && bs.Current is Security.IAuthorizeReadWrite)
ds = bs.Current
as Csla.Security.IAuthorizeReadWrite;
else
ds = bs.DataSource
as Csla.Security.IAuthorizeReadWrite;
//////////////////////////////////////////////////////
if (ds != null)
{
// get the object property name
string propertyName =
binding.BindingMemberInfo.BindingField;
ApplyReadRules(
control, binding,
ds.CanReadProperty(propertyName));
ApplyWriteRules(
control, binding,
ds.CanWriteProperty(propertyName));
}
gdk9am replied on Thursday, November 30, 2006
Hi
I have tried to use ReadWriteauthorization rules on Binding navigator and filteredbindinglist and they still don't work on 2.1.1. Did this change not make it into the 2.1.1 release ?
Has anyone implemented the complete fix as recommended by Rocky ?
RockfordLhotka replied on Wednesday, January 17, 2007
I have changed ReadWriteAuthorization for 2.1.2, so collections should work starting there. The change is in
cvs now if you want to pull it earlier.
Copyright (c) Marimer LLC