diff --git a/server/AyaNova/Controllers/AuthController.cs b/server/AyaNova/Controllers/AuthController.cs index 23388056..a84f3e2f 100644 --- a/server/AyaNova/Controllers/AuthController.cs +++ b/server/AyaNova/Controllers/AuthController.cs @@ -351,6 +351,7 @@ namespace AyaNova.Api.Controllers if (u.UserType == UserType.Customer | u.UserType == UserType.HeadOffice) { //customer type has special rights restrictions for UI features so return them here so client UI can enable or disable + var effectiveRights = await UserBiz.CustomerUserEffectiveRights(u.Id); return Ok(ApiOkResponse.Response(new { token = token, @@ -359,7 +360,7 @@ namespace AyaNova.Api.Controllers roles = ((int)u.Roles).ToString(), dlt = DownloadToken, tfa = u.TwoFactorEnabled, - CustomerRights = UserBiz.CustomerUserEffectiveRights(u.Id) + CustomerRights = effectiveRights })); } else diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 0487b22a..712b7616 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -111,8 +111,6 @@ namespace AyaNova.Biz { using (AyContext ct = ServiceProviderProvider.DBContext) { - - var UserInfo = await ct.User.AsNoTracking().Where(x => x.Id == userId).Select(x => new { x.UserType, x.HeadOfficeId, x.CustomerId, x.Tags }).FirstAsync(); if (UserInfo.UserType != UserType.Customer && UserInfo.UserType != UserType.HeadOffice) @@ -121,12 +119,20 @@ namespace AyaNova.Biz List AllTags = new List(); AllTags.AddRange(UserInfo.Tags); + //Contact is for a customer or for a head office not both so... if (UserInfo.CustomerId != null && UserInfo.CustomerId != 0) - AllTags.AddRange(await ct.Customer.AsNoTracking().Where(x => x.Id == UserInfo.CustomerId).Select(x => x.Tags).FirstAsync()); - - if (UserInfo.HeadOfficeId != null && UserInfo.HeadOfficeId != 0) + { + var CustomerInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == UserInfo.CustomerId).Select(x => new { x.HeadOfficeId, x.Tags }).FirstAsync(); + AllTags.AddRange(CustomerInfo.Tags); + //does the customer have a head office?? + if (CustomerInfo.HeadOfficeId != null && CustomerInfo.HeadOfficeId != 0) + AllTags.AddRange(await ct.HeadOffice.AsNoTracking().Where(x => x.Id == CustomerInfo.HeadOfficeId).Select(x => x.Tags).FirstAsync()); + } + else + if (UserInfo.HeadOfficeId != null && UserInfo.HeadOfficeId != 0) AllTags.AddRange(await ct.HeadOffice.AsNoTracking().Where(x => x.Id == UserInfo.HeadOfficeId).Select(x => x.Tags).FirstAsync()); + return new CustomerRightsRecord( CustomerUserEffectiveRightsAllowed(AyaNova.Util.ServerGlobalBizSettings.Cache.CustomerAllowCSR, AllTags,