Per-type authorization (which is a little different now) where you can ask:
And the new per-instance authorization where you can ask:
Our projects Authorization rules work with WriteProperty where we want to disable and enable xaml objects 100%, we just had to play with the rulesets: example 1 see below
now we are trying to use the "per-instance authorization where you can ask. Can the user delete this instance?" my problem is my execute method's context object is null, why? what am I missing? see example 2 see below
example 1:
BusinessRules.AddRule(new AuthorisationPropertyRule(AuthorizationActions.WriteProperty, PresentStatusIDProperty, new List<string> { "IsClosed", "FutureDate" }));
private class AuthorisationPropertyRule : AuthorizationRule
{
private List<string> _ruleSets;
//Creates an instance of the rule.
public AuthorisationPropertyRule(AuthorizationActions action, List<string> ruleSets)
: base(action)
{
_ruleSets = ruleSets;
}
/// Creates an instance of the rule.
public AuthorisationPropertyRule(AuthorizationActions action, Csla.Core.IMemberInfo element, List<string> ruleSets)
: base(action, element)
{
_ruleSets = ruleSets;
}
/// Rule implementation.
protected override void Execute(AuthorizationContext context)
{
bool hasPermission = true;
var target = (RowCallDetailsEC)context.Target;
//Check all conditions
if (_ruleSets.Count > 0)
{
foreach (var ruleSet in _ruleSets)
{
switch (ruleSet)
{
case "IsClosed":
//if (target.IsClosed == true)
if (IsClosedConditionBroken(target))
hasPermission = false;
break;
case "FutureDate":
if (IsFutureDateConditionBroken(target))
hasPermission = false;
break;
case "PresentStatusComment":
if (IsCommentConditionBroken(target))
hasPermission = false;
break;
case "LeaveTypeSet":
if (IsLeaveTypeSetConditionBroken(target))
hasPermission = false;
break;
}
if (hasPermission == false)
break;
}
}
context.HasPermission = hasPermission;
}
}
example 2:
protected override void AddBusinessRules()
{
base.AddBusinessRules();
BusinessRules.AddRule(new AuthorisationCanRemoveObjectRule(AuthorizationActions.DeleteObject, this, new List<string> { "" }));
}
public class AuthorisationCanRemoveObjectRule : AuthorizationRule
{
private List<string> _ruleSets;
private CompanyGroupEC _instance;
//Creates an instance of the rule.
public AuthorisationCanRemoveObjectRule(AuthorizationActions action, List<string> ruleSets)
: base(action)
{
_ruleSets = ruleSets;
_instance = null;
}
/// Creates an instance of the rule.
public AuthorisationCanRemoveObjectRule(AuthorizationActions action, CompanyGroupEC instance, List<string> ruleSets)
: base(action)
{
_ruleSets = ruleSets;
_instance = instance;
}
/// Rule implementation.
protected override void Execute(AuthorizationContext context)
{
bool hasPermission = true;
var target = (CompanyGroupEC)context.Target; //is null
//var ptarget = _instance; is null
//var ptarget = this.Element; is null
try
{
if (target.haveChildren)
hasPermission = false;
}
catch (Exception eeee) { }
context.HasPermission = hasPermission;
}
}
// BusinessRules.CheckRules(); is in the other partial class
Question 2: When will the CSLA.net 4 videos be online and examples?
Copyright (c) Marimer LLC