From 6176d966c0da63375516b674eeeb440e588a8f52 Mon Sep 17 00:00:00 2001 From: dkattan <1424395+dkattan@users.noreply.github.com> Date: Fri, 3 Dec 2021 14:05:33 -0600 Subject: [PATCH 1/2] Added Get route for device groups --- .../API/OrganizationManagementController.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Server/API/OrganizationManagementController.cs b/Server/API/OrganizationManagementController.cs index b4d36686..a8ef1ace 100644 --- a/Server/API/OrganizationManagementController.cs +++ b/Server/API/OrganizationManagementController.cs @@ -1,6 +1,8 @@ -using Microsoft.AspNetCore.Identity; +using MailKit; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.WebUtilities; +using Org.BouncyCastle.Crypto.Agreement; using Remotely.Server.Auth; using Remotely.Server.Services; using Remotely.Shared.Models; @@ -17,8 +19,8 @@ namespace Remotely.Server.API [ApiController] public class OrganizationManagementController : ControllerBase { - public OrganizationManagementController(IDataService dataService, - UserManager userManager, + public OrganizationManagementController(IDataService dataService, + UserManager userManager, IEmailSenderEx emailSender) { DataService = dataService; @@ -89,6 +91,20 @@ namespace Remotely.Server.API return Ok("ok"); } + [HttpGet("DeviceGroup")] + [ServiceFilter(typeof(ApiAuthorizationFilter))] + public IActionResult DeviceGroup() + { + if (User.Identity.IsAuthenticated && + DataService.GetUserByNameWithOrg(User.Identity.Name).IsAdministrator) + { + return Ok(DataService.GetDeviceGroups(User.Identity.Name)); + } + if (Request.Headers.TryGetValue("OrganizationID", out var orgID)) + return Ok(DataService.GetDeviceGroupsForOrganization(orgID)); + return BadRequest("Unable to find User or organizationID for device group"); + } + [HttpDelete("DeviceGroup")] [ServiceFilter(typeof(ApiAuthorizationFilter))] public IActionResult DeviceGroup([FromBody] string deviceGroupID) From 846e5415b708cacec1add0ef897a6bc833af2b10 Mon Sep 17 00:00:00 2001 From: Steve Sobol Date: Tue, 14 Dec 2021 17:28:20 -0800 Subject: [PATCH 2/2] DeviceGroup(): return NotFound, instead of BadRequest --- Server/API/OrganizationManagementController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/API/OrganizationManagementController.cs b/Server/API/OrganizationManagementController.cs index a8ef1ace..c11e598e 100644 --- a/Server/API/OrganizationManagementController.cs +++ b/Server/API/OrganizationManagementController.cs @@ -102,7 +102,7 @@ namespace Remotely.Server.API } if (Request.Headers.TryGetValue("OrganizationID", out var orgID)) return Ok(DataService.GetDeviceGroupsForOrganization(orgID)); - return BadRequest("Unable to find User or organizationID for device group"); + return NotFound("Unable to find User or organizationID for device group"); } [HttpDelete("DeviceGroup")]