271 lines
11 KiB
C#
271 lines
11 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> Type2PermissionMapping { 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},
|
|
{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>();
|
|
|
|
foreach (var r in Utils.GetAllEnumValues<UserRightType>().Except(this._Rights).ToList())
|
|
{
|
|
if (IsObsoleteRight(r))
|
|
continue;
|
|
|
|
bool valid = true;
|
|
|
|
foreach (var item in Type2PermissionMapping)
|
|
{
|
|
var isType = item.Key(r);
|
|
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(r);
|
|
}
|
|
|
|
return possibleRights;
|
|
}
|
|
}
|
|
|
|
private static bool IsObsoleteRight(UserRightType userRightType)
|
|
{
|
|
if (userRightType == UserRightType.QueryView_Create
|
|
|| userRightType == UserRightType.QueryView_Delete
|
|
|| userRightType == UserRightType.QueryView_Edit)
|
|
{
|
|
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)
|
|
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 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;
|
|
}
|
|
}
|
|
} |