Merge pull request #416 from immense/feature/device-group-api

Added Get route for device groups
This commit is contained in:
dkattan 2021-12-15 06:04:56 -06:00 committed by GitHub
commit c3e80e6635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<RemotelyUser> userManager,
public OrganizationManagementController(IDataService dataService,
UserManager<RemotelyUser> 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 NotFound("Unable to find User or organizationID for device group");
}
[HttpDelete("DeviceGroup")]
[ServiceFilter(typeof(ApiAuthorizationFilter))]
public IActionResult DeviceGroup([FromBody] string deviceGroupID)