Files
BeWoPlaner/BeWo/ViewModel/UserGroupVM.cs
Rene Evertz 5594fa4815 Merge branch 'master' of ssh://float.ownsoft.de/git/beyondSoft/BeWo into feature_rene_13_dakota
# Conflicts:
#	BeWo/BeWoApp.xaml.cs
#	BeWo/View/Detail/OrganisationView.xaml
#	BeWo/View/Master/FinanceView.xaml
#	BeWo/View/Master/FinanceView.xaml.cs
#	BeWo/ViewModel/UserGroupVM.cs
#	Service/ServiceImplementations/AccountingServiceImp.cs
#	Shared/Shared.csproj
2024-10-31 10:12:06 +01:00

309 lines
13 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BeWo.Validation;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
namespace BeWo.ViewModel
{
public class UserGroupVM : AbstractDCMapperVM<UserGroupDC>
{
public static string PropertyName_Description = "Description";
public static string PropertyName_Name = "Name";
public static string PropertyName_PossibleRights = "PossibleRights";
public static string PropertyName_Rights = "Rights";
private string _Description;
private string _Name;
private ObservableSortCollection<UserRightType> _Rights;
public UserGroupVM(UserGroupDC pDataContract) : base(pDataContract, pDataContract.UserGroupOid == null) { }
public string Description
{
get { return _Description; }
set
{
if (AreDifferent(_Description, value))
{
_Description = value;
StoreDirtyInformation(AreDifferent(DataContract.Description, value), PropertyName_Description);
FirePropertyChanged(PropertyName_Description);
}
}
}
[Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
public string Name
{
get { return _Name; }
set
{
if (AreDifferent(_Name, value))
{
_Name = value;
StoreDirtyInformation(AreDifferent(DataContract.Name, value), PropertyName_Name);
FirePropertyChanged(PropertyName_Name);
}
}
}
public ObservableSortCollection<UserRightType> Rights
{
get { return _Rights; }
set
{
if (AreDifferent(_Rights, value))
{
_Rights = value;
_Rights.CollectionChanged += (s, e) => RightsChanged();
RightsChanged();
}
}
}
private void RightsChanged()
{
StoreDirtyInformation(!_Rights.ContainsSameItemsAs(DataContract.Rights), PropertyName_Rights);
FirePropertyChanged(PropertyName_Rights);
FirePropertyChanged(PropertyName_PossibleRights);
}
private Dictionary<Func<UserRightType, bool>, bool> IsTypeFunc2PermissionMapping { get; } = new Dictionary<Func<UserRightType, bool>, bool>()
{
{(r) => r == UserRightType.AdditionalService_View, BeWoApp.Mandator.BeWoClientType == 3 || BeWoApp.AppSettings.ShowAdditionalService},
{IsKalenderRight, BeWoApp.AppSettings.IsSchedulerAllowed },
{IsWohnheimRight, BeWoApp.AppSettings.IsWohnheimAllowed },
{IsSbdRight, BeWoApp.Mandator.AllowSbd},
{IsResourceRight, BeWoApp.AppSettings.ShowRessources},
{IsChatRight, BeWoApp.AppSettings.ShowOwnChat},
{IsChatSettingsRight, BeWoApp.AppSettings.ShowOwnChatSettings},
{IsHiddenRight, false},
{IsMedicationRight, BeWoApp.AppSettings.IsMedicationAllowed},
{IsPivotGridRight, BeWoApp.AppSettings.ShowPivotGrid},
{IsDienstplanungRight, BeWoApp.AppSettings.ShowDienstplanung},
{IsAbwesenheitsPlanungRight, BeWoApp.AppSettings.ShowUrlaubsplanung},
{IsWohnhilfeRight, BeWoApp.AppSettings.ShowWohnhilfe},
{IsGkvAbrechnungRight, BeWoApp.AppSettings.AllowGkvAbrechnung},
{IsUnterschriftRight, false},
{(r) => r == UserRightType.SupportConcept_ImportData, BeWoApp.AppSettings.ShowPersehImport},
{(r) => r == UserRightType.AiChatInZeiterfassung, BeWoApp.AppSettings.ShowAI},
{IsDakotaRight, BeWoApp.AppSettings.AllowGkvAbrechnung},
};
public List<UserRightType> PossibleRights
{
get
{
List<UserRightType> possibleRights = new List<UserRightType>();
//List<UserRightType> nopossibleRights = new List<UserRightType>();
foreach (var right in Utils.GetAllEnumValues<UserRightType>().Except(this._Rights).ToList())
{
if (IsObsoleteRight(right))
continue;
bool valid = true;
foreach (var item in IsTypeFunc2PermissionMapping)
{
var isTypeFunc = item.Key;
var isType = isTypeFunc(right);
var hasPermission = item.Value;
// valid wird nur false, wenn "r" vom Typ "t" ist und für "t" keine Berechtigung vorliegt
valid &= isType.Implies(hasPermission);
}
#if DEBUG
valid = true;
#endif
if(valid)
possibleRights.Add(right);
//else
//{
// nopossibleRights.Add(right);
//}
}
return possibleRights;
}
}
private static bool IsObsoleteRight(UserRightType userRightType)
{
if (userRightType == UserRightType.QueryView_Create
|| userRightType == UserRightType.QueryView_Delete
|| userRightType == UserRightType.QueryView_Edit
|| userRightType == UserRightType.SupportConcept_AllowGoalOrientedSupportConcepts)
{
return true;
}
return false;
}
private static bool IsPivotGridRight(UserRightType userRightType)
{
if (userRightType == UserRightType.PivotTabelleAnsehen)
return true;
return false;
}
private static bool IsDienstplanungRight(UserRightType userRightType)
{
if (userRightType == UserRightType.DienstplanungAnsehen
|| userRightType == UserRightType.DienstplanungBearbeiten)
return true;
return false;
}
private static bool IsAbwesenheitsPlanungRight(UserRightType userRightType)
{
if (userRightType == UserRightType.AbwesenheitsPlanungAnsehen)
return true;
return false;
}
private static bool IsMedicationRight(UserRightType userRightType)
{
if (userRightType == UserRightType.Customer_ViewMedication || userRightType == UserRightType.Customer_EditMedication)
return true;
return false;
}
private static bool IsChatRight(UserRightType userRightType)
{
if (userRightType == UserRightType.ChatSettings)
return true;
return false;
}
private static bool IsChatSettingsRight(UserRightType userRightType)
{
if (userRightType == UserRightType.ChatAdminSettings)
return true;
return false;
}
private static bool IsWohnheimRight(UserRightType userRightType)
{
if (userRightType == UserRightType.WohnheimView_Create
|| userRightType == UserRightType.WohnheimView_Delete
|| userRightType == UserRightType.WohnheimView_Edit
|| userRightType == UserRightType.WohnheimView_View
|| userRightType == UserRightType.Wohnheim_AllowArchiving)
return true;
return false;
}
private static bool IsHiddenRight(UserRightType userRightType)
{
if (userRightType == UserRightType.CustomerTeam_View
|| userRightType == UserRightType.CustomerTeam_Create
|| userRightType == UserRightType.CustomerTeam_Edit
|| userRightType == UserRightType.CustomerTeam_Delete)
return true;
return false;
}
private static bool IsSbdRight(UserRightType userRightType)
{
if (userRightType == UserRightType.VertretungenView_View)
return true;
return false;
}
private static bool IsResourceRight(UserRightType userRightType)
{
if (userRightType == UserRightType.
ResourceBookingView_AllowEditResourcesFromOtherEmployees
|| userRightType == UserRightType.ResourceBookingView_Create
|| userRightType == UserRightType.ResourceBookingView_View
|| userRightType == UserRightType.ResourceBookingView_Delete
|| userRightType == UserRightType.ResourceBookingView_Edit)
return true;
return false;
}
private static bool IsKalenderRight(UserRightType userRightType)
{
if (userRightType == UserRightType.KalenderAnsehen
|| userRightType == UserRightType.KalenderKliententermineAendern
|| userRightType == UserRightType.KalenderKliententermineAlleAnsehen
|| userRightType == UserRightType.KalenderKliententermineAnlegen
|| userRightType == UserRightType.KalenderMitarbeitertermineAendern
|| userRightType == UserRightType.KalenderMitarbeitertermineAnlegen
|| userRightType == UserRightType.KalenderMitarbeitertermineAnsehen
|| userRightType == UserRightType.KalenderRessourcentermineAendern
|| userRightType == UserRightType.KalenderRessourcentermineAndererAendern
|| userRightType == UserRightType.KalenderRessourcentermineAnlegen
|| userRightType == UserRightType.KalenderRessourcentermineAnsehen
|| userRightType == UserRightType.KalenderInZeiterfassungUebernehmen)
{
return true;
}
return false;
}
private static bool IsWohnhilfeRight(UserRightType userRightType)
{
if (userRightType == UserRightType.WohnheimView_Wohneinheit_Belegung_View
|| userRightType == UserRightType.WohnheimView_Wohneinheit_Belegung_Manage
|| userRightType == UserRightType.WohnheimView_Wohneinheit_View
|| userRightType == UserRightType.WohnheimView_Wohneinheit_Manage
|| userRightType == UserRightType.WohnheimView_Wohneinheit_Gallery_View
|| userRightType == UserRightType.WohnheimView_Wohneinheit_Gallery_Manage
|| userRightType == UserRightType.Customer_GemeinnutzigeArbeit_View
|| userRightType == UserRightType.Customer_GemeinnutzigeArbeit_Manage
|| userRightType == UserRightType.Customer_Wohnhilfe_View
|| userRightType == UserRightType.Customer_Wohnhilfe_Manage)
return true;
return false;
}
private static bool IsGkvAbrechnungRight(UserRightType userRightType)
{
if (userRightType == UserRightType.Finance_Gkv_View
|| userRightType == UserRightType.Finance_Gkv_Create
|| userRightType == UserRightType.Finance_Gkv_Send
|| userRightType == UserRightType.Finance_Gkv_Delete)
return true;
return false;
}
private static bool IsUnterschriftRight(UserRightType userRightType)
{
if (userRightType == UserRightType.ServiceRecord_AllowCreateAfterEmployeeSignature
|| userRightType == UserRightType.ServiceRecord_AllowEditAfterEmployeeSignature
|| userRightType == UserRightType.ServiceRecord_AllowDeleteAfterEmployeeSignature)
return true;
return false;
}
private static bool IsDakotaRight(UserRightType right)
=> right == UserRightType.Finance_Gkv_Create ||
right == UserRightType.Finance_Gkv_Delete ||
right == UserRightType.Finance_Gkv_Send ||
right == UserRightType.Finance_Gkv_View;
protected override void InitByDataContract(UserGroupDC pDataContract)
{
_Name = pDataContract.Name;
_Description = pDataContract.Description;
Rights = pDataContract.Rights != null ? pDataContract.Rights.Where(r => !IsObsoleteRight(r)).ToObservableSortCollection() : new ObservableSortCollection<UserRightType>();
}
protected override UserGroupDC MapToDataContract(UserGroupDC pDataContract, bool doCommit)
{
pDataContract.Rights = _Rights.ToList();
pDataContract.Name = _Name;
pDataContract.Description = _Description;
return pDataContract;
}
}
}