Portal application - initial.

This commit is contained in:
2021-07-08 20:50:46 +01:00
parent 13c79a8da4
commit 01ae03ddfc
1208 changed files with 186342 additions and 1690 deletions
@@ -0,0 +1,45 @@
using Sarand.Net.Standard.Base.App;
using Sarand.Net.Standard.Base.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sarand.BusinessMgr.Net.Standard.Base.App
{
//=======================================================================
static partial class Sbm
{
//-------------------------------------------------------------------
// Application version.
//-------------------------------------------------------------------
public static class Version
{
private static String version { get; } = "3.0.0.0";
// Retrieve version.
public static String GetFullVersion() { return version; }
public static String GetAppVersion()
{
if (!SbmSystem.DebugMode)
{
try
{
// Live instance version is only first 3 elements.
String[] versionElements = version.Split('.');
return String.Join(".", versionElements.Take(3));
}
catch (Exception exc) { SaLogger.Warn("Sbm.Version.ToString " + ExceptionUtil.GetErrorStateMessage(exc)); }
}
return version;
}
}
//-------------------------------------------------------------------
// Version history.
//-------------------------------------------------------------------
// 3.0.0 ?-Jul-2021 Initial demo test version.
// - .
//-------------------------------------------------------------------
}
//=======================================================================
}
@@ -1,21 +1,106 @@
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.App;
using Sarand.Net.Standard.Base.Core;
using System;
using System.Collections.Generic;
namespace Sarand.BusinessMgr.Net.Standard.Base.App
{
//=======================================================================
public static class Sbm
public static partial class Sbm
{
//-------------------------------------------------------------------
// Application configuration defaults.
public static class Config
{
public static String Context_Defaults { get; } = "Defaults";
public static class Security
{
public static class Password
{
}
public static class Activation
{
public static int EmailLinkExpiresMins_Default { get; } = 60;
public static int EmailLinkExpiresMins_Min { get; } = 30;
public static int EmailLinkExpiresMins_Max { get; } = 60 * 24;
}
public static class SignIn
{
public static class PasswordRequest
{
public static int EmailLinkExpiresMins_Default { get; } = 60;
public static int EmailLinkExpiresMins_Min { get; } = 30;
public static int EmailLinkExpiresMins_Max { get; } = 60 * 24;
}
public static class KeepLoggedIn
{
public static bool Allowed_Default { get; } = true;
public static int CookieExpiresDays_Default { get; } = 10;
public static int CookieExpiresDays_Min { get; } = 1;
public static int CookieExpiresDays_Max { get; } = 30;
}
}
}
public class Online
{
public static class Session
{
public static class Cookie
{
/// <summary>Default cookie name: '.AspNetCore.Session'</summary>
public static String Name { get; } = "BusinessMgr.Online.Session";
public static bool HttpOnly { get; } = true;
public static TimeSpan IdleTimeout { get; } = SacsSystem.DebugMode ? TimeSpan.FromMinutes(5) : TimeSpan.FromMinutes(60);
public static long RememberMeTimeoutMilis { get; } = (long)(SacsSystem.DebugMode ? TimeSpan.FromMinutes(2) : TimeSpan.FromMinutes(10)).TotalMilliseconds;
}
}
public static class DataCache
{
public static class RefreshIntervalSecs
{
public static int Initial { get; } = SacsSystem.DebugMode ? 2 : 5;
public static int Periodic { get; } = SacsSystem.DebugMode ? 60 : 1800;
}
}
}
public class Admin
{
public static class Session
{
public static class Cookie
{
/// <summary>Default cookie name: '.AspNetCore.Session'</summary>
public static String Name { get; } = "BusinessMgr.Admin.Session";
public static bool HttpOnly { get; } = true;
public static TimeSpan IdleTimeout { get; } = SacsSystem.DebugMode ? TimeSpan.FromMinutes(5) : TimeSpan.FromMinutes(15);
public static long KeepLoggedInTimeoutMillis { get; } = (long)(SacsSystem.DebugMode ? TimeSpan.FromMinutes(2) : TimeSpan.FromMinutes(10)).TotalMilliseconds;
}
}
}
}
//-------------------------------------------------------------------
// Definitions.
public static String Version { get; } = "3.0.0.0";
public static String ApplicationCaption { get; } = "Sarand BusinessMgr";
// Option values.
public static String ValueYes { get; } = "YES";
public static String ValueNo { get; } = "NO";
public static List<CodeDesc> ValuesYesNo { get; } = new List<CodeDesc>() { new CodeDesc(ValueYes, "Yes"), new CodeDesc(ValueNo, "No") };
//-------------------------------------------------------------------
public enum Application
{
WebControl,
WebPortal,
}
public enum InstanceType
{
Production,
UAT,
QC,
Dev
}
//-------------------------------------------------------------------
// Configuration console.
public enum ConfigConsole
+19 -16
View File
@@ -12,9 +12,10 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
//-------------------------------------------------------------------
// A p p l i c a t i o n V i e w s
//-------------------------------------------------------------------
public static bool IsViewApplicable(SbmUserContext userContext, Sbm.View view)
// Jul-2021 ConfigConsole parameter added to avoid local creation. To be reviewed/replaced.
public static bool IsViewApplicable(SbmUserContext userContext, SbmConfigConsole configConsole, Sbm.View view)
{
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(userContext.SessionContext);
//SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(userContext.SessionContext);
SbmSecurityProfile securityProfile = userContext.SecurityProfile;
switch (view)
{
@@ -223,11 +224,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
case Sbm.View.SystemUsers:
if (!configConsole.AllowOption(userContext, Sbm.ConfigOption.AllowContacts)) return false;
// Interfaces must be available.
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
if (interfaceConsole == null || !interfaceConsole.DatabaseIsValid) return false;
// System Account & User tables must be available.
if (!SbmGlobals.Application.TableExists(userContext.SessionContext, SbmDbDfn.TableIdx.SystemAccount)) return false;
if (!SbmGlobals.Application.TableExists(userContext.SessionContext, SbmDbDfn.TableIdx.SystemUser)) return false;
using (SaInterfaceConsole interfaceConsole = SbmGlobals.Application.CreateInterfaceConsole(userContext))
{
if (interfaceConsole == null || !interfaceConsole.DatabaseIsValid) return false;
// System Account & User tables must be available.
if (!SbmGlobals.Application.BusMgrTableExists(userContext.SessionContext, SbmDbDfn.TableIdx.SystemAccount)) return false;
if (!SbmGlobals.Application.BusMgrTableExists(userContext.SessionContext, SbmDbDfn.TableIdx.SystemUser)) return false;
}
return true;
}
@@ -257,7 +260,7 @@ 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(SbmUserContext userContext, Sbm.MenuOption menuOption)
public static bool IsMenuOptionApplicable(SbmUserContext userContext, SbmConfigConsole configConsole, Sbm.MenuOption menuOption)
{
String fn = ClassName + ".IsMenuOptionApplicable";
if (!userContext.ValidUser)
@@ -268,7 +271,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
Sbm.View view = GetViewForMenuOption(userContext.SessionContext, menuOption);
if (view != Sbm.View.Unknown)
// View options.
return IsViewApplicable(userContext, GetViewForMenuOption(userContext.SessionContext, menuOption));
return IsViewApplicable(userContext, configConsole, GetViewForMenuOption(userContext.SessionContext, menuOption));
// Non-view options.
switch (menuOption)
@@ -278,16 +281,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
case Sbm.MenuOption.Config_Organisation:
return true;
case Sbm.MenuOption.Config_CodeTypes:
return (SbmGlobals.Application.GetCodeTypeConsole(userContext) != null);
return true; // (SbmGlobals.Application.GetCodeTypeConsole(userContext) != null);
case Sbm.MenuOption.Config_Interfaces:
return (SbmGlobals.Application.GetInterfaceConsole(userContext) != null);
return true; // (SbmGlobals.Application.GetInterfaceConsole(userContext) != null);
case Sbm.MenuOption.Security_Manage:
return (SbmGlobals.Application.GetSecurityConsole(userContext) != null);
//-----------------------------------------------------------
// Actions.
return true; // (SbmGlobals.Application.GetSecurityConsole(userContext) != null);
//-----------------------------------------------------------
// Actions.
case Sbm.MenuOption.Timesheet:
return SbmGlobals.Application.GetConfigConsole(userContext.SessionContext).AllowOption(userContext, Sbm.ConfigOption.TimeRecording);
//-----------------------------------------------------------
return configConsole.AllowOption(userContext, Sbm.ConfigOption.TimeRecording);
//-----------------------------------------------------------
}
SaLogger.Warn(fn + " Unsupport menu option - " + menuOption.ToString());
return false;
+36 -47
View File
@@ -1,9 +1,10 @@
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
using Sarand.Net.Standard.Base.CodeTypes;
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Dbas;
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;
@@ -42,55 +43,43 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
}
//-------------------------------------------------------------------
// Properties.
public abstract SbmSystem System { get; }
// Database.
public abstract ISacsDatabase GetDatabase(SbmSessionContext sessionContext);
public abstract bool TableExists(SbmSessionContext sessionContext, SbmDbDfn.TableIdx tableIdx);
public abstract bool ColumnExists(SbmSessionContext sessionContext, SbmDbDfn.ColumnIdx columnIdx);
public abstract ISacsDatabase GetBusMgrDatabase(SbmSessionContext sessionContext);
public abstract IDatabaseInfo CreateBusMgrDbInfo(SbmSessionContext sessionContext);
public bool BusMgrTableExists(SbmSessionContext sessionContext, SbmDbDfn.TableIdx tableIdx)
{
ISacsDatabase db = GetBusMgrDatabase(sessionContext);
return db?.TableExists(SbmDbDfn.GetTableName(tableIdx)) ?? false;
}
public bool BusMgrColumnExists(SbmSessionContext sessionContext, SbmDbDfn.ColumnIdx columnIdx)
{
ISacsDatabase db = GetBusMgrDatabase(sessionContext);
return db?.ColumnExists(SbmDbDfn.GetTableName(SbmDbDfn.GetTableForColumn(columnIdx)), SbmDbDfn.GetColumnName(columnIdx, false)) ?? false;
}
// Application instance.
public abstract Sbm.InstanceType InstanceType { get; }
public bool IsLiveHost() { return InstanceType == Sbm.InstanceType.Production; }
public bool IsTestHost() { return InstanceType != Sbm.InstanceType.Production; }
public bool IsDevHost() { return InstanceType == Sbm.InstanceType.Dev; }
public abstract String EnvironmentName { get; }
// Email configuration.
public abstract SbmEmailConfig EmailConfig { get; }
//-------------------------------------------------------------------
// Config Console.
public abstract SbmConfigConsole GetConfigConsole(SbmSessionContext sessionContext);
//-------------------------------------------------------------------
// Managers.
public abstract SbmAccountMgr CreateAccountMgr(SbmUserContext userContext);
public abstract SbmTransactionMgr CreateTransactionMgr(SbmUserContext userContext);
//-------------------------------------------------------------------
// Diary console.
public abstract SaDiaryConsole GetDiaryConsole(SbmUserContext userContext);
//-------------------------------------------------------------------
// Security console.
public abstract SaSecurityConsole GetSecurityConsole(SbmUserContext userContext);
//-------------------------------------------------------------------
// Code Type console.
public abstract SaCodeTypeConsole GetCodeTypeConsole(SbmUserContext userContext);
//-------------------------------------------------------------------
// Reference Data console.
public abstract SaReferenceDataConsole GetReferenceDataConsole(SbmUserContext userContext);
//-------------------------------------------------------------------
// Item Data console.
public abstract Sarand.Net.Standard.Base.ItemData.SaItemDataConsole GetItemDataConsole(SbmUserContext userContext);
//-------------------------------------------------------------------
// Item Doc console.
public abstract SaItemDocConsole GetItemDocConsole(SbmUserContext userContext);
//-------------------------------------------------------------------
// Item Option console.
public abstract SaItemOptionConsole GetItemOptionConsole(SbmUserContext userContext);
//-------------------------------------------------------------------
// Interface console.
public abstract SaInterfaceConsole GetInterfaceConsole(SbmUserContext userContext);
//-------------------------------------------------------------------
// Update Log console.
public abstract SaUpdateLogConsole GetUpdateLogConsole(SbmUserContext userContext);
// Create consoles.
public abstract SbmConfigConsole CreateConfigConsole(SbmSessionContext sessionContext);
public abstract SaDiaryConsole CreateDiaryConsole(SbmUserContext userContext);
public abstract SaSecurityConsole CreateSecurityConsole(SbmUserContext userContext);
public abstract SaCodeTypeConsole CreateCodeTypeConsole(SbmUserContext userContext);
public abstract SaReferenceDataConsole CreateReferenceDataConsole(SbmUserContext userContext);
public abstract SaItemDataConsole CreateItemDataConsole(SbmUserContext userContext);
public abstract SaItemDocConsole CreateItemDocConsole(SbmUserContext userContext);
public abstract SaItemOptionConsole CreateItemOptionConsole(SbmUserContext userContext);
public abstract SaInterfaceConsole CreateInterfaceConsole(SbmUserContext userContext);
public abstract SaUpdateLogConsole CreateUpdateLogConsole(SbmUserContext userContext);
public abstract SbmEmailConsole CreateEmailConsole(SbmUserContext userContext);
//-------------------------------------------------------------------
}
@@ -77,7 +77,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
protected SbmConfigConsole(Sbm.ConfigConsole configConsole, SbmVersion consoleVersion, SbmSessionContext sessionContext)
{
ConfigConsole = configConsole;
AppVersion = new SbmVersion("BusinessMgr", Sbm.Version, SbmSystem.AssemblyBuildAt);
AppVersion = new SbmVersion("BusinessMgr", Sbm.Version.GetFullVersion(), SbmSystem.AssemblyBuildAt);
ConsoleVersion = consoleVersion;
SessionContext = sessionContext;
}
@@ -103,7 +103,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
String fn = "SbmConfigConsole.CreateConsole";
SaLogger.Warn(fn + ".CreateConsole Creating default configuration console.");
// Default console.
SbmVersion consoleVersion = new SbmVersion("Standard", Sbm.Version, SbmSystem.AssemblyBuildAt);
SbmVersion consoleVersion = new SbmVersion("Standard", Sbm.Version.GetFullVersion(), SbmSystem.AssemblyBuildAt);
return new SbmConfigConsole(Sbm.ConfigConsole.Generic, consoleVersion, sessionContext);
}
@@ -593,7 +593,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
public virtual bool SetMinTransactionId(SbmUserContext userContext, SysId AffiliateId_Owner, SysId idAssoc, Sbm.TransactionType transTypes, long iId)
{
bool set = false;
if (SbmGlobals.Application.GetDatabase(SessionContext) != null)
if (SbmGlobals.Application.GetBusMgrDatabase(SessionContext) != null)
{
String nextIdKey = GetTransactionNextIdKey(userContext, AffiliateId_Owner, idAssoc, transTypes);
// ToDo set = SbmGlobals.Database.SetMinNextId(nextIdKey, iId, false);
@@ -607,7 +607,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
(SbmUserContext userContext, SysId AffiliateId_Owner, SysId idAssoc, Sbm.TransactionType transTypes)
{
String Ref = "";
if (SbmGlobals.Application.GetDatabase(SessionContext) != null)
if (SbmGlobals.Application.GetBusMgrDatabase(SessionContext) != null)
{
String NextIdKey = GetTransactionNextIdKey(userContext, AffiliateId_Owner, idAssoc, transTypes);
// ToDo long iRefNext = SbmGlobals.Database.GetNextId(NextIdKey, false);
@@ -1,39 +0,0 @@
using Sarand.Net.Standard.Base.CodeTypes;
using Sarand.Net.Standard.Base.Dbas;
using Sarand.Net.Standard.Base.Interfaces;
using Sarand.Net.Standard.Base.ItemOptions;
using Sarand.Net.Standard.Base.ReferenceData;
using Sarand.Net.Standard.Base.Security;
using Sarand.Net.Standard.Base.UpdateLog;
namespace Sarand.BusinessMgr.Net.Standard.Base.App
{
//=======================================================================
public abstract class SbmConsoleHelper
{
//-------------------------------------------------------------------
// Protected construction - use derived objects.
protected SbmConsoleHelper()
{
}
//-------------------------------------------------------------------
// Database.
public abstract ISacsDatabase GetDatabase(SbmSessionContext sessionContext);
//-------------------------------------------------------------------
// Create local consoles.
//-------------------------------------------------------------------
// Retrieve Global Consoles by session context.
public abstract SaSecurityConsole GetSecurityConsole(SbmSessionContext sessionContext);
public abstract SaCodeTypeConsole GetCodeTypeConsole(SbmSessionContext sessionContext);
public abstract SaReferenceDataConsole GetReferenceDataConsole(SbmSessionContext sessionContext);
public abstract SaItemOptionConsole GetItemOptionConsole(SbmSessionContext sessionContext);
public abstract SaInterfaceConsole GetInterfaceConsole(SbmSessionContext sessionContext);
public abstract SaUpdateLogConsole GetUpdateLogConsole(SbmSessionContext sessionContext);
//-------------------------------------------------------------------
}
//=======================================================================
}
+2 -72
View File
@@ -24,79 +24,9 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
//-------------------------------------------------------------------
// Database.
public static ISacsDatabase GetDatabase(SbmSessionContext sessionContext)
public static ISacsDatabase GetBusMgrDatabase(SbmSessionContext sessionContext)
{
return Application != null ? Application.GetDatabase(sessionContext) : null;
}
//-------------------------------------------------------------------
// Configuration console.
public static SbmConfigConsole GetConfigConsole(SbmSessionContext sessionContext)
{
return Application != null ? Application.GetConfigConsole(sessionContext) : null;
}
//-------------------------------------------------------------------
// Diary.
public static SaDiaryConsole GetDiaryConsole(SbmUserContext userContext)
{
return Application != null ? Application.GetDiaryConsole(userContext) : null;
}
//-------------------------------------------------------------------
// Security console.
public static SaSecurityConsole GetSecurityConsole(SbmUserContext userContext)
{
return Application != null ? Application.GetSecurityConsole(userContext) : null;
}
//-------------------------------------------------------------------
// Code Type console.
public static SaCodeTypeConsole GetCodeTypeConsole(SbmUserContext userContext)
{
return Application != null ? Application.GetCodeTypeConsole(userContext) : null;
}
//-------------------------------------------------------------------
// Reference Data console.
public static SaReferenceDataConsole GetReferenceDataConsole(SbmUserContext userContext)
{
return Application != null ? Application.GetReferenceDataConsole(userContext) : null;
}
//-------------------------------------------------------------------
// Item Data console.
public static SaItemDataConsole GetItemDataConsole(SbmUserContext userContext)
{
return Application != null ? Application.GetItemDataConsole(userContext) : null;
}
//-------------------------------------------------------------------
// Item Doc console.
public static SaItemDocConsole GetItemDocConsole(SbmUserContext userContext)
{
return Application != null ? Application.GetItemDocConsole(userContext) : null;
}
//-------------------------------------------------------------------
// Item Option console.
public static SaItemOptionConsole GetItemOptionConsole(SbmUserContext userContext)
{
return Application != null ? Application.GetItemOptionConsole(userContext) : null;
}
//-------------------------------------------------------------------
// Interface console.
public static SaInterfaceConsole GetInterfaceConsole(SbmUserContext userContext)
{
return Application != null ? Application.GetInterfaceConsole(userContext) : null;
}
//-------------------------------------------------------------------
// Update Log console.
public static SaUpdateLogConsole GetUpdateLogConsole(SbmUserContext userContext)
{
return Application != null ? Application.GetUpdateLogConsole(userContext) : null;
return Application != null ? Application.GetBusMgrDatabase(sessionContext) : null;
}
//-------------------------------------------------------------------
+72 -8
View File
@@ -1,10 +1,14 @@
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.CodeTypes;
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Dbas;
using Sarand.Net.Standard.Base.Diary;
using Sarand.Net.Standard.Base.Email;
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;
@@ -34,6 +38,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
private SbmDataItemMgr dataItemMgr;
// Consoles.
private SbmConfigConsole configConsole;
private SaDiaryConsole diaryConsole;
private SaSecurityConsole securityConsole;
private SaCodeTypeConsole codeTypeConsole;
private SaReferenceDataConsole referenceDataConsole;
@@ -41,6 +46,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
private SaInterfaceConsole interfaceConsole;
private SaItemDocConsole itemDocConsole;
private SaItemOptionConsole itemOptionConsole;
private SaItemDataConsole itemDataConsole;
public SbmEmailConsole emailConsole;
// Configurations.
private SbmStockControlConfig stockControlConfig;
private SbmRequirementCostingConfig requirementCostingConfig;
@@ -59,6 +66,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
{
if (disposing)
{
// Managers.
if (accountMgr != null) accountMgr.Dispose();
if (assetMgr != null) assetMgr.Dispose();
if (commodityMgr != null) commodityMgr.Dispose();
@@ -70,17 +78,42 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
if (currencies != null) currencies.ClearAndDispose();
if (taxCodes != null) taxCodes.ClearAndDispose();
if (unitsOfMeasure != null) unitsOfMeasure.ClearAndDispose();
// Consoles.
if (configConsole != null) configConsole.Dispose();
if (diaryConsole != null) diaryConsole.Dispose();
if (securityConsole != null) securityConsole.Dispose();
if (codeTypeConsole != null) codeTypeConsole.Dispose();
if (referenceDataConsole != null) referenceDataConsole.Dispose();
if (updateLogConsole != null) updateLogConsole.Dispose();
if (interfaceConsole != null) interfaceConsole.Dispose();
if (itemDocConsole != null) itemDocConsole.Dispose();
if (itemOptionConsole != null) itemOptionConsole.Dispose();
if (itemDataConsole != null) itemDataConsole.Dispose();
if (itemDataConsole != null) itemDataConsole.Dispose();
}
}
//-------------------------------------------------------------------
// Session properties.
public SbmApplication Application { get { return SbmGlobals.Application; } }
public SbmUserContext UserContext { get; }
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
public SbmSecurityProfile SecurityProfile { get { return UserContext.SecurityProfile; } }
public SbmAccountsDfn AccountsDfn { get { if (accountsDfn == null) accountsDfn = new SbmAccountsDfn(UserContext); { return accountsDfn; } } }
// Database.
public ISacsDatabase BusMgrDatabase { get { return Application.GetBusMgrDatabase(SessionContext); } }
public DbUpdateInfo DbUpdateInfo { get { return UserContext.DbUpdateInfo; } }
//-------------------------------------------------------------------
// System codes.
private Dictionary<Sbm.SystemCode, List<TypeCodeDesc>> systemCodeCache = new Dictionary<Sbm.SystemCode, List<TypeCodeDesc>>();
public List<TypeCodeDesc> GetCodesOfType(Sbm.SystemCode systemCode)
{
if (!systemCodeCache.ContainsKey(systemCode))
systemCodeCache.Add(systemCode, SbmSystem.GetCodesOfType(UserContext, systemCode));
return systemCodeCache.GetValueOrDefault(systemCode, new List<TypeCodeDesc>());
}
//-------------------------------------------------------------------
// Managers.
public SbmAccountMgr AccountMgr
@@ -163,16 +196,25 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
get
{
if (configConsole == null)
configConsole = SbmGlobals.GetConfigConsole(SessionContext);
configConsole = Application.CreateConfigConsole(SessionContext);
return configConsole;
}
}
public SaDiaryConsole DiaryConsole
{
get
{
if (diaryConsole == null)
diaryConsole = Application.CreateDiaryConsole(UserContext);
return DiaryConsole;
}
}
public SaSecurityConsole SecurityConsole
{
get
{
if (securityConsole == null)
securityConsole = SbmGlobals.GetSecurityConsole(UserContext);
securityConsole = Application.CreateSecurityConsole(UserContext);
return securityConsole;
}
}
@@ -181,7 +223,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
get
{
if (codeTypeConsole == null)
codeTypeConsole = SbmGlobals.GetCodeTypeConsole(UserContext);
codeTypeConsole = Application.CreateCodeTypeConsole(UserContext);
return codeTypeConsole;
}
}
@@ -190,7 +232,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
get
{
if (referenceDataConsole == null)
referenceDataConsole = SbmGlobals.GetReferenceDataConsole(UserContext);
referenceDataConsole = Application.CreateReferenceDataConsole(UserContext);
return referenceDataConsole;
}
}
@@ -199,7 +241,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
get
{
if (updateLogConsole == null)
updateLogConsole = SbmGlobals.GetUpdateLogConsole(UserContext);
updateLogConsole = Application.CreateUpdateLogConsole(UserContext);
return updateLogConsole;
}
}
@@ -208,7 +250,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
get
{
if (interfaceConsole == null)
interfaceConsole = SbmGlobals.GetInterfaceConsole(UserContext);
interfaceConsole = Application.CreateInterfaceConsole(UserContext);
return interfaceConsole;
}
}
@@ -217,7 +259,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
get
{
if (itemDocConsole == null)
itemDocConsole = SbmGlobals.GetItemDocConsole(UserContext);
itemDocConsole = Application.CreateItemDocConsole(UserContext);
return itemDocConsole;
}
}
@@ -226,10 +268,32 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
get
{
if (itemOptionConsole == null)
itemOptionConsole = SbmGlobals.GetItemOptionConsole(UserContext);
itemOptionConsole = Application.CreateItemOptionConsole(UserContext);
return itemOptionConsole;
}
}
public SaItemDataConsole ItemDataConsole
{
get
{
if (itemDataConsole == null)
itemDataConsole = Application.CreateItemDataConsole(UserContext);
return itemDataConsole;
}
}
//-------------------------------------------------------------------
// Email.
public SaEmailConfig EmailConfig { get { return Application.EmailConfig; } }
public SbmEmailConsole EmailConsole
{
get
{
if (emailConsole == null)
emailConsole = Application.CreateEmailConsole(UserContext);
return emailConsole;
}
}
//-------------------------------------------------------------------
// Configurations.
@@ -39,7 +39,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
//-------------------------------------------------------------------
// Refresh profile.
public void RefreshProfile(SaSecurityConsole securityConsole, SysId userId, List<TypeCodeDesc> securityRights)
public void RefreshProfile(SbmConfigConsole configConsole, SaSecurityConsole securityConsole, SysId userId, List<TypeCodeDesc> securityRights)
{
String fn = GetType().Name + ".RefreshProfile";
ClearErrorState();
@@ -62,53 +62,33 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
}
SaLogger.Debug(fn + " User: '" + UserDisplayName + "' [Id: " + UserId + "]" + (SysId.IsValid(previousUserId) ? ". Previous UserId: " + SysId.ToString(previousUserId) : ""));
RefreshProfileSettings();
RefreshProfileSettings(configConsole);
}
protected void RefreshProfile(SaSecurityProfile userSecurityProfile, SaSecurityProfile hostSecurityProfile)
protected void RefreshProfile(SbmConfigConsole configConsole, SaSecurityProfile userSecurityProfile, SaSecurityProfile hostSecurityProfile)
{
this.userSecurityProfile = userSecurityProfile;
this.hostSecurityProfile = hostSecurityProfile;
RefreshProfileSettings();
RefreshProfileSettings(configConsole);
}
private void RefreshProfileSettings()
private void RefreshProfileSettings(SbmConfigConsole configConsole)
{
// Admin.
Admin.CanManageSecurity = UserHasSecurityRight(Sbm.SecurityRight.Security_Admin);
Admin.CanManageDatabase = UserHasSecurityRight(Sbm.SecurityRight.Database_Admin);
Admin.CanManageReferenceData = UserHasSecurityRight(Sbm.SecurityRight.ReferenceData_Admin);
Admin.CanManageInterfaces = UserHasSecurityRight(Sbm.SecurityRight.InterfaceConfig);
// Manage.
Manage.CanManageTasks = UserHasSecurityRight(Sbm.SecurityRight.TaskManager);
Manage.CanManageTimesheets = UserHasSecurityRight(Sbm.SecurityRight.TimesheetManager);
//Financials.
Financial.CanViewFinancials = UserHasSecurityRight(Sbm.SecurityRight.Financial_View);
Financial.CanUpdateFinancials = UserHasSecurityRight(Sbm.SecurityRight.Financial_Update);
Financial.CanViewCommoditySupplyFinancials = UserCanAccessFinancialViewOfType(Sbm.FinancialType.CommoditySupply);
Financial.CanUpdateCommoditySupplyFinancials = UserCanAccessFinancialUpdateOfType(Sbm.FinancialType.CommoditySupply);
Financial.CanViewCommoditySalesFinancials = UserCanAccessFinancialViewOfType(Sbm.FinancialType.CommoditySales);
Financial.CanUpdateCommoditySalesFinancials = UserCanAccessFinancialUpdateOfType(Sbm.FinancialType.CommoditySales);
// Contacts.
Contacts.CanUpdate = (UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Update));
Contacts.CanCreate = (Contacts.CanUpdate || UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Create));
// Transactions.
Transaction.CanUpdate = (UserHasSecurityRight(Sbm.SecurityRight.Transaction_Update));
Transaction.CanCreate = (Transaction.CanUpdate || UserHasSecurityRight(Sbm.SecurityRight.Transaction_View));
RefreshAdminProfile(configConsole);
RefreshManageProfile(configConsole);
RefreshFinancialProfile(configConsole);
RefreshContactsProfile(configConsole);
RefreshTransactionProfile(configConsole);
RefreshItemTypeProfile(configConsole);
// ToDo Commodities.
}
private void ClearProfile()
{
// Reset security profiles.
Admin.Clear();
Manage.Clear();
Financial.Clear();
Contacts.Clear();
Transaction.Clear();
Admin = new AdminProfile(this);
Manage = new ManageProfile(this);
Financial = new FinancialProfile(this);
Contacts = new ContactsProfile(this);
Transaction = new TransactionsProfile(this);
}
//-------------------------------------------------------------------
@@ -152,15 +132,15 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
public bool CanManageDatabase { get; internal set; } = false;
public bool CanManageReferenceData { get; internal set; } = false;
public bool CanManageInterfaces { get; internal set; } = false;
internal void Clear()
{
CanManageSecurity = false;
CanManageDatabase = false;
CanManageReferenceData = false;
CanManageInterfaces = false;
}
}
public AdminProfile Admin { get; }
public AdminProfile Admin { get; internal set; }
private void RefreshAdminProfile(SbmConfigConsole configConsole)
{
Admin.CanManageSecurity = UserHasSecurityRight(Sbm.SecurityRight.Security_Admin);
Admin.CanManageDatabase = UserHasSecurityRight(Sbm.SecurityRight.Database_Admin);
Admin.CanManageReferenceData = UserHasSecurityRight(Sbm.SecurityRight.ReferenceData_Admin);
Admin.CanManageInterfaces = UserHasSecurityRight(Sbm.SecurityRight.InterfaceConfig);
}
//-------------------------------------------------------------------
// Security rights - Manage.
@@ -173,12 +153,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
}
public bool CanManageTasks { get; internal set; } = false;
public bool CanManageTimesheets { get; internal set; } = false;
internal void Clear()
{
CanManageTasks = false;
}
}
public ManageProfile Manage { get; }
public ManageProfile Manage { get; internal set; }
private void RefreshManageProfile(SbmConfigConsole configConsole)
{
Manage.CanManageTasks = UserHasSecurityRight(Sbm.SecurityRight.TaskManager);
Manage.CanManageTimesheets = UserHasSecurityRight(Sbm.SecurityRight.TimesheetManager);
}
//-------------------------------------------------------------------
// Security rights - Financials.
@@ -189,28 +170,30 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
{
this.securityProfile = securityProfile;
}
public bool CanViewFinancials { get; internal set; } = false;
public bool CanUpdateFinancials { get; internal set; } = false;
public bool CanViewCommoditySupplyFinancials { get; internal set; } = false;
public bool CanUpdateCommoditySupplyFinancials { get; internal set; } = false;
public bool CanViewCommoditySalesFinancials { get; internal set; } = false;
public bool CanUpdateCommoditySalesFinancials { get; internal set; } = false;
internal void Clear()
{
CanViewFinancials = false;
CanUpdateFinancials = false;
CanViewCommoditySupplyFinancials = false;
CanUpdateCommoditySupplyFinancials = false;
CanViewCommoditySalesFinancials = false;
CanUpdateCommoditySalesFinancials = false;
}
public bool CanViewFinancials { get; internal set; }
public bool CanUpdateFinancials { get; internal set; }
public bool CanViewCommoditySupplyFinancials { get; internal set; }
public bool CanUpdateCommoditySupplyFinancials { get; internal set; }
public bool CanViewCommoditySalesFinancials { get; internal set; }
public bool CanUpdateCommoditySalesFinancials { get; internal set; }
public bool ConfigOption_AllowFinancialsAccessControl { get; internal set; }
}
public FinancialProfile Financial { get; internal set; }
private void RefreshFinancialProfile(SbmConfigConsole configConsole)
{
Financial.CanViewFinancials = UserHasSecurityRight(Sbm.SecurityRight.Financial_View);
Financial.CanUpdateFinancials = UserHasSecurityRight(Sbm.SecurityRight.Financial_Update);
Financial.CanViewCommoditySupplyFinancials = UserCanAccessFinancialViewOfType(Sbm.FinancialType.CommoditySupply);
Financial.CanUpdateCommoditySupplyFinancials = UserCanAccessFinancialUpdateOfType(Sbm.FinancialType.CommoditySupply);
Financial.CanViewCommoditySalesFinancials = UserCanAccessFinancialViewOfType(Sbm.FinancialType.CommoditySales);
Financial.CanUpdateCommoditySalesFinancials = UserCanAccessFinancialUpdateOfType(Sbm.FinancialType.CommoditySales);
// Config options.
Financial.ConfigOption_AllowFinancialsAccessControl = (configConsole != null && !configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowFinancialsAccessControl));
}
public FinancialProfile Financial { get; }
public bool UserCanViewFinancials(Sbm.FinancialType financialType = Sbm.FinancialType.Any)
{
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(UserContext.SessionContext);
if (configConsole != null && !configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowFinancialsAccessControl)) return true;
if (Financial.ConfigOption_AllowFinancialsAccessControl) return true;
if (IsSecurityRightGranted(Sbm.SecurityRight.Financial_Update) || IsSecurityRightGranted(Sbm.SecurityRight.Financial_View))
{
// If specific type of financial is requested, check that view is not denied.
@@ -223,8 +206,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
public bool UserCanUpdateFinancials(Sbm.FinancialType financialType = Sbm.FinancialType.Any)
{
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(UserContext.SessionContext);
if (configConsole != null && !configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowFinancialsAccessControl)) return true;
if (Financial.ConfigOption_AllowFinancialsAccessControl) return true;
if (IsSecurityRightGranted(Sbm.SecurityRight.Financial_Update))
{
// If specific type of financial is requested, check that update is not denied.
@@ -264,13 +246,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
}
public bool CanCreate { get; internal set; } = false;
public bool CanUpdate { get; internal set; } = false;
internal void Clear()
{
CanCreate = false;
CanUpdate = false;
}
}
public ContactsProfile Contacts { get; }
public ContactsProfile Contacts { get; internal set; }
private void RefreshContactsProfile(SbmConfigConsole configConsole)
{
Contacts.CanUpdate = (UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Update));
Contacts.CanCreate = (Contacts.CanUpdate || UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Create));
}
//-------------------------------------------------------------------
// Security rights - Transactions.
@@ -308,13 +290,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
}
return true;
}
internal void Clear()
{
CanCreate = false;
CanUpdate = false;
}
}
public TransactionsProfile Transaction { get; }
public TransactionsProfile Transaction { get; internal set; }
private void RefreshTransactionProfile(SbmConfigConsole configConsole)
{
Transaction.CanUpdate = (UserHasSecurityRight(Sbm.SecurityRight.Transaction_Update));
Transaction.CanCreate = (Transaction.CanUpdate || UserHasSecurityRight(Sbm.SecurityRight.Transaction_View));
}
public bool UserCanAccessTransactionsOfType(Sbm.TransactionType transactionType)
{
if ((int)transactionType < 1) return false;
@@ -329,22 +312,44 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
public class ItemTypesProfile
{
internal ItemTypesProfile() { }
public bool CanCreate { get; internal set; } = false;
public bool CanUpdate { get; internal set; } = false;
public bool CanRemove { get; internal set; } = false;
internal void Clear()
{
CanCreate = false;
CanUpdate = false;
CanRemove = false;
}
public bool CanCreate { get; internal set; }
public bool CanUpdate { get; internal set; }
public bool CanRemove { get; internal set; }
// Config options.
public bool ConfigOption_AllowProcesses { get; internal set; }
public bool ConfigOption_AllowContacts { get; internal set; }
public bool ConfigOption_AllowCommodities { get; internal set; }
public bool ConfigOption_AllowPortfolios { get; internal set; }
public bool ConfigOption_AllowPriceSets { get; internal set; }
public bool ConfigOption_CommodityCustomers { get; internal set; }
public bool ConfigOption_CommoditySuppliers { get; internal set; }
public bool ConfigOption_AllowTransactions { get; internal set; }
public bool ConfigOption_AllowAssets { get; internal set; }
public bool ConfigOption_AllowVehicles { get; internal set; }
public bool ConfigOption_AllowStockLocations { get; internal set; }
public bool ConfigOption_AllowStockContainers { get; internal set; }
public bool ConfigOption_AllowStockControl { get; internal set; }
}
public ItemTypesProfile ItemType { get; } = new ItemTypesProfile();
private void RefreshItemTypeProfile(SbmConfigConsole configConsole)
{
ItemType.ConfigOption_AllowProcesses = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowProcesses);
ItemType.ConfigOption_AllowContacts = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowContacts);
ItemType.ConfigOption_AllowCommodities = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowCommodities);
ItemType.ConfigOption_AllowPortfolios = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowPortfolios);
ItemType.ConfigOption_AllowPriceSets = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowPriceSets);
ItemType.ConfigOption_CommodityCustomers = configConsole.AllowOption(UserContext, Sbm.ConfigOption.CommodityCustomers);
ItemType.ConfigOption_CommoditySuppliers = configConsole.AllowOption(UserContext, Sbm.ConfigOption.CommoditySuppliers);
ItemType.ConfigOption_AllowTransactions = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowTransactions);
ItemType.ConfigOption_AllowAssets = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowAssets);
ItemType.ConfigOption_AllowVehicles = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowVehicles);
ItemType.ConfigOption_AllowStockLocations = configConsole.GetStockControlConfig(UserContext).AllowStockLocations();
ItemType.ConfigOption_AllowStockContainers = configConsole.GetStockControlConfig(UserContext).AllowStockContainers();
ItemType.ConfigOption_AllowStockControl = configConsole.GetStockControlConfig(UserContext).AllowStockControl();
}
public bool ItemTypeIsAllowed(Sbm.ItemType itemType)
{
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(UserContext.SessionContext);
if (configConsole == null) return false;
switch (itemType)
{
//case Sbm.ItemType.SecItem:
@@ -353,37 +358,37 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
//case Sbm.ItemType.Language:
//case Sbm.ItemType.TaxCode:
//case Sbm.ItemType.UnitMeasure:
case Sbm.ItemType.Process: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowProcesses);
case Sbm.ItemType.Process: return ItemType.ConfigOption_AllowProcesses;
case Sbm.ItemType.Affiliate:
case Sbm.ItemType.Address: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowContacts);
case Sbm.ItemType.Commodity: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowCommodities);
case Sbm.ItemType.PortfolioItem: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowPortfolios);
case Sbm.ItemType.Location: return configConsole.GetStockControlConfig(UserContext).AllowStockLocations();
case Sbm.ItemType.Address: return ItemType.ConfigOption_AllowContacts;
case Sbm.ItemType.Commodity: return ItemType.ConfigOption_AllowCommodities;
case Sbm.ItemType.PortfolioItem: return ItemType.ConfigOption_AllowPortfolios;
case Sbm.ItemType.Location: return ItemType.ConfigOption_AllowStockLocations;
case Sbm.ItemType.Container:
case Sbm.ItemType.ContainerItem: return configConsole.GetStockControlConfig(UserContext).AllowStockContainers();
case Sbm.ItemType.ContainerItem: return ItemType.ConfigOption_AllowStockContainers;
case Sbm.ItemType.Movement:
case Sbm.ItemType.StockLevel: return configConsole.GetStockControlConfig(UserContext).AllowStockControl();
case Sbm.ItemType.StockLevel: return ItemType.ConfigOption_AllowStockControl;
case Sbm.ItemType.PriceSet:
case Sbm.ItemType.Price: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowPriceSets);
case Sbm.ItemType.CommodityCustomer: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.CommodityCustomers);
case Sbm.ItemType.CommoditySupplier: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.CommoditySuppliers);
case Sbm.ItemType.Price: return ItemType.ConfigOption_AllowPriceSets;
case Sbm.ItemType.CommodityCustomer: return ItemType.ConfigOption_CommodityCustomers;
case Sbm.ItemType.CommoditySupplier: return ItemType.ConfigOption_CommoditySuppliers;
//case Sbm.ItemType.Association:
case Sbm.ItemType.Transaction:
case Sbm.ItemType.Requirement:
case Sbm.ItemType.Constituent: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowTransactions);
case Sbm.ItemType.Constituent: return ItemType.ConfigOption_AllowTransactions;
//case Sbm.ItemType.SystemAccount:
//case Sbm.ItemType.SystemUser:
//case Sbm.ItemType.SystemAccountUser:
case Sbm.ItemType.AssetCategory:
case Sbm.ItemType.AssetCategoryProcess:
case Sbm.ItemType.Asset:
case Sbm.ItemType.AssetProcess: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowAssets);
case Sbm.ItemType.AssetProcess: return ItemType.ConfigOption_AllowAssets;
case Sbm.ItemType.VehicleClass:
case Sbm.ItemType.Vehicle:
case Sbm.ItemType.VehicleEvent:
case Sbm.ItemType.VehicleFeature: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowVehicles);
case Sbm.ItemType.CommodityProcess: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowProcesses);
case Sbm.ItemType.RequirementProcess: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowProcesses);
case Sbm.ItemType.VehicleFeature: return ItemType.ConfigOption_AllowVehicles;
case Sbm.ItemType.CommodityProcess: return ItemType.ConfigOption_AllowProcesses;
case Sbm.ItemType.RequirementProcess: return ItemType.ConfigOption_AllowProcesses;
//case Sbm.ItemType.Interface:
}
return true;
@@ -1,19 +1,21 @@
namespace Sarand.BusinessMgr.Net.Standard.Base.App
using Sarand.Net.Standard.Base.App;
namespace Sarand.BusinessMgr.Net.Standard.Base.App
{
//=======================================================================
public class SbmSessionContext
public class SbmSessionContext : SacsSessionContext
{
//-------------------------------------------------------------------
// Construction.
protected SbmSessionContext(ushort index)
protected SbmSessionContext(ushort index, Sbm.Application application) : base(index)
{
Index = index;
Application = application;
}
//-------------------------------------------------------------------
// Properties.
public ushort Index { get; }
//public Sbm.Instance Instance { get; protected set; }
public Sbm.Application Application { get; private set; }
//-------------------------------------------------------------------
}
@@ -0,0 +1,136 @@
using Newtonsoft.Json;
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
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
{
//-------------------------------------------------------------------
private static long sessionIdxRoot = SacsRandomHelper.GetInt32(1000, 1999);
//-------------------------------------------------------------------
// Construction.
/// <summary>Protected constructor for deserialisation only.</summary>
protected SbmSessionData(long sessionIdx, int itemIdx, SbmSessionContext sessionContext)
{
SessionIdx = sessionIdx;
ItemIdx = itemIdx;
SessionContext = sessionContext;
userData = CreateUserData(SessionContext, null, null);
}
/// <summary>
/// Primary constructor - on user login.
/// <para>SessionContext and UserAccount must be supplied.</para>
/// <para>Roles list is optional.</para>
/// </summary>
protected SbmSessionData(SbmSessionContext sessionContext, SaSecurityItem securityItemUser, SbmAffiliate affiliateUser)
{
SessionIdx = ++sessionIdxRoot;
ItemIdx = 1000;
SessionContext = sessionContext;
userData = CreateUserData(SessionContext, securityItemUser, affiliateUser);
}
//-------------------------------------------------------------------
// 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; }
[JsonIgnore]
public bool ValidUserSession { get { return SysId.IsValid(User.AffiliateId) && SysId.IsValid(User.AffiliateId); } }
[JsonIgnore]
public DbUpdateInfo DbUpdateInfo
{
get
{
return new DbUpdateInfo(User.AffiliateId, StringUtil.OnEmpty(User.DisplayName, User.EmailAddress), SbmSystem.ComputerName);
}
}
//-------------------------------------------------------------------
// User.
public class UserData
{
protected UserData() { }
protected UserData(SbmSessionContext sessionContext, SaSecurityItem securityItemUser, SbmAffiliate affiliateUser)
{
if (securityItemUser != null)
{
SecurityItemId = securityItemUser.Id;
}
if (affiliateUser != null)
{
AffiliateId = affiliateUser.Id;
Refresh(securityItemUser, affiliateUser);
if (sessionContext.Application == Sbm.Application.WebControl)
KeepLoggedIn = affiliateUser.KeepLoggedIn_Control;
else if (sessionContext.Application == Sbm.Application.WebPortal)
KeepLoggedIn = affiliateUser.KeepLoggedIn_Portal;
else Debugger.Break();
}
}
protected UserData(UserData userData)
{
SecurityItemId = userData.SecurityItemId;
AffiliateId = userData.AffiliateId;
Title = userData.Title;
FirstName = userData.FirstName;
LastName = userData.LastName;
DisplayName = userData.DisplayName;
EmailAddress = userData.EmailAddress;
KeepLoggedIn = userData.KeepLoggedIn;
}
// Properties.
public SysId SecurityItemId { get; protected set; }
public SysId AffiliateId { get; protected set; }
public String Title { get; protected set; }
public String FirstName { get; protected set; }
public String LastName { get; protected set; }
public String DisplayName { get; protected set; }
public String EmailAddress { get; protected set; }
public bool KeepLoggedIn { get; protected set; }
public bool UserAccountSupplied { get; protected set; }
// Refresh properties.
protected bool Refresh(SaSecurityItem securityItemUser, SbmAffiliate affiliateUser)
{
// Check that user matches the session.
if (!SysId.IsValid(SecurityItemId) || !SysId.IsValid(securityItemUser?.Id ?? null) || !SecurityItemId.Equals(securityItemUser.Id)) return false;
if (!SysId.IsValid(AffiliateId) || !SysId.IsValid(affiliateUser?.Id ?? null) || !AffiliateId.Equals(affiliateUser.Id)) return false;
// Refresh properties.
EmailAddress = securityItemUser.EmailAddress;
Title = affiliateUser.Title;
FirstName = affiliateUser.FirstName;
LastName = affiliateUser.LastName;
DisplayName = affiliateUser.GetDisplayName();
return true;
}
}
protected abstract UserData CreateUserData(SbmSessionContext sessionContext, SaSecurityItem securityItemUser, SbmAffiliate affiliateUser);
private UserData userData;
public UserData User { get { return userData; } }
/// <summary>User - JSON deserialisation route.</summary>
protected void SetUser(UserData user)
{
if (this.userData != null && User.UserAccountSupplied)
throw new NotSupportedException("Session User cannot be replaced.");
this.userData = user;
}
//-------------------------------------------------------------------
}
//=======================================================================
}
@@ -5,6 +5,7 @@ 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 System.Collections.Generic;
namespace Sarand.BusinessMgr.Net.Standard.Base.App
@@ -96,7 +97,11 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
userContext.RefreshUser(affiliateUser, userSupervisedOwners);
// Populate security rights.
SecurityProfile.RefreshProfile(SbmGlobals.Application.GetSecurityConsole(UserContext), userId, securityRights);
using (SbmConfigConsole configConsole = SbmGlobals.Application.CreateConfigConsole(UserContext.SessionContext))
using (SaSecurityConsole securityConsole = SbmGlobals.Application.CreateSecurityConsole(UserContext))
{
SecurityProfile.RefreshProfile(configConsole, securityConsole, userId, securityRights);
}
// Reinstate previous owner if defined and verify that it is in the supervised list.
SysId affiliateIdOwner = UserContext.Organisation.AffiliateId;
@@ -23,10 +23,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
//-------------------------------------------------------------------
// R e g i s t e r C o d e T y p e s
//-------------------------------------------------------------------
public static void RegisterCodeTypes(SaCodeTypeConsole codeTypeConsole, SbmUserContext userContext)
public static void RegisterCodeTypes(SbmConfigConsole configConsole, SaCodeTypeConsole codeTypeConsole, SbmUserContext userContext)
{
SbmConfigConsole configConsole = SbmGlobals.Application.GetConfigConsole(userContext.SessionContext);
//---------------------------------------------------------------
// C o m m o d i t i e s
//---------------------------------------------------------------
+1 -1
View File
@@ -83,7 +83,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
}
public static List<TypeCodeDesc> GetCodesOfType(SbmUserContext userContext, Sbm.SystemCode systemCode)
{
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(userContext.SessionContext);
SbmConfigConsole configConsole = null; // SbmGlobals.GetConfigConsole(userContext.SessionContext);
switch (systemCode)
{
case Sbm.SystemCode.ItemType:
@@ -111,7 +111,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
//-------------------------------------------------------------------
// Construction.
public SbmUserContext(SbmSessionContext sessionContext)
protected SbmUserContext(SbmSessionContext sessionContext)
{
SessionContext = sessionContext;
organisationData = new OrganisationData_Internal();
@@ -307,14 +307,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
ItemId associationItemId_Owner = new ItemId((short)Sbm.ItemType.Association, organisationData.AssociationId);
if (!organisationData.configOptionsCache.ItemIdRef.Id.Equals(affiliateItemId_Owner))
{
SaItemOptionConsole itemOptionConsole = SbmGlobals.Application.GetItemOptionConsole(this);
organisationData.configOptionsCache.Clear();
if (itemOptionConsole != null)
using (SaItemOptionConsole itemOptionConsole = SbmGlobals.Application.CreateItemOptionConsole(this))
{
// Retrieve the options for this association.
organisationData.configOptionsCache.Reset(associationItemId_Owner, affiliateItemId_Owner);
organisationData.configOptionsCache.ItemOptions.AddRange(itemOptionConsole.GetItemOptionsForItem(associationItemId_Owner));
SaLogger.Debug(fn + " Populated organisation options: " + organisationData.configOptionsCache.ItemOptions.Count);
organisationData.configOptionsCache.Clear();
if (itemOptionConsole != null)
{
// Retrieve the options for this association.
organisationData.configOptionsCache.Reset(associationItemId_Owner, affiliateItemId_Owner);
organisationData.configOptionsCache.ItemOptions.AddRange(itemOptionConsole.GetItemOptionsForItem(associationItemId_Owner));
SaLogger.Debug(fn + " Populated organisation options: " + organisationData.configOptionsCache.ItemOptions.Count);
}
}
}
}