diff --git a/Data/Security/UserRightHelper.cs b/Data/Security/UserRightHelper.cs index b26f37e0d..b0d618631 100644 --- a/Data/Security/UserRightHelper.cs +++ b/Data/Security/UserRightHelper.cs @@ -10,203 +10,208 @@ using System.Threading.Tasks; namespace BeWo.Data.Security { - public class UserRightHelper - { - public static readonly string BASE_VERSION = "1.0"; + public class UserRightHelper + { + public static readonly string BASE_VERSION = "1.0"; - public static ApplicationUser GetLoggedInUserWithOid() - { - if(GetLoggedInUser() is ApplicationUser user && user.Oid is long) - return user; + public static ApplicationUser GetLoggedInUserWithOid() + { + if (GetLoggedInUser() is ApplicationUser user && user.Oid is long) + return user; - throw new InvalidOperationException("RequireLoggedInUserOid"); - } + throw new InvalidOperationException("RequireLoggedInUserOid"); + } public static ApplicationUser GetLoggedInUser() - { - return LoggedInUserOperationContextExt.Current?.User ?? SessionFacade.LoggedInUser; + { + return LoggedInUserOperationContextExt.Current?.User ?? SessionFacade.LoggedInUser; - //if (LoggedInUserOperationContextExt.Current != null && - // LoggedInUserOperationContextExt.Current.User != null) - //{ - // return LoggedInUserOperationContextExt.Current.User; - //} - //else - //{ - // return SessionFacade.LoggedInUser; - //} + //if (LoggedInUserOperationContextExt.Current != null && + // LoggedInUserOperationContextExt.Current.User != null) + //{ + // return LoggedInUserOperationContextExt.Current.User; + //} + //else + //{ + // return SessionFacade.LoggedInUser; + //} - //return null; - } + //return null; + } - public static bool LoggedInUserHasRight(UserRightType right) - { - return GetGrantedRights(GetLoggedInUser()).Contains(right); + 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 bool UserHasRight(ApplicationUser user, UserRightType right) + { + return GetGrantedRights(user).Contains(right); - } + } - public static List GetGrantedRights(ApplicationUser user) - { - var rights = new List(); - foreach (var ug in user.UserGroups) - { - foreach (var rr in ug.Rights) - { - rights.Add(rr.RightType); - } - } + public static List GetGrantedRights(ApplicationUser user) + { + var rights = new List(); + foreach (var ug in user.UserGroups) + { + foreach (var rr in ug.Rights) + { + rights.Add(rr.RightType); + } + } - return rights; - } + return rights; + } - public static String GetBeWoVersion() - { - return GetBeWoVersion(GetLoggedInUser().LoginName); - } + 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"; + 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 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(); + 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 ""; - } + return version; + } + } + } + } + return ""; + } - public static void CheckRightVersion(UserDC user) - { - var version = GetBeWoVersion(GetLoggedInUser().LoginName); - CheckRightVersion(version, user); - } + public static void CheckRightVersion(UserDC user) + { + var version = GetBeWoVersion(GetLoggedInUser().LoginName); + CheckRightVersion(version, user); + } - public static void CheckRightVersion(UserGroupDC groupDC) - { - var version = GetBeWoVersion(GetLoggedInUser().LoginName); - CheckRightVersion(version, groupDC); - } + 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, 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(); - foreach (var r in allrights) - { - if (IsCorrectVersion(r, version)) - { - ug.Rights.Add(r); - } - } - } + public static void CheckRightVersion(String version, UserGroupDC ug) + { + var allrights = ug.Rights; + ug.Rights = new List(); + 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); + public static bool IsCorrectVersion(UserRightType r, string version) + { + var rightVersion = GetRightVersion(r); - if (!String.IsNullOrEmpty(version) && version.CompareTo(rightVersion) < 0) - { - return false; - } - return true; - } + 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"; - } + 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"; + } - var rights_3_22 = new List { - UserRightType.DienstplanungBearbeiten, - UserRightType.WohnheimView_Wohneinheit_Belegung_View, - UserRightType.WohnheimView_Wohneinheit_Belegung_Manage, - UserRightType.WohnheimView_Wohneinheit_View, - UserRightType.WohnheimView_Wohneinheit_Manage, - UserRightType.WohnheimView_Wohneinheit_Gallery_View, - UserRightType.WohnheimView_Wohneinheit_Gallery_Manage, - UserRightType.Customer_GemeinnutzigeArbeit_View, - UserRightType.Customer_GemeinnutzigeArbeit_Manage, - UserRightType.Customer_Wohnhilfe_View, - UserRightType.Customer_Wohnhilfe_Manage, - UserRightType.Finance_Gkv_View, - UserRightType.Finance_Gkv_Create, - UserRightType.Finance_Gkv_Send, - UserRightType.Finance_Gkv_Delete - }; + if (isRightVersion322(r)) + return "3.22"; - if (rights_3_22.Contains(r)) - { - return "3.22"; - } + if (isRightVersion324(r)) + return "3.24"; - if (isRightVersion324(r)) - { - return "3.24"; - } + if (isRightVersion326(r)) + return "3.26"; - return BASE_VERSION; - } + 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.AiModuleView2 - || r == UserRightType.AiModuleChatAdd - || r == UserRightType.AiModuleChatDelete - || r == UserRightType.AiModuleChatEdit - || r == UserRightType.AiModuleChatClone - || r == UserRightType.AiModuleViewSetting; + return r == UserRightType.AiModuleView + || r == UserRightType.AiModuleView2 + || r == UserRightType.AiModuleChatAdd + || r == UserRightType.AiModuleChatDelete + || r == UserRightType.AiModuleChatEdit; + } + + private static bool isRightVersion326(UserRightType r) + { + return r == UserRightType.AiModuleChatClone + || r == UserRightType.AiModuleViewSetting; } } }