Files
BeWoPlaner/Data/Security/UserRightHelper.cs
Rene Evertz 1b9efb8f79 Squashed commit of the following:
commit af28476b76
Merge: b76e16946 c3b6a1e9c
Author: Marcel Hirschle <marcel.hirschle@ownsoft.de>
Date:   Thu Jun 20 11:53:31 2024 +0200

    Merge branch 'master' of ssh://float.ownsoft.de/git/beyondSoft/BeWo

    # Conflicts:
    #	ReportImp/VkmHamm/CustomerMitarbeiterstundenkontoBerechnung.cs

commit b76e169462
Author: Marcel Hirschle <marcel.hirschle@ownsoft.de>
Date:   Thu Jun 20 11:40:08 2024 +0200

    MH: vkm hamm stundenkonto

commit c3b6a1e9c0
Author: Christian <christian.baeurle@beyondsoft.de>
Date:   Thu Jun 20 10:58:05 2024 +0200

    Mergemarker entfernt

commit 5ff8fe343b
Merge: c1aa61f05 fc57725f4
Author: Christian <christian.baeurle@beyondsoft.de>
Date:   Thu Jun 20 10:52:16 2024 +0200

    Merge branch 'master' of ssh://float.beyondsoft.de/git/beyondSoft/BeWo

commit c1aa61f058
Merge: 12faccb71 1c0a94c60
Author: Christian <christian.baeurle@beyondsoft.de>
Date:   Thu Jun 20 10:51:59 2024 +0200

    Merge branch 'master' of ssh://float.beyondsoft.de/git/beyondSoft/BeWo

    # Conflicts:
    #	BeWo/ServiceProxy/Generated.cs
    #	Data/Security/UserRightHelper.cs
    #	Shared/BeWoEntityEnums.cs
    #	Shared/Core/EnumTranslations.cs

commit 12faccb71b
Author: Christian <christian.baeurle@beyondsoft.de>
Date:   Wed Jun 19 16:13:56 2024 +0200

    Perseh Hilfeplan Import + KI Prototyp,
2024-06-20 12:16:00 +02:00

162 lines
4.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 ApplicationUser GetLoggedInUser()
{
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 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(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";
}
return "1.0";
}
}
}