69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Sockeye.Models;
|
|
using Sockeye.Api.ControllerHelpers;
|
|
using Sockeye.Biz;
|
|
|
|
|
|
namespace Sockeye.Api.Controllers
|
|
{
|
|
|
|
/// <summary>
|
|
/// Enum pick list controller
|
|
/// </summary>
|
|
[ApiController]
|
|
[ApiVersion("8.0")]
|
|
[Route("api/v{version:apiVersion}/authorization-roles")]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
public class AuthorizationRolesController : ControllerBase
|
|
{
|
|
private readonly AyContext ct;
|
|
private readonly ILogger<AuthorizationRolesController> log;
|
|
private readonly ApiServerState serverState;
|
|
|
|
|
|
/// <summary>
|
|
/// ctor
|
|
/// </summary>
|
|
/// <param name="dbcontext"></param>
|
|
/// <param name="logger"></param>
|
|
/// <param name="apiServerState"></param>
|
|
public AuthorizationRolesController(AyContext dbcontext, ILogger<AuthorizationRolesController> logger, ApiServerState apiServerState)
|
|
{
|
|
ct = dbcontext;
|
|
log = logger;
|
|
serverState = apiServerState;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get roles
|
|
/// </summary>
|
|
/// <param name="AsJson">Return as compact JSON format</param>
|
|
/// <returns>Dictionary list of Sockeye object types and their authorization role rights in Sockeye</returns>
|
|
[HttpGet("list")]
|
|
public ActionResult GetRoles([FromQuery] bool AsJson = false)
|
|
{
|
|
if (!serverState.IsOpen)
|
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
|
|
|
//as json for client end of things
|
|
if (AsJson)
|
|
return Ok(ApiOkResponse.Response(Newtonsoft.Json.JsonConvert.SerializeObject(BizRoles.roles, Newtonsoft.Json.Formatting.None)));
|
|
else
|
|
return Ok(ApiOkResponse.Response(BizRoles.roles));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}//eoc
|
|
}//ens |