256 lines
6.8 KiB
C#
256 lines
6.8 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.FinanzenRechnungenNachVersandBearbeiten)
|
|
{
|
|
return "3.21";
|
|
}
|
|
|
|
if (isRightVersion322(r))
|
|
return "3.22";
|
|
if (isRightVersion329(r))
|
|
return "3.29";
|
|
if (isRightVersion330(r))
|
|
return "3.30";
|
|
if (isRightVersion3301(r))
|
|
return "3.30.1";
|
|
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 isRightVersion329(UserRightType r)
|
|
{
|
|
return r == UserRightType.Employee_AllowEditAbsenceTimes
|
|
|| r == UserRightType.Employee_AllowEditOvertimes;
|
|
}
|
|
|
|
private static bool isRightVersion330(UserRightType r)
|
|
{
|
|
return r == UserRightType.KalenderInAbwesenheitenUebernehmen
|
|
|| r == UserRightType.AiModuleChatView
|
|
//|| r == UserRightType.AiModuleChatClone
|
|
//|| r == UserRightType.AiModuleViewSetting
|
|
//|| r == UserRightType.AiModuleChatAdd
|
|
//|| r == UserRightType.AiModuleChatDelete
|
|
//|| r == UserRightType.AiModuleChatEdit
|
|
//|| r == UserRightType.AiModulePromptbausteineAdd
|
|
|| r == UserRightType.AiModulePromptbausteineEdit
|
|
//|| r == UserRightType.AiModulePromptbausteineRemove
|
|
//|| r == UserRightType.AiModulePromptbausteineSeeAll
|
|
|| r == UserRightType.AiModulePromptbausteineView
|
|
//|| r == UserRightType.AiModulePromptbausteineExecute
|
|
|| r == UserRightType.AiVoiceView;
|
|
}
|
|
|
|
private static bool isRightVersion3301(UserRightType r)
|
|
{
|
|
return r == UserRightType.AiModulePromptbausteinShare ||
|
|
r == UserRightType.AiModuleServiceRecordChat ||
|
|
r == UserRightType.AiModuleServiceRecordDocu;
|
|
}
|
|
}
|
|
}
|