diff --git a/Data/Data.csproj b/Data/Data.csproj index 134b4cdf0..ee666490f 100644 --- a/Data/Data.csproj +++ b/Data/Data.csproj @@ -370,6 +370,7 @@ + diff --git a/Data/Security/UserRightHelper.cs b/Data/Security/UserRightHelper.cs new file mode 100644 index 000000000..644be3aa0 --- /dev/null +++ b/Data/Security/UserRightHelper.cs @@ -0,0 +1,56 @@ +using BeWo.Data.Entities; +using BS.Shared; +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 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; + } + } +} diff --git a/Service/Plugins/ServiceRecordValidator.cs b/Service/Plugins/ServiceRecordValidator.cs index 2db4a3228..44787f15c 100644 --- a/Service/Plugins/ServiceRecordValidator.cs +++ b/Service/Plugins/ServiceRecordValidator.cs @@ -13,6 +13,7 @@ using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using BS.Shared.Services; using BeWo.Service.Configuration; +using BeWo.Data.Security; namespace BeWo.Service.Plugins { @@ -388,11 +389,22 @@ namespace BeWo.Service.Plugins if (reldc.StartDate.HasValue && reldc.EndDate.HasValue) if (!start.InBetween(reldc.StartDate.Value, reldc.EndDate.Value, true)) { + String handlungsOption = "Das Speichern ist nicht möglich."; + bool hatDasRechtTrotzdemZuSpeichern = false; + + if (UserRightHelper.LoggedInUserHasRight(UserRightType.BookServiceRecordOutOfSupportConcept)) + { + handlungsOption = "Trotzdem Speichern?"; + hatDasRechtTrotzdemZuSpeichern = true; + } + var dc = new ServiceRecordValidationResultDC { - ResultType = ServiceRecordValidationResult.OutsideOfSupportConcept, + ResultType = ServiceRecordValidationResult.Custom, + Message = $"Das gewählte Datum '{start}' liegt außerhalb des Hilfeplanzeitraums ('{reldc.StartDate.Value.ToShortDateString()}' bis '{reldc.EndDate.Value.ToShortDateString()}').\n" + handlungsOption, StartDate = reldc.StartDate.Value, - EndDate = reldc.EndDate.Value + EndDate = reldc.EndDate.Value, + Allow = hatDasRechtTrotzdemZuSpeichern }; result.Add(dc); } @@ -467,7 +479,7 @@ namespace BeWo.Service.Plugins return result; } - + public virtual ServiceRecordValidationResultDC CheckAbwesenheiten(ServiceRecordDC newServiceRecord, IList allRecords, SupportConceptCostBearerRelDC reldc, decimal rd, bool isGroupRecord) {