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 { 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 _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 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, bool> IsTypeFunc2PermissionMapping { get; } = new Dictionary, 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}, {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}, {IsAiModuleRight, BeWoApp.AppSettings.ShowAI}, //{IsAiModuleSettingRight, BeWoApp.AppSettings.ModuleAiSettingsEnabled}, {(r) => r == UserRightType.AiVoiceView, BeWoApp.AppSettings.ShowAIVoice}, }; public List PossibleRights { get { List possibleRights = new List(); //List nopossibleRights = new List(); var load_all = false; #if DEBUG if (DebugConfig.CurrentConfig is DebugConfig config && config.EnableAllUserRightsInDebug) load_all = true; #endif foreach (var right in Utils.GetAllEnumValues().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 if (load_all) valid = true; else #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 || 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 || userRightType == UserRightType.KalenderInAbwesenheitenUebernehmen) { 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 IsAiModuleRight(UserRightType right) => ContainsRight(right, UserRightType.AiModuleServiceRecordChat, UserRightType.AiModuleServiceRecordDocu, UserRightType.AiModulePromptbausteineEdit, UserRightType.AiModulePromptbausteineView, UserRightType.AiModulePromptbausteinShare); //private static bool IsAiModuleSettingRight(UserRightType right) => // ContainsRight(right); private static bool ContainsRight(UserRightType right, params UserRightType[] rightTypes) { return rightTypes.Length != 0 && rightTypes.Any(x => x == right); } 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(); } protected override UserGroupDC MapToDataContract(UserGroupDC pDataContract, bool doCommit) { pDataContract.Rights = _Rights.ToList(); pDataContract.Name = _Name; pDataContract.Description = _Description; return pDataContract; } } }