Files
BusinessMgr-2019/SaBusMgrStandardBase/Base/App/SbmSecurityProfile.cs
T
2021-08-04 21:32:35 +01:00

524 lines
25 KiB
C#

using Newtonsoft.Json;
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
using Sarand.BusinessMgr.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.App;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Core;
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 SbmSecurityProfile : SaErrorStateItem, ISbmSecurityProfile
{
//-------------------------------------------------------------------
// Data members.
private static readonly String userNameUnknown = "Unknown";
private bool includeHostSecurityProfile = false;
private SaSecurityProfile userSecurityProfile;
private SaSecurityProfile hostSecurityProfile;
private readonly List<TypeCodeDesc> securityRights = new List<TypeCodeDesc>();
//-------------------------------------------------------------------
// Construction.
public SbmSecurityProfile(ISbmUserContext userContext, bool includeHostSecurityProfile)
{
this.UserContext = userContext;
this.includeHostSecurityProfile = includeHostSecurityProfile;
Admin = new AdminProfile(this);
Manage = new ManageProfile(this);
Financial = new FinancialProfile(this);
Contacts = new ContactsProfile(this);
Transaction = new TransactionsProfile(this);
}
//-------------------------------------------------------------------
// Properties.
[JsonIgnore]
public ISbmUserContext UserContext { get; }
//-------------------------------------------------------------------
// Refresh profile.
public void RefreshProfile(SbmConfigConsole configConsole, SaSecurityConsole securityConsole, SysId userId, List<TypeCodeDesc> securityRights)
{
String fn = GetType().Name + ".RefreshProfile";
ClearErrorState();
// Make a note of the security right.
this.securityRights.Clear();
this.securityRights.AddRange(securityRights);
SysId previousUserId = UserId;
// Clear existing profile.
UserId = SysId.InvalidOnNull(userId);
// Load new profile.
if (securityConsole != null)
{
userSecurityProfile = securityConsole.GetUserSecurityProfile(UserId);
if (hostSecurityProfile == null && includeHostSecurityProfile)
hostSecurityProfile = securityConsole.GetHostSecurityProfile();
}
SaLogger.Debug(fn + " User: '" + UserDisplayName + "' [Id: " + UserId + "]" + (SysId.IsValid(previousUserId) ? ". Previous UserId: " + SysId.ToString(previousUserId) : ""));
RefreshProfileSettings(configConsole);
}
protected void RefreshProfile(SbmConfigConsole configConsole, SaSecurityProfile userSecurityProfile, SaSecurityProfile hostSecurityProfile)
{
this.userSecurityProfile = userSecurityProfile;
this.hostSecurityProfile = hostSecurityProfile;
RefreshProfileSettings(configConsole);
}
private void RefreshProfileSettings(SbmConfigConsole configConsole)
{
RefreshAdminProfile(configConsole);
RefreshManageProfile(configConsole);
RefreshFinancialProfile(configConsole);
RefreshContactsProfile(configConsole);
RefreshTransactionProfile(configConsole);
RefreshItemTypeProfile(configConsole);
// ToDo Commodities.
}
private void ClearProfile()
{
// Reset security profiles.
Admin = new AdminProfile(this);
Manage = new ManageProfile(this);
Financial = new FinancialProfile(this);
Contacts = new ContactsProfile(this);
Transaction = new TransactionsProfile(this);
}
//-------------------------------------------------------------------
// User.
public SysId UserId { get; protected set; } = new SysId();
public String UserDisplayName { get { return (userSecurityProfile != null ? userSecurityProfile.Description : userNameUnknown); } }
public String UserLocation { get { return (userSecurityProfile != null ? userSecurityProfile.Location : ""); } }
public DateTime UserLastLogin { get { return (userSecurityProfile != null ? userSecurityProfile.LastLogin : DateTime.MinValue); } }
//-------------------------------------------------------------------
// Utilities.
public bool IsUserMemberOfSecurityGroup(SysId secGroupId)
{
if (userSecurityProfile != null)
return userSecurityProfile.IsMemberOfSecurityGroup(secGroupId);
return false;
}
public bool IsSecurityRightGranted(Sbm.SecurityRight securityRight, SysId id = null)
{
if (userSecurityProfile != null)
return userSecurityProfile.IsSecurityRightGranted(securityRights.GetCodeForType(securityRight));
return false;
}
public bool IsSecurityRightDenied(Sbm.SecurityRight securityRight, SysId id = null)
{
if (userSecurityProfile != null)
return userSecurityProfile.IsSecurityRightDenied(securityRights.GetCodeForType(securityRight), id);
return true;
}
//-------------------------------------------------------------------
// Security rights - Admin.
public class AdminProfile
{
private readonly SbmSecurityProfile securityProfile;
internal AdminProfile(SbmSecurityProfile securityProfile)
{
this.securityProfile = securityProfile;
}
public bool CanManageSecurity { get; internal set; } = false;
public bool CanManageDatabase { get; internal set; } = false;
public bool CanManageReferenceData { get; internal set; } = false;
public bool CanManageInterfaces { get; internal set; } = false;
}
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.
public class ManageProfile
{
private readonly SbmSecurityProfile securityProfile;
internal ManageProfile(SbmSecurityProfile securityProfile)
{
this.securityProfile = securityProfile;
}
public bool CanManageTasks { get; internal set; } = false;
public bool CanManageTimesheets { get; internal set; } = false;
}
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.
public class FinancialProfile
{
private readonly SbmSecurityProfile securityProfile;
internal FinancialProfile(SbmSecurityProfile securityProfile)
{
this.securityProfile = securityProfile;
}
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 bool UserCanViewFinancials(Sbm.FinancialType financialType = Sbm.FinancialType.Any)
{
if (!Financial.ConfigOption_AllowFinancialsAccessControl) return true;
if (Financial.CanUpdateFinancials || Financial.CanViewFinancials)
{
// If specific type of financial is requested, check that view is not denied.
if (financialType > 0 && IsSecurityRightDenied(Sbm.SecurityRight.Financial_ViewByType, new SysId((int)financialType)))
return false;
return true;
}
return false;
}
public bool UserCanUpdateFinancials(Sbm.FinancialType financialType = Sbm.FinancialType.Any)
{
if (!Financial.ConfigOption_AllowFinancialsAccessControl) return true;
if (Financial.CanUpdateFinancials)
{
// If specific type of financial is requested, check that update is not denied.
if (financialType > 0 && IsSecurityRightDenied(Sbm.SecurityRight.Financial_UpdateByType, new SysId((int)financialType)))
return false;
return true;
}
return false;
}
public bool UserCanAccessFinancialViewOfType(Sbm.FinancialType financialType)
{
if ((int)financialType < 1) return false;
// If specific type of financial is requested, check that view is not denied.
if (IsSecurityRightDenied(Sbm.SecurityRight.Financial_ViewByType, new SysId((int)financialType)))
return false;
return true;
}
public bool UserCanAccessFinancialUpdateOfType(Sbm.FinancialType financialType)
{
if ((int)financialType < 1) return false;
// If specific type of financial is requested, check that update is not denied.
if (IsSecurityRightDenied(Sbm.SecurityRight.Financial_UpdateByType, new SysId((int)financialType)))
return false;
return true;
}
//-------------------------------------------------------------------
// Security rights - Contacts.
public class ContactsProfile
{
private readonly SbmSecurityProfile securityProfile;
internal ContactsProfile(SbmSecurityProfile securityProfile)
{
this.securityProfile = securityProfile;
}
public bool CanCreate { get; internal set; } = false;
public bool CanUpdate { get; internal set; } = false;
}
public ContactsProfile Contacts { get; internal set; }
public bool UserCanCreateContacts { get { return Contacts.CanCreate; } }
public bool UserCanUpdateContacts { get { return Contacts.CanUpdate; } }
private void RefreshContactsProfile(SbmConfigConsole configConsole)
{
Contacts.CanUpdate = (UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Update));
Contacts.CanCreate = (Contacts.CanUpdate || UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Create));
}
//-------------------------------------------------------------------
// Security rights - Transactions.
public class TransactionsProfile
{
private readonly SbmSecurityProfile securityProfile;
internal TransactionsProfile(SbmSecurityProfile securityProfile)
{
this.securityProfile = securityProfile;
}
public bool CanCreate { get; internal set; } = false;
public bool CanUpdate { get; internal set; } = false;
public bool CanUpdateTransactionTypeStatusCat(Sbm.TransactionType transactionType, SbmTransaction.StatusCat transactionStatusCat)
{
SysId transactionTypeStatusCatId = SbmTransaction.GetTransactionTypeStatusId(transactionType, transactionStatusCat);
// Check if update of this transaction type and status is denied:
if (securityProfile.IsSecurityRightDenied(Sbm.SecurityRight.Transaction_UpdateByTypeStatus, transactionTypeStatusCatId))
return false;
// Check if update of this transaction type and status is explicitly allowed:
if (securityProfile.IsSecurityRightGranted(Sbm.SecurityRight.Transaction_UpdateByTypeStatus, transactionTypeStatusCatId))
return true;
// Check if any other statuses for this type of transaction are allowed.
foreach (TypeCodeDesc statusCat in SbmTransaction.GetTransactionStatusCats(securityProfile.UserContext, transactionType))
{
SbmTransaction.StatusCat transactionStatusCatOther = (SbmTransaction.StatusCat)statusCat.Type;
// Ignore the transaction status category.
if (transactionStatusCatOther == transactionStatusCat) continue;
if (securityProfile.IsSecurityRightGranted(Sbm.SecurityRight.Transaction_UpdateByTypeStatus, SbmTransaction.GetTransactionTypeStatusId(transactionType, transactionStatusCatOther)))
// Explicit granting of right to another status for this transaction right
// implies that other statuses are implicitly denied.
return false;
}
return true;
}
}
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;
// Check if specific type of transaction is denied.
if (IsSecurityRightDenied(Sbm.SecurityRight.Transaction_ByType, new SysId((int)transactionType)))
return false;
return true;
}
//-------------------------------------------------------------------
// Security rights - ItemType.
public class ItemTypesProfile
{
internal ItemTypesProfile() { }
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)
{
switch (itemType)
{
//case Sbm.ItemType.SecItem:
//case Sbm.ItemType.Currency:
//case Sbm.ItemType.Region:
//case Sbm.ItemType.Language:
//case Sbm.ItemType.TaxCode:
//case Sbm.ItemType.UnitMeasure:
case Sbm.ItemType.Process: return ItemType.ConfigOption_AllowProcesses;
case Sbm.ItemType.Affiliate:
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 ItemType.ConfigOption_AllowStockContainers;
case Sbm.ItemType.Movement:
case Sbm.ItemType.StockLevel: return ItemType.ConfigOption_AllowStockControl;
case Sbm.ItemType.PriceSet:
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 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 ItemType.ConfigOption_AllowAssets;
case Sbm.ItemType.VehicleClass:
case Sbm.ItemType.Vehicle:
case Sbm.ItemType.VehicleEvent:
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;
}
public bool UserCanCreateItemType(Sbm.ItemType itemType)
{
if (!ItemTypeIsAllowed(itemType)) return false;
switch (itemType)
{
case Sbm.ItemType.SecItem: return IsSecurityRightGranted(Sbm.SecurityRight.Security_Admin);
case Sbm.ItemType.Currency:
case Sbm.ItemType.Region:
case Sbm.ItemType.Language:
case Sbm.ItemType.TaxCode:
case Sbm.ItemType.UnitMeasure: return IsSecurityRightGranted(Sbm.SecurityRight.ReferenceData_Admin);
case Sbm.ItemType.Process: return IsSecurityRightGranted(Sbm.SecurityRight.ReferenceData_Admin);
case Sbm.ItemType.Affiliate: return IsSecurityRightGranted(Sbm.SecurityRight.Affiliate_Create);
case Sbm.ItemType.Address: return IsSecurityRightGranted(Sbm.SecurityRight.Affiliate_Update);
case Sbm.ItemType.Commodity: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Create);
case Sbm.ItemType.PortfolioItem: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.Location: return IsSecurityRightGranted(Sbm.SecurityRight.ReferenceData_Admin);
case Sbm.ItemType.Container: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Create);
case Sbm.ItemType.ContainerItem: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.Movement: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.StockLevel: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.PriceSet:
case Sbm.ItemType.Price: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update) && UserCanUpdateFinancials();
case Sbm.ItemType.CommodityCustomer:
case Sbm.ItemType.CommoditySupplier: return IsSecurityRightGranted(Sbm.SecurityRight.Association_Update) && IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.Association: return IsSecurityRightGranted(Sbm.SecurityRight.Association_Create);
case Sbm.ItemType.Transaction: return IsSecurityRightGranted(Sbm.SecurityRight.Transaction_Create);
case Sbm.ItemType.Requirement:
case Sbm.ItemType.Constituent: return IsSecurityRightGranted(Sbm.SecurityRight.Transaction_Update);
case Sbm.ItemType.SystemAccount:
case Sbm.ItemType.SystemUser:
case Sbm.ItemType.SystemAccountUser: return IsSecurityRightGranted(Sbm.SecurityRight.Security_Admin);
case Sbm.ItemType.AssetCategory:
case Sbm.ItemType.AssetCategoryProcess:
case Sbm.ItemType.Asset:
case Sbm.ItemType.AssetProcess: return IsSecurityRightGranted(Sbm.SecurityRight.Asset_Create);
case Sbm.ItemType.VehicleClass:
case Sbm.ItemType.Vehicle:
case Sbm.ItemType.VehicleEvent:
case Sbm.ItemType.VehicleFeature: return IsSecurityRightGranted(Sbm.SecurityRight.Asset_Create);
case Sbm.ItemType.CommodityProcess: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.RequirementProcess: return IsSecurityRightGranted(Sbm.SecurityRight.Transaction_Update);
case Sbm.ItemType.Interface: return IsSecurityRightGranted(Sbm.SecurityRight.InterfaceConfig);
}
return false;
}
public bool UserCanUpdateItemType(Sbm.ItemType itemType)
{
switch (itemType)
{
case Sbm.ItemType.SecItem: return IsSecurityRightGranted(Sbm.SecurityRight.Security_Admin);
case Sbm.ItemType.Currency:
case Sbm.ItemType.Region:
case Sbm.ItemType.Language:
case Sbm.ItemType.TaxCode:
case Sbm.ItemType.UnitMeasure: return IsSecurityRightGranted(Sbm.SecurityRight.ReferenceData_Admin);
case Sbm.ItemType.Process: return IsSecurityRightGranted(Sbm.SecurityRight.ReferenceData_Admin);
case Sbm.ItemType.Affiliate:
case Sbm.ItemType.Address: return IsSecurityRightGranted(Sbm.SecurityRight.Affiliate_Update);
case Sbm.ItemType.Commodity: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.PortfolioItem: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.Location: return IsSecurityRightGranted(Sbm.SecurityRight.ReferenceData_Admin);
case Sbm.ItemType.Container:
case Sbm.ItemType.ContainerItem: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.Movement:
case Sbm.ItemType.StockLevel: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.PriceSet:
case Sbm.ItemType.Price: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update) && UserCanUpdateFinancials();
case Sbm.ItemType.CommodityCustomer:
case Sbm.ItemType.CommoditySupplier: return IsSecurityRightGranted(Sbm.SecurityRight.Association_Update) && IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.Association: return IsSecurityRightGranted(Sbm.SecurityRight.Association_Update);
case Sbm.ItemType.Transaction:
case Sbm.ItemType.Requirement:
case Sbm.ItemType.Constituent: return IsSecurityRightGranted(Sbm.SecurityRight.Transaction_Update);
case Sbm.ItemType.SystemAccount:
case Sbm.ItemType.SystemUser:
case Sbm.ItemType.SystemAccountUser: return IsSecurityRightGranted(Sbm.SecurityRight.Security_Admin);
case Sbm.ItemType.AssetCategory:
case Sbm.ItemType.AssetCategoryProcess:
case Sbm.ItemType.Asset:
case Sbm.ItemType.AssetProcess: return IsSecurityRightGranted(Sbm.SecurityRight.Asset_Update);
case Sbm.ItemType.VehicleClass:
case Sbm.ItemType.Vehicle:
case Sbm.ItemType.VehicleEvent:
case Sbm.ItemType.VehicleFeature: return IsSecurityRightGranted(Sbm.SecurityRight.Asset_Update);
case Sbm.ItemType.CommodityProcess: return IsSecurityRightGranted(Sbm.SecurityRight.Commodity_Update);
case Sbm.ItemType.RequirementProcess: return IsSecurityRightGranted(Sbm.SecurityRight.Transaction_Update);
case Sbm.ItemType.Interface: return IsSecurityRightGranted(Sbm.SecurityRight.InterfaceConfig);
}
return false;
}
public bool UserCanRemoveItemType(Sbm.ItemType itemType)
{
switch (itemType)
{
case Sbm.ItemType.Transaction:
if (!IsSecurityRightGranted(Sbm.SecurityRight.Transaction_Remove)) return false;
break;
}
return (UserCanCreateItemType(itemType) && UserCanUpdateItemType(itemType));
}
//-------------------------------------------------------------------
// Security rights.
private bool UserHasSecurityRight(Sbm.SecurityRight securityRight, SysId dataItemId = null)
{
String rightCode = securityRights.GetCodeForType(securityRight);
if (StringUtil.IsEmpty(rightCode)) return false;
// Check if right is denied by either user or host profiles.
if (userSecurityProfile != null && userSecurityProfile.IsSecurityRightDenied(rightCode)) return false;
if (hostSecurityProfile != null && hostSecurityProfile.IsSecurityRightDenied(rightCode)) return false;
// Check if right is granted by either user or host profiles.
if (userSecurityProfile != null && userSecurityProfile.IsSecurityRightGranted(rightCode)) return true;
if (hostSecurityProfile != null && hostSecurityProfile.IsSecurityRightGranted(rightCode)) return true;
return false;
}
//-------------------------------------------------------------------
}
//=======================================================================
}