diff --git a/Providers/Resgrid.Providers.Bus/NotificationProvider.cs b/Providers/Resgrid.Providers.Bus/NotificationProvider.cs index 434715f2..70f75ea2 100644 --- a/Providers/Resgrid.Providers.Bus/NotificationProvider.cs +++ b/Providers/Resgrid.Providers.Bus/NotificationProvider.cs @@ -9,6 +9,8 @@ using Newtonsoft.Json.Linq; using Resgrid.Providers.Bus.Models; using Newtonsoft.Json; +using static System.Runtime.InteropServices.JavaScript.JSType; +using String = System.String; namespace Resgrid.Providers.Bus { @@ -99,7 +101,8 @@ public async Task RegisterPush(PushUri pushUri) { try { - var result = await hubClient.CreateFcmNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray()); + //var result = await hubClient.CreateFcmNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray()); + var result = await hubClient.CreateFcmV1NativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray()); } catch (Exception ex) { @@ -311,7 +314,8 @@ public async Task SendAndroidNotification(string title channel = "chats"; androidNotification = CreateAndroidNotification(title, subTitle, eventCode, type, count, color, channel); - var androidOutcome = await hubClient.SendFcmNativeNotificationAsync(androidNotification, string.Format("userId:{0}", userId)); + //var androidOutcome = await hubClient.SendFcmNativeNotificationAsync(androidNotification, string.Format("userId:{0}", userId)); + var androidOutcome = await hubClient.SendFcmV1NativeNotificationAsync(androidNotification, string.Format("userId:{0}", userId)); return androidOutcome.State; } @@ -506,27 +510,35 @@ private string CreateAndroidNotification(string title, string subTitle, string e dynamic pushNotification = new JObject(); - pushNotification.notification = new JObject(); - pushNotification.notification.title = title; - pushNotification.notification.body = subTitle; - pushNotification.notification.android_channel_id = type; + pushNotification.message = new JObject(); + pushNotification.message.notification = new JObject(); + pushNotification.message.notification.title = title; + pushNotification.message.notification.body = subTitle; + //pushNotification.notification.android_channel_id = type; - pushNotification.android = new JObject(); - pushNotification.android.ttl = "86400"; - pushNotification.android.notification = new JObject(); + pushNotification.message.android = new JObject(); + + if (channel != null && channel == "calls") + pushNotification.message.android.priority = 1; + + //pushNotification.message.android.ttl = "86400"; + pushNotification.message.android.notification = new JObject(); //pushNotification.android.notification.color = color; - pushNotification.android.notification.channel_id = type; + pushNotification.message.android.notification.channel_id = type; //pushNotification.android.notification.sound = soundFilename; - pushNotification.android.notification.defaultSound = true; + pushNotification.message.android.notification.default_sound = true; if (channel != null && channel == "calls") - pushNotification.android.notification.priority = "high"; + { + pushNotification.message.android.notification.sticky = true; + pushNotification.message.android.notification.notification_priority = 5; + } - pushNotification.data = new JObject(); - pushNotification.data.title = title; - pushNotification.data.message = subTitle; - pushNotification.data.eventCode = eventCode; - pushNotification.data.type = type; + pushNotification.message.data = new JObject(); + pushNotification.message.data.title = title; + pushNotification.message.data.message = subTitle; + pushNotification.message.data.eventCode = eventCode; + pushNotification.message.data.type = type; //if (channel != null && channel == "calls") // pushNotification.data.priority = "high"; diff --git a/Providers/Resgrid.Providers.Bus/UnitNotificationProvider.cs b/Providers/Resgrid.Providers.Bus/UnitNotificationProvider.cs index c6865e05..dc2d21e6 100644 --- a/Providers/Resgrid.Providers.Bus/UnitNotificationProvider.cs +++ b/Providers/Resgrid.Providers.Bus/UnitNotificationProvider.cs @@ -9,6 +9,7 @@ using Newtonsoft.Json.Linq; using Resgrid.Providers.Bus.Models; using Newtonsoft.Json; +using static Resgrid.Framework.Testing.TestData; namespace Resgrid.Providers.Bus { @@ -82,7 +83,8 @@ public async Task RegisterPush(PushUri pushUri) { try { - var result = await hubClient.CreateFcmNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray()); + //var result = await hubClient.CreateFcmNativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray()); + var result = await hubClient.CreateFcmV1NativeRegistrationAsync(pushUri.DeviceId, tagsWithHashedDeviceId.ToArray()); } catch (ArgumentException ex) { @@ -308,7 +310,8 @@ public async Task SendAndroidNotification(string title var hubClient = NotificationHubClient.CreateClientFromConnectionString(Config.ServiceBusConfig.AzureUnitNotificationHub_FullConnectionString, Config.ServiceBusConfig.AzureUnitNotificationHub_PushUrl); string androidNotification = CreateAndroidNotification(subTitle, title, eventCode, type, count, color, "calls"); - var androidOutcome = await hubClient.SendFcmNativeNotificationAsync(androidNotification, string.Format("unitId:{0}", unitId)); + //var androidOutcome = await hubClient.SendFcmNativeNotificationAsync(androidNotification, string.Format("unitId:{0}", unitId)); + var androidOutcome = await hubClient.SendFcmV1NativeNotificationAsync(androidNotification, string.Format("unitId:{0}", unitId)); return androidOutcome.State; } @@ -480,28 +483,36 @@ private string CreateAndroidNotification(string title, string subTitle, string e dynamic pushNotification = new JObject(); - pushNotification.notification = new JObject(); - pushNotification.notification.title = title; - pushNotification.notification.body = subTitle; - pushNotification.notification.android_channel_id = type; + pushNotification.message = new JObject(); + pushNotification.message.notification = new JObject(); + pushNotification.message.notification.title = title; + pushNotification.message.notification.body = subTitle; + //pushNotification.notification.android_channel_id = type; - pushNotification.android = new JObject(); - pushNotification.android.ttl = "86400"; - pushNotification.android.notification = new JObject(); + pushNotification.message.android = new JObject(); + + if (channel != null && channel == "calls") + pushNotification.message.android.priority = 1; + + //pushNotification.message.android.ttl = "86400"; + pushNotification.message.android.notification = new JObject(); //pushNotification.android.notification.color = color; - pushNotification.android.notification.channel_id = type; + pushNotification.message.android.notification.channel_id = type; //pushNotification.android.notification.sound = soundFilename; - pushNotification.android.notification.defaultSound = true; + pushNotification.message.android.notification.default_sound = true; if (channel != null && channel == "calls") - pushNotification.android.notification.priority = "high"; - - pushNotification.data = new JObject(); - pushNotification.data.title = title; - pushNotification.data.message = subTitle; - pushNotification.data.notId = eventCode; - pushNotification.data.eventCode = eventCode; - pushNotification.data.type = type; + { + pushNotification.message.android.notification.sticky = true; + pushNotification.message.android.notification.notification_priority = 5; + } + + pushNotification.message.data = new JObject(); + pushNotification.message.data.title = title; + pushNotification.message.data.message = subTitle; + pushNotification.message.data.notId = eventCode; + pushNotification.message.data.eventCode = eventCode; + pushNotification.message.data.type = type; return pushNotification.ToString(); } diff --git a/Web/Resgrid.Web.ServicesCore/Controllers/v4/PersonnelController.cs b/Web/Resgrid.Web.ServicesCore/Controllers/v4/PersonnelController.cs index a11b13bc..4382abd9 100644 --- a/Web/Resgrid.Web.ServicesCore/Controllers/v4/PersonnelController.cs +++ b/Web/Resgrid.Web.ServicesCore/Controllers/v4/PersonnelController.cs @@ -96,6 +96,13 @@ public async Task> GetPersonnelInfo(string use if (department.DepartmentId != DepartmentId) return Unauthorized(); + if (!await _authorizationService.CanUserViewPersonViaMatrixAsync(user.UserId, UserId, DepartmentId)) + { + ResponseHelper.PopulateV4ResponseNotFound(result); + + return result; + } + var profile = await _userProfileService.GetProfileByUserIdAsync(user.UserId); var group = await _departmentGroupsService.GetGroupForUserAsync(user.UserId, DepartmentId); var roles = await _personnelRolesService.GetRolesForUserAsync(user.UserId, DepartmentId); diff --git a/Web/Resgrid.Web.ServicesCore/Controllers/v4/UnitsController.cs b/Web/Resgrid.Web.ServicesCore/Controllers/v4/UnitsController.cs index 5145244a..49916e80 100644 --- a/Web/Resgrid.Web.ServicesCore/Controllers/v4/UnitsController.cs +++ b/Web/Resgrid.Web.ServicesCore/Controllers/v4/UnitsController.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System; using System.Web; +using SharpKml.Dom; namespace Resgrid.Web.Services.Controllers.v4 { @@ -62,6 +63,9 @@ public async Task> GetAllUnits() foreach (var unit in units) { + if (!await _authorizationService.CanUserViewUnitViaMatrixAsync(unit.UnitId, UserId, DepartmentId)) + continue; + UnitType type = null; if (types != null && types.Any()) @@ -113,6 +117,9 @@ public async Task> GetAllUnitsInfos(string activeF foreach (var unit in units) { + if (!await _authorizationService.CanUserViewUnitViaMatrixAsync(unit.UnitId, UserId, DepartmentId)) + continue; + UnitType type = null; if (types != null && types.Any()) @@ -203,7 +210,7 @@ public async Task> GetUnitsFilterOptio return Ok(result); } - public static UnitResultData ConvertUnitsData(Unit unit, UnitState state, UnitType type, string timeZone) + public static UnitResultData ConvertUnitsData(Model.Unit unit, UnitState state, UnitType type, string timeZone) { var data = new UnitResultData(); data.UnitId = unit.UnitId.ToString(); @@ -250,7 +257,7 @@ public static UnitResultData ConvertUnitsData(Unit unit, UnitState state, UnitTy return data; } - public static UnitsInfoResultData ConvertUnitsInfoResultData(Unit unit, UnitState state, CustomStateDetail customState, UnitType type, string timeZone, + public static UnitsInfoResultData ConvertUnitsInfoResultData(Model.Unit unit, UnitState state, CustomStateDetail customState, UnitType type, string timeZone, bool canViewLocation, List activeRoles, List names) { var data = new UnitsInfoResultData(); diff --git a/Web/Resgrid.WebCore/Areas/User/Controllers/UnitsController.cs b/Web/Resgrid.WebCore/Areas/User/Controllers/UnitsController.cs index 1c9cbaa8..fa30d7d9 100644 --- a/Web/Resgrid.WebCore/Areas/User/Controllers/UnitsController.cs +++ b/Web/Resgrid.WebCore/Areas/User/Controllers/UnitsController.cs @@ -22,6 +22,7 @@ using Resgrid.WebCore.Areas.User.Models; using Resgrid.WebCore.Areas.User.Models.Personnel; using System.Web; +using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext; namespace Resgrid.Web.Areas.User.Controllers { @@ -68,13 +69,17 @@ public async Task Index() model.Department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId); model.CanUserAddUnit = await _limitsService.CanDepartmentAddNewUnit(DepartmentId); model.Groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId); - model.Units = await _unitsService.GetUnitsForDepartmentUnlimitedAsync(DepartmentId); + model.Units = new List(); + var units = await _unitsService.GetUnitsForDepartmentUnlimitedAsync(DepartmentId); model.States = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId); model.UnitStatuses = await _customStateService.GetAllActiveUnitStatesForDepartmentAsync(DepartmentId); model.UnitCustomStates = new Dictionary(); - foreach (var unit in model.Units) + foreach (var unit in units) { + if (!await _authorizationService.CanUserViewUnitViaMatrixAsync(unit.UnitId, UserId, DepartmentId)) + continue; + var type = await _unitsService.GetUnitTypeByNameAsync(DepartmentId, unit.Type); if (type != null && type.CustomStatesId.HasValue) { @@ -85,6 +90,8 @@ public async Task Index() model.UnitCustomStates.Add(unit.UnitId, customStates); } } + + model.Units.Add(unit); } if (model.Department.IsUserAnAdmin(UserId)) @@ -1052,6 +1059,9 @@ public async Task GetUnitsList() foreach (var unit in units) { + if (!await _authorizationService.CanUserViewUnitViaMatrixAsync(unit.UnitId, UserId, DepartmentId)) + continue; + var unitJson = new UnitForListJson(); unitJson.Name = unit.Name; unitJson.Type = unit.Type; diff --git a/Web/Resgrid.WebCore/Areas/User/Views/Security/Index.cshtml b/Web/Resgrid.WebCore/Areas/User/Views/Security/Index.cshtml index bfac4bab..d56ae76c 100644 --- a/Web/Resgrid.WebCore/Areas/User/Views/Security/Index.cshtml +++ b/Web/Resgrid.WebCore/Areas/User/Views/Security/Index.cshtml @@ -424,7 +424,7 @@ - Who can view groups and units + Who can view units By default all users can see all units in the system. This option allows you to limit who can units in the system.