Session data.
This commit is contained in:
@@ -1855,6 +1855,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
public enum AssetType
|
||||
{
|
||||
Unknown = 0,
|
||||
Any = Unknown,
|
||||
// NB Do not change the positive values, as tied to the database.
|
||||
General = 10,
|
||||
Furniture = 11,
|
||||
@@ -1863,8 +1864,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
}
|
||||
public enum AssetIncomeType
|
||||
{
|
||||
Unknown = 0,
|
||||
None = 0,
|
||||
Unknown = 0,
|
||||
// NB Do not change the positive values, as tied to the database.
|
||||
Sale = 10,
|
||||
Rental = 20,
|
||||
@@ -1874,8 +1875,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
// Vehicles.
|
||||
public enum VehicleType
|
||||
{
|
||||
Any = -1,
|
||||
Unknown = 0,
|
||||
Any = Unknown,
|
||||
// NB Do not change the positive values, as tied to the database.
|
||||
Car = 10,
|
||||
Minibus = 11,
|
||||
|
||||
@@ -8,12 +8,12 @@ using System;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
{
|
||||
//=======================================================================
|
||||
/// <summary>
|
||||
/// Application configuration:
|
||||
/// <para>- Availability of UI components - menu options, views etc.</para>
|
||||
/// </summary>
|
||||
public static class SbmAppConfig
|
||||
//=======================================================================
|
||||
/// <summary>
|
||||
/// Application configuration:
|
||||
/// <para>- Availability of UI components - menu options, views etc.</para>
|
||||
/// </summary>
|
||||
public static class SbmAppConfig
|
||||
{
|
||||
private const String ClassName = nameof(SbmAppConfig);
|
||||
|
||||
@@ -21,8 +21,9 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
// A p p l i c a t i o n V i e w s
|
||||
//-------------------------------------------------------------------
|
||||
// Jul-2021 SessionConfig parameter added to avoid local creation. To be reviewed/replaced.
|
||||
public static bool IsViewApplicable(SbmSessionConsole sessionConsole, Sbm.View view)
|
||||
public static bool IsViewApplicable(SbmInternals internals, Sbm.View view)
|
||||
{
|
||||
SbmSessionConsole sessionConsole = internals.SessionConsole;
|
||||
ISbmSecurityProfile_Core securityProfile = sessionConsole.UserContext.SecurityProfile_Core;
|
||||
switch (view)
|
||||
{
|
||||
@@ -231,14 +232,11 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
case Sbm.View.SystemUsers:
|
||||
if (!sessionConsole.AllowOption(Sbm.ConfigOption.Contacts)) return false;
|
||||
// Interfaces must be available.
|
||||
using (SaInterfaceConsole interfaceConsole = SbmGlobals.Application.CreateInterfaceConsole(sessionConsole.UserContext))
|
||||
{
|
||||
if (interfaceConsole == null || !interfaceConsole.DatabaseIsValid) return false;
|
||||
// System Account & User tables must be available.
|
||||
ISacsDatabase busMgrDb = SbmGlobals.Application.GetBusMgrDatabase(sessionConsole.UserContext.SessionContext);
|
||||
if (!SbmGlobals.Application.DbTableExists(busMgrDb, SbmDbDfn.TableIdx.SystemAccount)) return false;
|
||||
if (!SbmGlobals.Application.DbTableExists(busMgrDb, SbmDbDfn.TableIdx.SystemUser)) return false;
|
||||
}
|
||||
if (internals.InterfaceConsole == null || !internals.InterfaceConsole.DatabaseIsValid) return false;
|
||||
// System Account & User tables must be available.
|
||||
ISacsDatabase busMgrDb = SbmGlobals.Application.GetBusMgrDatabase(sessionConsole.UserContext.SessionContext);
|
||||
if (!SbmGlobals.Application.DbTableExists(busMgrDb, SbmDbDfn.TableIdx.SystemAccount)) return false;
|
||||
if (!SbmGlobals.Application.DbTableExists(busMgrDb, SbmDbDfn.TableIdx.SystemUser)) return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -268,17 +266,17 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
//-------------------------------------------------------------------
|
||||
// A p p l i c a t i o n M e n u
|
||||
//-------------------------------------------------------------------
|
||||
public static bool IsMenuOptionApplicable(SbmSessionConsole sessionConsole, Sbm.MenuOption menuOption)
|
||||
public static bool IsMenuOptionApplicable(SbmInternals internals, Sbm.MenuOption menuOption)
|
||||
{
|
||||
if (!sessionConsole.UserContext.ValidUser)
|
||||
if (!internals.SessionConsole.UserContext.ValidUser)
|
||||
{
|
||||
// ToDo Only Login menu option available.
|
||||
return false;
|
||||
}
|
||||
Sbm.View view = GetViewForMenuOption(sessionConsole.UserContext.SessionContext, menuOption);
|
||||
Sbm.View view = GetViewForMenuOption(internals.SessionConsole.UserContext.SessionContext, menuOption);
|
||||
if (view != Sbm.View.Unknown)
|
||||
// View options.
|
||||
return IsViewApplicable(sessionConsole, GetViewForMenuOption(sessionConsole.UserContext.SessionContext, menuOption));
|
||||
return IsViewApplicable(internals, GetViewForMenuOption(internals.SessionConsole.UserContext.SessionContext, menuOption));
|
||||
|
||||
// Non-view options.
|
||||
switch (menuOption)
|
||||
@@ -296,7 +294,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
//-----------------------------------------------------------
|
||||
// Actions.
|
||||
case Sbm.MenuOption.Timesheet:
|
||||
return sessionConsole.AllowOption(Sbm.ConfigOption.TimeRecording);
|
||||
return internals.SessionConsole.AllowOption(Sbm.ConfigOption.TimeRecording);
|
||||
//-----------------------------------------------------------
|
||||
}
|
||||
SaLogger.Warn($"{SysUtil.Fn} Unsupport menu option - {menuOption.ToString()}");
|
||||
|
||||
@@ -84,20 +84,6 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
// Email configuration.
|
||||
public abstract SbmEmailConfig EmailConfig { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Create consoles.
|
||||
public abstract SbmSessionConsole CreateSessionConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaDiaryConsole CreateDiaryConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaSecurityConsole CreateSecurityConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaCodeTypeConsole CreateCodeTypeConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaReferenceDataConsole CreateReferenceDataConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaItemDataConsole CreateItemDataConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaItemDocConsole CreateItemDocConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaItemOptionConsole CreateItemOptionConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaInterfaceConsole CreateInterfaceConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaUpdateLogConsole CreateUpdateLogConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SbmEmailConsole CreateEmailConsole(ISbmUserOrganisationContext userContext);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -3,6 +3,7 @@ using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.CodeTypes;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
@@ -31,12 +32,30 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
// Definitions.
|
||||
|
||||
/// <summary>
|
||||
/// Internal User Context for read-only database access when this class is used outside of user specific sessions.
|
||||
/// <para>- data caches etc.</para>
|
||||
/// Internal core Session Data for Core database access when this
|
||||
/// class is used outside of user specific core sessions, eg.
|
||||
/// <para>- Pre-login.</para>
|
||||
/// <para>- Data caches.</para>
|
||||
/// <para>- Control application session interacting with a core database.</para>
|
||||
/// </summary>
|
||||
private class SbmUserContext_Internal : SbmUserContext
|
||||
private class SbmSessionData_Internals : SbmSessionData, ISbmUserOrganisationContext
|
||||
{
|
||||
public SbmUserContext_Internal(SbmSessionContext sessionContext) : base(sessionContext) { }
|
||||
public SbmSessionData_Internals(SbmSessionContext sessionContext) : base(sessionContext) { }
|
||||
// User properties.
|
||||
public override string UserEmailAddress => "";
|
||||
public override string UserDisplayName => "";
|
||||
public override bool ValidUser => false;
|
||||
public SysId UserSecurityItemId => new SysId();
|
||||
public SysId UserAffiliateId => new SysId();
|
||||
public override DbUpdateInfo DbUpdateInfo => new DbUpdateInfo(UserSecurityItemId, UserDisplayName, SacsSystem.ComputerName);
|
||||
// User security.
|
||||
public ISbmSecurityProfile_Core SecurityProfile_Core => throw new NotImplementedException();
|
||||
// Organisation.
|
||||
public SysId OrganisationAffiliateId => new SysId();
|
||||
public Sbm.AffiliateType OrganisationAffiliateType => Sbm.AffiliateType.Unknown;
|
||||
public SysId OrganisationAssociationId => new SysId();
|
||||
public string OrganisationDisplayName => "";
|
||||
public string OrganisationInterfaceContext => "";
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@@ -82,11 +101,15 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
/// <summary>
|
||||
/// Sessionless construction - minimal context information.
|
||||
/// </summary>
|
||||
public SbmInternals(SbmSessionContext sessionContext)
|
||||
{
|
||||
UserContext = new SbmUserContext_Internal(sessionContext);
|
||||
UserContext = new SbmSessionData_Internals(sessionContext);
|
||||
ReadOnly = true;
|
||||
}
|
||||
// Session dependent construction.
|
||||
public SbmInternals(ISbmUserOrganisationContext userContext)
|
||||
{
|
||||
UserContext = userContext;
|
||||
@@ -207,6 +230,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
public List<TypeCodeDesc> AssociationTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.AssociationType); } }
|
||||
public List<TypeCodeDesc> CommodityTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.CommodityType); } }
|
||||
public List<TypeCodeDesc> AssetTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.AssetType); } }
|
||||
public List<TypeCodeDesc> VehicleTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.VehicleType); } }
|
||||
public List<TypeCodeDesc> TransactionTypeCodes { get { return GetSystemCodes(Sbm.SystemCode.TransactionType); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@@ -305,7 +329,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.sessionConsole == null)
|
||||
con.sessionConsole = Application.CreateSessionConsole(UserContext);
|
||||
con.sessionConsole = SbmGlobals.System.CreateSessionConsole(UserContext);
|
||||
return con.sessionConsole;
|
||||
}
|
||||
}
|
||||
@@ -314,7 +338,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.diaryConsole == null)
|
||||
con.diaryConsole = Application.CreateDiaryConsole(UserContext);
|
||||
con.diaryConsole = SbmGlobals.System.CreateDiaryConsole(UserContext);
|
||||
return con.diaryConsole;
|
||||
}
|
||||
}
|
||||
@@ -323,7 +347,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.securityConsole == null)
|
||||
con.securityConsole = Application.CreateSecurityConsole(UserContext);
|
||||
con.securityConsole = SbmGlobals.System.CreateSecurityConsole(UserContext);
|
||||
return con.securityConsole;
|
||||
}
|
||||
}
|
||||
@@ -332,7 +356,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.codeTypeConsole == null)
|
||||
con.codeTypeConsole = Application.CreateCodeTypeConsole(UserContext);
|
||||
con.codeTypeConsole = SbmGlobals.System.CreateCodeTypeConsole(UserContext);
|
||||
return con.codeTypeConsole;
|
||||
}
|
||||
}
|
||||
@@ -341,7 +365,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.referenceDataConsole == null)
|
||||
con.referenceDataConsole = Application.CreateReferenceDataConsole(UserContext);
|
||||
con.referenceDataConsole = SbmGlobals.System.CreateReferenceDataConsole(UserContext);
|
||||
return con.referenceDataConsole;
|
||||
}
|
||||
}
|
||||
@@ -350,7 +374,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.updateLogConsole == null)
|
||||
con.updateLogConsole = Application.CreateUpdateLogConsole(UserContext);
|
||||
con.updateLogConsole = SbmGlobals.System.CreateUpdateLogConsole(UserContext);
|
||||
return con.updateLogConsole;
|
||||
}
|
||||
}
|
||||
@@ -359,7 +383,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.interfaceConsole == null)
|
||||
con.interfaceConsole = Application.CreateInterfaceConsole(UserContext);
|
||||
con.interfaceConsole = SbmGlobals.System.CreateInterfaceConsole(UserContext);
|
||||
return con.interfaceConsole;
|
||||
}
|
||||
}
|
||||
@@ -368,7 +392,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.itemDocConsole == null)
|
||||
con.itemDocConsole = Application.CreateItemDocConsole(UserContext);
|
||||
con.itemDocConsole = SbmGlobals.System.CreateItemDocConsole(UserContext);
|
||||
return con.itemDocConsole;
|
||||
}
|
||||
}
|
||||
@@ -377,7 +401,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.itemOptionConsole == null)
|
||||
con.itemOptionConsole = Application.CreateItemOptionConsole(UserContext);
|
||||
con.itemOptionConsole = SbmGlobals.System.CreateItemOptionConsole(UserContext);
|
||||
return con.itemOptionConsole;
|
||||
}
|
||||
}
|
||||
@@ -386,20 +410,20 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
get
|
||||
{
|
||||
if (con.itemDataConsole == null)
|
||||
con.itemDataConsole = Application.CreateItemDataConsole(UserContext);
|
||||
con.itemDataConsole = SbmGlobals.System.CreateItemDataConsole(UserContext);
|
||||
return con.itemDataConsole;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Email.
|
||||
public SaEmailConfig EmailConfig { get { return Application.EmailConfig; } }
|
||||
public SbmEmailConfig EmailConfig { get { return Application.EmailConfig; } }
|
||||
public SbmEmailConsole EmailConsole
|
||||
{
|
||||
get
|
||||
{
|
||||
if (con.emailConsole == null)
|
||||
con.emailConsole = Application.CreateEmailConsole(UserContext);
|
||||
con.emailConsole = SbmGlobals.System.CreateEmailConsole(UserContext, EmailConfig);
|
||||
return con.emailConsole;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
// Construction.
|
||||
[JsonConstructor]
|
||||
private SbmSecurityProfile() { }
|
||||
public SbmSecurityProfile(ISbmUserOrganisationContext userContext, bool includeHostSecurityProfile)
|
||||
public SbmSecurityProfile(bool includeHostSecurityProfile)
|
||||
{
|
||||
this.UserContext = userContext;
|
||||
this.includeHostSecurityProfile = includeHostSecurityProfile;
|
||||
Admin = new AdminProfile();
|
||||
Manage = new ManageProfile();
|
||||
@@ -40,8 +39,6 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
[JsonIgnore]
|
||||
public ISbmUserOrganisationContext UserContext { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Refresh profile.
|
||||
@@ -271,7 +268,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
return true;
|
||||
|
||||
// Check if any other statuses for this type of transaction are allowed.
|
||||
foreach (TypeCodeDesc statusCat in SbmTransaction.GetTransactionStatusCats(securityProfile.UserContext, transactionType))
|
||||
foreach (TypeCodeDesc statusCat in SbmTransaction.GetTransactionStatusCats(transactionType))
|
||||
{
|
||||
SbmTransaction.StatusCat transactionStatusCatOther = (SbmTransaction.StatusCat)statusCat.Type;
|
||||
// Ignore the transaction status category.
|
||||
@@ -388,6 +385,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
}
|
||||
public bool UserCanCreateItemType(Sbm.ItemType itemType)
|
||||
{
|
||||
if (userSecurityProfile?.SystemAdmin ?? false) return true;
|
||||
if (!ItemTypeIsAllowed(itemType)) return false;
|
||||
switch (itemType)
|
||||
{
|
||||
@@ -434,6 +432,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
}
|
||||
public bool UserCanUpdateItemType(Sbm.ItemType itemType)
|
||||
{
|
||||
if (userSecurityProfile?.SystemAdmin ?? false) return true;
|
||||
switch (itemType)
|
||||
{
|
||||
case Sbm.ItemType.SecItem: return IsSecurityRightGranted(Sbm.SecurityRight.Security_Admin);
|
||||
|
||||
@@ -1,68 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
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.Bus;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Helpers;
|
||||
using Sarand.Net.Standard.Base.Security;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SbmSessionData
|
||||
/// <summary>
|
||||
/// Basic user session data, shared by Portal and Control applications.
|
||||
/// </summary>
|
||||
public abstract class SbmSessionData : ISbmUserContext
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
private static long sessionIdxRoot = SacsRandomHelper.GetInt32(1000, 1999);
|
||||
// Definitions.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
/// <summary>Protected constructor for deserialisation only.</summary>
|
||||
protected SbmSessionData(long sessionIdx, int itemIdx, SbmSessionContext sessionContext)
|
||||
{
|
||||
SessionIdx = sessionIdx;
|
||||
ItemIdx = itemIdx;
|
||||
SessionContext = sessionContext;
|
||||
}
|
||||
/// <summary>
|
||||
/// Plain constructor.
|
||||
/// <para>- SessionContext must be supplied.</para>
|
||||
/// </summary>
|
||||
protected SbmSessionData(SbmSessionContext sessionContext)
|
||||
{
|
||||
SessionIdx = ++sessionIdxRoot;
|
||||
ItemIdx = 1000;
|
||||
SessionContext = sessionContext;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
// Session and Item indexers.
|
||||
public long SessionIdx { get; }
|
||||
public int ItemIdx { get; private set; }
|
||||
[JsonIgnore]
|
||||
public int NextItemIdx { get { return ++ItemIdx; } }
|
||||
|
||||
// Session context.
|
||||
public SbmSessionContext SessionContext { get; }
|
||||
|
||||
// User properties.
|
||||
[JsonIgnore]
|
||||
public abstract String UserEmailAddress { get; }
|
||||
[JsonIgnore]
|
||||
public abstract String UserDisplayName { get; }
|
||||
[JsonIgnore]
|
||||
public abstract bool ValidUser { get; }
|
||||
[JsonIgnore]
|
||||
public abstract DbUpdateInfo DbUpdateInfo { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// User.
|
||||
public class UserData
|
||||
{
|
||||
@@ -91,6 +43,61 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private static long sessionIdxNext { get; set; } = SacsRandomHelper.GetInt32(100001, 199999);
|
||||
private static long dataIdxNext { get; set; } = 1000001;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
/// <summary>
|
||||
/// Constructor to persist the Session index, eg. for deserialisation from Session.
|
||||
/// <para>- Session index of zero indicates sessionless data, eg. background tasks.</para>
|
||||
/// <para>- Session index less than zero will assign a new value.</para>
|
||||
/// </summary>
|
||||
protected SbmSessionData(long sessionIdx, SbmSessionContext sessionContext)
|
||||
{
|
||||
SessionIdx = sessionIdx >= 0 ? sessionIdx : sessionIdxNext++;
|
||||
DataIdx = dataIdxNext++;
|
||||
SessionContext = sessionContext;
|
||||
}
|
||||
/// <summary>
|
||||
/// Main constructor.
|
||||
/// <para>- SessionContext must be supplied.</para>
|
||||
/// </summary>
|
||||
protected SbmSessionData(SbmSessionContext sessionContext)
|
||||
{
|
||||
SessionIdx = sessionIdxNext++;
|
||||
DataIdx = dataIdxNext++;
|
||||
SessionContext = sessionContext;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
/// <summary>
|
||||
/// Session Index - assigned in sequence and persistent when data is serialised/deserialised.
|
||||
/// </summary>
|
||||
public long SessionIdx { get; }
|
||||
/// <summary>
|
||||
/// Data Index - assigned in sequence for each object constructed.
|
||||
/// </summary>
|
||||
public long DataIdx { get; }
|
||||
|
||||
// Session context.
|
||||
public SbmSessionContext SessionContext { get; }
|
||||
|
||||
// User properties.
|
||||
[JsonIgnore]
|
||||
public abstract String UserEmailAddress { get; }
|
||||
[JsonIgnore]
|
||||
public abstract String UserDisplayName { get; }
|
||||
[JsonIgnore]
|
||||
public abstract bool ValidUser { get; }
|
||||
[JsonIgnore]
|
||||
public abstract DbUpdateInfo DbUpdateInfo { get; }
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -3,7 +3,16 @@ using Sarand.BusinessMgr.Net.Standard.Base.Core;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr.Control;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.CodeTypes;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Diary;
|
||||
using Sarand.Net.Standard.Base.Interfaces;
|
||||
using Sarand.Net.Standard.Base.ItemData;
|
||||
using Sarand.Net.Standard.Base.ItemDocs;
|
||||
using Sarand.Net.Standard.Base.ItemOptions;
|
||||
using Sarand.Net.Standard.Base.ReferenceData;
|
||||
using Sarand.Net.Standard.Base.Security;
|
||||
using Sarand.Net.Standard.Base.UpdateLog;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -110,6 +119,20 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
public abstract SbmcInstanceMgr CreateControlInstanceMgr();
|
||||
public abstract SbmcItemMgr CreateControlItemMgr();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Consoles.
|
||||
public abstract SbmSessionConsole CreateSessionConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaDiaryConsole CreateDiaryConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaSecurityConsole CreateSecurityConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaCodeTypeConsole CreateCodeTypeConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaReferenceDataConsole CreateReferenceDataConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaItemDataConsole CreateItemDataConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaItemDocConsole CreateItemDocConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaItemOptionConsole CreateItemOptionConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaInterfaceConsole CreateInterfaceConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SaUpdateLogConsole CreateUpdateLogConsole(ISbmUserOrganisationContext userContext);
|
||||
public abstract SbmEmailConsole CreateEmailConsole(ISbmUserOrganisationContext userContext, SbmEmailConfig emailConfig);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// A p p l i c a t i o n P r o p e r t i e s
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
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;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class SbmUserContext : ISbmUserOrganisationContext
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
// User profile.
|
||||
public class UserData
|
||||
{
|
||||
protected UserData() { }
|
||||
protected readonly List<SysIdString> supervisedOwners = new List<SysIdString>();
|
||||
/// <summary>User Security Item Id.</summary>
|
||||
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> SupervisedOrganisations { get { return new List<SysIdString>(supervisedOwners); } }
|
||||
}
|
||||
private class UserData_Internal : UserData
|
||||
{
|
||||
internal UserData_Internal() { }
|
||||
internal void Clear()
|
||||
{
|
||||
SecurityItemId = new SysId();
|
||||
AffiliateId = new SysId();
|
||||
FirstName = "";
|
||||
LastName = "";
|
||||
DisplayName = "";
|
||||
EmailAddress = "";
|
||||
supervisedOwners.Clear();
|
||||
}
|
||||
internal void Refresh(SaSecurityItem securityItemUser, SbmAffiliate affiliateUser, List<SysIdString> supervisedOwners)
|
||||
{
|
||||
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
|
||||
{
|
||||
internal OrganisationData() { }
|
||||
/// <summary>Organisation Affiliate Id.</summary>
|
||||
public SysId AffiliateId { get; protected set; } = new SysId();
|
||||
/// <summary>Organisation Affiliate Type.</summary>
|
||||
public Sbm.AffiliateType AffiliateType { get; protected set; } = Sbm.AffiliateType.Unknown;
|
||||
/// <summary>Organisation display name.</summary>
|
||||
public String DisplayName { get; protected set; } = "";
|
||||
/// <summary>Organisation Interface context - to qualify interfaces belonging to the organisation.</summary>
|
||||
public String InterfaceContext { get; protected set; } = "";
|
||||
/// <summary>Organisation 'Internal' Association Id.</summary>
|
||||
public SysId AssociationId { get; protected set; } = new SysId();
|
||||
}
|
||||
private class OrganisationData_Internal : OrganisationData
|
||||
{
|
||||
internal OrganisationData_Internal() { }
|
||||
internal void Clear()
|
||||
{
|
||||
AffiliateId = new SysId();
|
||||
AffiliateType = Sbm.AffiliateType.Unknown;
|
||||
DisplayName = "";
|
||||
InterfaceContext = "";
|
||||
}
|
||||
internal void Refresh(SbmAffiliate affiliateOrganisation, SbmAssociation associationInternal, String interfaceContext)
|
||||
{
|
||||
AffiliateId = SysId.InvalidOnNull(affiliateOrganisation.Id);
|
||||
AffiliateType = affiliateOrganisation.AffiliateType;
|
||||
DisplayName = StringUtil.EmptyOnNull(affiliateOrganisation.GetDisplayName()).TrimAll();
|
||||
InterfaceContext = StringUtil.EmptyOnNull(interfaceContext);
|
||||
AssociationId = associationInternal.Id;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly UserData_Internal userData = new UserData_Internal();
|
||||
private readonly OrganisationData_Internal organisationData;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SbmUserContext(SbmSessionContext sessionContext)
|
||||
{
|
||||
SessionContext = sessionContext;
|
||||
organisationData = new OrganisationData_Internal();
|
||||
securityProfile = new SbmSecurityProfile(this, true);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public SbmSessionContext SessionContext { get; protected set; }
|
||||
|
||||
// User properties.
|
||||
public UserData User { get { return userData; } }
|
||||
/// <summary>User Security Item Id.</summary>
|
||||
public SysId UserSecurityItemId { get { return User?.SecurityItemId; } }
|
||||
/// <summary>User Affiliate Id.</summary>
|
||||
public SysId UserAffiliateId { get { return User?.AffiliateId; } }
|
||||
/// <summary>User display name.</summary>
|
||||
public String UserDisplayName { get { return userData?.DisplayName; } }
|
||||
/// <summary>User email address.</summary>
|
||||
public String UserEmailAddress { get { return userData?.EmailAddress; } }
|
||||
public bool ValidUser { get { return SysId.IsValid(userData.SecurityItemId) && SysId.IsValid(userData?.AffiliateId); } }
|
||||
public DbUpdateInfo DbUpdateInfo { get { return new DbUpdateInfo(userData?.AffiliateId, userData?.DisplayName ?? "", SacsSystem.ComputerName); } }
|
||||
|
||||
// Organisation properties.
|
||||
public OrganisationData Organisation { get { return organisationData; } }
|
||||
/// <summary>Organisation Affiliate Id.</summary>
|
||||
public SysId OrganisationAffiliateId { get { return Organisation?.AffiliateId; } }
|
||||
/// <summary>Organisation Affiliate Type.</summary>
|
||||
public Sbm.AffiliateType OrganisationAffiliateType { get { return Organisation?.AffiliateType ?? Sbm.AffiliateType.Unknown; } }
|
||||
/// <summary>Organisation 'Internal' Association Id.</summary>
|
||||
public SysId OrganisationAssociationId { get { return Organisation?.AssociationId; } }
|
||||
/// <summary>Organisation display name.</summary>
|
||||
public String OrganisationDisplayName { get { return Organisation?.DisplayName; } }
|
||||
/// <summary>Organisation Interface context - to qualify interfaces belonging to the organisation.</summary>
|
||||
public String OrganisationInterfaceContext { get { return Organisation?.InterfaceContext; } }
|
||||
public List<SysIdString> SupervisedOrganisations { get { return new List<SysIdString>(userData.SupervisedOrganisations); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Security profile.
|
||||
private SbmSecurityProfile securityProfile { get; set; }
|
||||
public ISbmSecurityProfile_Core SecurityProfile_Core { get { return securityProfile; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Modify properties - internal only.
|
||||
protected void SetUserData(SaSecurityItem securityItemUser, SbmAffiliate affiliateUser, List<SysIdString> supervisedOwners)
|
||||
{
|
||||
userData.Refresh(securityItemUser, affiliateUser, supervisedOwners);
|
||||
}
|
||||
protected void ClearUserData()
|
||||
{
|
||||
userData.Clear();
|
||||
organisationData.Clear();
|
||||
SetSecurityProfile(new SbmSecurityProfile(this, true));
|
||||
}
|
||||
protected void SetOrganisationData(SysId affiliateIdOrganisation)
|
||||
{
|
||||
// Interface context for selected organisation.
|
||||
String interfaceContext = SbmAccountMgr.GetInterfaceContext(affiliateIdOrganisation);
|
||||
|
||||
if (SysId.IsValid(affiliateIdOrganisation))
|
||||
{
|
||||
using (SbmAccountMgr accountMgr = SbmGlobals.System.CreateAccountMgr(this))
|
||||
// Affiliate.
|
||||
using (SbmAffiliate affiliateOrganisation = accountMgr.GetAffiliateById(affiliateIdOrganisation))
|
||||
// 'Internal' association.
|
||||
using (SbmAssociation associationInternal = accountMgr.GetAssociationByOwnerTypeTarget(affiliateIdOrganisation, Sbm.AssociationType.Internal, affiliateIdOrganisation))
|
||||
|
||||
if (affiliateOrganisation != null && associationInternal != null)
|
||||
{
|
||||
// Refresh the organisation properties.
|
||||
organisationData.Refresh(affiliateOrganisation, associationInternal, interfaceContext);
|
||||
}
|
||||
else ClearOrganisationData();
|
||||
}
|
||||
}
|
||||
protected void ClearOrganisationData()
|
||||
{
|
||||
organisationData.Clear();
|
||||
}
|
||||
protected void SetSecurityProfile(SbmSecurityProfile securityProfile)
|
||||
{
|
||||
this.securityProfile = securityProfile;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user