Consolidate User Context

This commit is contained in:
2021-08-04 21:32:35 +01:00
parent b8cfd87860
commit afd38cea03
126 changed files with 2240 additions and 634 deletions
+46 -32
View File
@@ -1,10 +1,12 @@
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
using Sarand.BusinessMgr.Net.Standard.Base.Core;
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
using Sarand.Net.Standard.Base.App;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Dbas;
using Sarand.Net.Standard.Base.ItemOptions;
using Sarand.Net.Standard.Base.Security;
using Sarand.Net.Standard.Base.Utils;
using System;
using System.Collections.Generic;
@@ -12,45 +14,57 @@ using System.Collections.Generic;
namespace Sarand.BusinessMgr.Net.Standard.Base.App
{
//=======================================================================
public class SbmUserContext
public class SbmUserContext : ISbmUserContext
{
//-------------------------------------------------------------------
// Definitions.
// User profile.
public class UserData
public class UserData : ISbmUserContext.IUserData
{
protected UserData() { }
protected readonly List<SysIdString> supervisedOwners = new List<SysIdString>();
/// <summary>User Security Item Id.</summary>
public SysId SecItemId { get; protected set; } = new SysId();
public SysId SecurityItemId { get; protected set; } = new SysId();
/// <summary>User Affiliate Id.</summary>
public SysId AffiliateId { get; protected set; } = new SysId();
/// <summary>User first name.</summary>
public String FirstName { get; protected set; } = "";
/// <summary>User last name.</summary>
public String LastName { get; protected set; } = "";
/// <summary>User display name.</summary>
public String DisplayName { get; protected set; } = "";
/// <summary>User email address.</summary>
public String EmailAddress { get; protected set; } = "";
/// <summary>User managed associations - Id and display name.</summary>
public List<SysIdString> SupervisedOwners { get { return new List<SysIdString>(supervisedOwners); } }
public List<SysIdString> SupervisedOrganisations { get { return new List<SysIdString>(supervisedOwners); } }
}
private class UserData_Internal : UserData
{
internal UserData_Internal() { }
internal void Clear()
{
SecItemId = new SysId();
SecurityItemId = new SysId();
AffiliateId = new SysId();
FirstName = "";
LastName = "";
DisplayName = "";
EmailAddress = "";
supervisedOwners.Clear();
}
internal void Refresh(SysId securityItemId, SysId affiliateId, String displayName, List<SysIdString> supervisedOwners)
internal void Refresh(SaSecurityItem securityItemUser, SbmAffiliate affiliateUser, List<SysIdString> supervisedOwners)
{
SecItemId = SysId.InvalidOnNull(securityItemId);
AffiliateId = SysId.InvalidOnNull(affiliateId);
DisplayName = StringUtil.EmptyOnNull(displayName).TrimAll();
SecurityItemId = SysId.InvalidOnNull(securityItemUser?.Id ?? null);
AffiliateId = SysId.InvalidOnNull(affiliateUser?.Id ?? null);
FirstName = StringUtil.EmptyOnNull(affiliateUser?.FirstName ?? "").TrimAll();
LastName = StringUtil.EmptyOnNull(affiliateUser?.LastName ?? "").TrimAll();
DisplayName = StringUtil.EmptyOnNull(affiliateUser?.GetDisplayName() ?? "").TrimAll();
EmailAddress = StringUtil.EmptyOnNull(securityItemUser?.EmailAddress ?? "");
this.supervisedOwners.Clear();
this.supervisedOwners.AddRange(supervisedOwners);
}
}
// Owner profile - selected organisation to manage.
public class OrganisationData
public class OrganisationData : ISbmUserContext.IOrganisationData
{
internal OrganisationData() { }
// Organisation options.
@@ -115,24 +129,26 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
{
SessionContext = sessionContext;
organisationData = new OrganisationData_Internal();
SecurityProfile = new SbmSecurityProfile(this, true);
securityProfile = new SbmSecurityProfile(this, true);
DbUpdateInfo = new DbUpdateInfo(User.AffiliateId, User.DisplayName, SacsSystem.ComputerName);
}
//-------------------------------------------------------------------
// Properties.
public SbmSessionContext SessionContext { get; protected set; }
public UserData User { get { return userData; } }
public bool ValidUser { get { return SysId.IsValid(userData.SecItemId) && SysId.IsValid(userData.AffiliateId); } }
public OrganisationData Organisation { get { return organisationData; } }
public ISbmUserContext.IUserData User { get { return userData; } }
public bool ValidUser { get { return SysId.IsValid(userData.SecurityItemId) && SysId.IsValid(userData.AffiliateId); } }
public ISbmUserContext.IOrganisationData Organisation { get { return organisationData; } }
public DbUpdateInfo DbUpdateInfo { get; private set; }
//-------------------------------------------------------------------
// Security profile.
public SbmSecurityProfile SecurityProfile { get; protected set; }
private SbmSecurityProfile securityProfile { get; set; }
public ISbmSecurityProfile SecurityProfile { get { return securityProfile; } }
//-------------------------------------------------------------------
// Organisation configuration.
public SaItemOption.Cache OrganisationConfigOptionsCache { get { return organisationData.configOptionsCache; } }
public String GetOrganisationOption(Sbm.OrganisationOption option, String context)
{
if (assocOptions == null) assocOptions = SbmSystem.GetCodesOfType(this, Sbm.SystemCode.AssociationOption);
@@ -142,7 +158,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
public String GetOrganisationOption(String optionName, String context)
{
// Retrieve the requested value from the cache.
return Organisation.configOptionsCache.ItemOptions.GetOptionValue(optionName, context);
return organisationData.configOptionsCache.ItemOptions.GetOptionValue(optionName, context);
}
public String GetOwnerOption_Value(Sbm.OrgOption_Value eCol)
{
@@ -185,14 +201,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
String value = GetOrganisationOption(Sbm.OrganisationOption.ShowColumn, context).Trim();
return StringUtil.ToBool(value);
}
public String GetOwnerOption_FieldLabel(SbmDbDfn.ColumnIdx eCol, String sDefault)
public String GetOwnerOption_FieldLabel(SbmDbDfn.ColumnIdx eCol, String defautValue)
{
if (contextFieldLabels == null) contextFieldLabels = SbmSystem.GetCodesOfType(this, Sbm.SystemCode.OrgOption_FieldLabel);
String context = contextFieldLabels.GetCodeForType(eCol);
String value = GetOrganisationOption(Sbm.OrganisationOption.FieldLabel, context).Trim();
return (!value.IsEmpty() ? value : sDefault); // Return default if no label defined.
return (!value.IsEmpty() ? value : defautValue); // Return default if no label defined.
}
public int GetOwnerOption_Minutes(Sbm.OrgOption_Minutes eLimit, int iDefault)
public int GetOwnerOption_Minutes(Sbm.OrgOption_Minutes eLimit, int defautValue)
{
if (contextMinutes == null) contextMinutes = SbmSystem.GetCodesOfType(this, Sbm.SystemCode.OrgOption_Minutes);
String context = contextMinutes.GetCodeForType(eLimit);
@@ -203,9 +219,9 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
if (iUpdateLimit > 0)
return iUpdateLimit;
}
return iDefault;
return defautValue;
}
public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodDays eLimit, int iDefault)
public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodDays eLimit, int defautValue)
{
if (contextPeriodDays == null) contextPeriodDays = SbmSystem.GetCodesOfType(this, Sbm.SystemCode.OrgOption_PeriodDays);
String context = contextPeriodDays.GetCodeForType(eLimit);
@@ -216,9 +232,9 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
if (iUpdateLimit > 0)
return iUpdateLimit;
}
return iDefault;
return defautValue;
}
public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodWeeks eLimit, int iDefault)
public int GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodWeeks eLimit, int defautValue)
{
if (contextPeriodWeeks == null) contextPeriodWeeks = SbmSystem.GetCodesOfType(this, Sbm.SystemCode.OrgOption_PeriodWeeks);
String context = contextPeriodWeeks.GetCodeForType(eLimit);
@@ -229,14 +245,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
if (iUpdateLimit > 0)
return iUpdateLimit;
}
return iDefault;
return defautValue;
}
public int GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals eNumDecimals, int iDefault = 2)
public int GetOwnerOption_NumericDecimals(Sbm.OrgOption_NumericDecimals eNumDecimals, int defautValue = 2)
{
if (contextNumericDecimals == null) contextNumericDecimals = SbmSystem.GetCodesOfType(this, Sbm.SystemCode.OrgOption_NumericDecimals);
String context = contextNumericDecimals.GetCodeForType(eNumDecimals);
String value = GetOrganisationOption(Sbm.OrganisationOption.NumericDecimals, context).Trim();
int iNumDecimals = iDefault;
int iNumDecimals = defautValue;
if (!value.IsEmpty())
iNumDecimals = value.ToShort();
iNumDecimals = Math.Min(4, Math.Max(0, iNumDecimals));
@@ -264,9 +280,9 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
//-------------------------------------------------------------------
// Modify properties - internal only.
protected void SetUserData(SbmAffiliate affiliateUser, List<SysIdString> supervisedOwners)
protected void SetUserData(SaSecurityItem securityItemUser, SbmAffiliate affiliateUser, List<SysIdString> supervisedOwners)
{
userData.Refresh(affiliateUser.UserId, affiliateUser.Id, affiliateUser.GetDisplayName(), supervisedOwners);
userData.Refresh(securityItemUser, affiliateUser, supervisedOwners);
DbUpdateInfo = new DbUpdateInfo(User.AffiliateId, User.DisplayName, SacsSystem.ComputerName);
}
protected void ClearUserData()
@@ -281,9 +297,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
String fn = GetType().Name + ".SetOrganisationData";
// Interface context for selected organisation.
String interfaceContext = "";
if (SysId.IsValid(affiliateIdOrganisation))
interfaceContext = "ORG" + StringUtil.PadLeft(SysId.ToString(affiliateIdOrganisation), 5, '0');
String interfaceContext = SbmAccountMgr.GetInterfaceContext(affiliateIdOrganisation);
SbmAffiliate affiliateOrganisation = null;
SbmAssociation associationInternal = null;
@@ -330,7 +344,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
}
protected void SetSecurityProfile(SbmSecurityProfile securityProfile)
{
SecurityProfile = securityProfile;
this.securityProfile = securityProfile;
}
//-------------------------------------------------------------------