Files
BeWoPlaner/Data/Security/UserRightHelper.cs
Rene Evertz c5ba4bd0ad Kleines Mergechen
Merge branch 'feature_rene_18_ai'

# Conflicts:
#	BeWo/BeWo.csproj
#	BeWo/BeWoApp.xaml.cs
#	BeWo/ServiceProxy/GeneratedCustomerService.cs
#	BeWo/ServiceProxy/GeneratedEmployeeService.cs
#	BeWo/ServiceProxy/GeneratedOperationsService.cs
#	BeWo/View/Detail/Accounting/GkvAbrechnungOverview.xaml.cs
#	BeWo/View/Detail/EmployeeView.xaml
#	BeWo/app.config
#	BeWoAllReports.sln
#	BeWoPlanerMobil.sln
#	Data/Access/SearchDAO.cs
#	Data/Data.csproj
#	Data/Security/UserRightHelper.cs
#	Server/Components/AICore/Prompt/SystemPrompts/Examples/TranscriptionService.cs
#	Service/DCEntityMapper/GkvAbrechnungDC_GkvAbrechnung.cs
#	Service/ServiceImplementations/EmployeeServiceImp.cs
#	Shared/BeWoEntityEnums.cs
#	Shared/Core/EnumTranslations.cs
#	Shared/Core/GkvValidator.cs
#	Shared/Core/ValidatorExtended.cs
#	Shared/Shared.csproj
2026-02-20 16:36:41 +01:00

257 lines
6.7 KiB
C#

using BeWo.Data.Access;
using BeWo.Data.Entities;
using BS.Shared;
using BS.Shared.DataContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeWo.Data.Security
{
public class UserRightHelper
{
public static readonly string BASE_VERSION = "1.0";
public static string GetTenant()
{
return MultitenancyOperationContextExt.Current?.Tenant;
}
public static Employee GetLoggedInEmployee()
{
if (LoggedInUserOperationContextExt.Current != null)
{
var lLoggedInEmployee = LoggedInUserOperationContextExt.Current.User.Employee;
return lLoggedInEmployee;
}
return null;
}
public static ApplicationUser GetLoggedInUserWithOid()
{
if (GetLoggedInUser() is ApplicationUser user && user.Oid is long)
return user;
throw new InvalidOperationException("RequireLoggedInUserOid");
}
public static ApplicationUser GetLoggedInUser()
{
return LoggedInUserOperationContextExt.Current?.User ?? SessionFacade.LoggedInUser;
//if (LoggedInUserOperationContextExt.Current != null &&
// LoggedInUserOperationContextExt.Current.User != null)
//{
// return LoggedInUserOperationContextExt.Current.User;
//}
//else
//{
// return SessionFacade.LoggedInUser;
//}
//return null;
}
public static bool LoggedInUserHasRight(UserRightType right)
{
return GetGrantedRights(GetLoggedInUser()).Contains(right);
}
public static bool UserHasRight(ApplicationUser user, UserRightType right)
{
return GetGrantedRights(user).Contains(right);
}
public static List<UserRightType> GetGrantedRights(ApplicationUser user)
{
var rights = new List<UserRightType>();
foreach (var ug in user.UserGroups)
{
foreach (var rr in ug.Rights)
{
rights.Add(rr.RightType);
}
}
return rights;
}
public static String GetBeWoVersion()
{
return GetBeWoVersion(GetLoggedInUser().LoginName);
}
public static String GetBeWoVersion(String loginName)
{
var lastLogins = DAOFactory.SearchDAO.FindLastLogins(loginName, 1).ToList();
if (lastLogins != null && lastLogins.Count > 0)
{
var login = lastLogins[0];
if (!String.IsNullOrEmpty(login.Referrer))
{
//var test = "MobilClient, Version: Unbekannt";
//var test2 = "BeWoClient, Version: Microsoft Windows NT 6.2.9200.0;CLRVersion=4.0.30319.42000;BeWoVersion=Version 3.16;IsNet45OrNewer=True";
var str = login.Referrer;
var start = str.IndexOf("BeWoVersion=");
if (start > 0)
{
var stop = str.IndexOf(";", start);
if (stop > start)
{
var version = str.Substring(start + 12, stop - start - 12);
version = version.Replace("Version", "").Trim();
return version;
}
}
}
}
return "";
}
public static void CheckRightVersion(UserDC user)
{
var liu = GetLoggedInUser();
if (liu != null)
{
var version = GetBeWoVersion(liu.LoginName);
CheckRightVersion(version, user);
}
}
public static void CheckRightVersion(UserGroupDC groupDC)
{
var version = GetBeWoVersion(GetLoggedInUser().LoginName);
CheckRightVersion(version, groupDC);
}
public static void CheckRightVersion(String version, UserDC userDC)
{
foreach (var ug in userDC.UserGroups)
{
CheckRightVersion(version, ug);
}
}
public static void CheckRightVersion(String version, UserGroupDC ug)
{
var allrights = ug.Rights;
ug.Rights = new List<UserRightType>();
foreach (var r in allrights)
{
if (IsCorrectVersion(r, version))
{
ug.Rights.Add(r);
}
}
}
public static bool IsCorrectVersion(UserRightType r, string version)
{
var rightVersion = GetRightVersion(r);
if (!String.IsNullOrEmpty(version) && version.CompareTo(rightVersion) < 0)
{
return false;
}
return true;
}
public static String GetRightVersion(UserRightType r)
{
if (r == UserRightType.Customer_ViewBetreuung || r == UserRightType.Customer_ViewAbsenceTimes)
{
return "3.17";
}
if (r == UserRightType.AdditionalService_Edit)
{
return "3.18";
}
if (r == UserRightType.Customer_EditMedication)
{
return "3.19";
}
if (r == UserRightType.SupportConcept_ImportData || r == UserRightType.AiChatInZeiterfassung || r == UserRightType.FinanzenRechnungenNachVersandBearbeiten)
{
return "3.21";
}
if (isRightVersion322(r))
return "3.22";
if (isRightVersion324(r))
return "3.24";
if (isRightVersion326(r))
return "3.26";
if (isRightVersion329(r))
return "3.29";
if (r == UserRightType.KalenderInAbwesenheitenUebernehmen)
return "3.30";
return BASE_VERSION;
}
private static bool isRightVersion322(UserRightType r)
{
return r == UserRightType.DienstplanungBearbeiten
|| r == UserRightType.WohnheimView_Wohneinheit_Belegung_View
|| r == UserRightType.WohnheimView_Wohneinheit_Belegung_Manage
|| r == UserRightType.WohnheimView_Wohneinheit_View
|| r == UserRightType.WohnheimView_Wohneinheit_Manage
|| r == UserRightType.WohnheimView_Wohneinheit_Gallery_View
|| r == UserRightType.WohnheimView_Wohneinheit_Gallery_Manage
|| r == UserRightType.Customer_GemeinnutzigeArbeit_View
|| r == UserRightType.Customer_GemeinnutzigeArbeit_Manage
|| r == UserRightType.Customer_Wohnhilfe_View
|| r == UserRightType.Customer_Wohnhilfe_Manage
|| r == UserRightType.Finance_Gkv_View
|| r == UserRightType.Finance_Gkv_Create
|| r == UserRightType.Finance_Gkv_Send
|| r == UserRightType.Finance_Gkv_Delete;
}
private static bool isRightVersion324(UserRightType r)
{
return r == UserRightType.AiModuleView
|| r == UserRightType.AiModuleChatAdd
|| r == UserRightType.AiModuleChatDelete
|| r == UserRightType.AiModuleChatEdit;
}
private static bool isRightVersion326(UserRightType r)
{
return r == UserRightType.AiModuleChatClone
|| r == UserRightType.AiModuleViewSetting;
}
private static bool isRightVersion329(UserRightType r)
{
return r == UserRightType.Employee_AllowEditAbsenceTimes
|| r == UserRightType.Employee_AllowEditOvertimes;
}
private static bool isRightVersion328(UserRightType r)
{
return r == UserRightType.AiModulePromptbausteineAdd
|| r == UserRightType.AiModulePromptbausteineEdit
|| r == UserRightType.AiModulePromptbausteineRemove
|| r == UserRightType.AiModulePromptbausteineSeeAll
|| r == UserRightType.AiModulePromptbausteineView;
}
}
}