Files
mixtape/zero.Web/Controllers/UsersController.cs
T

54 lines
1.3 KiB
C#
Raw Normal View History

2020-04-17 15:32:33 +02:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
2020-04-17 15:32:33 +02:00
using System.Threading.Tasks;
using zero.Core;
using zero.Core.Api;
using zero.Core.Entities;
using zero.Core.Identity;
using zero.Web.Mapper;
using zero.Web.Models;
namespace zero.Web.Controllers
{
[ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Read)]
public class UsersController : BackofficeController
{
private IUserApi Api { get; set; }
private ZeroOptions Options { get; set; }
public UsersController(IZeroConfiguration config, IUserApi api, IMapper mapper, IToken token, IOptionsMonitor<ZeroOptions> options) : base(config, mapper, token)
2020-04-17 15:32:33 +02:00
{
Api = api;
Options = options.CurrentValue;
2020-04-17 15:32:33 +02:00
}
/// <summary>
/// Get user by id
/// </summary>
public async Task<IActionResult> GetById([FromQuery] string id)
{
2020-04-24 12:46:25 +02:00
return As<User, UserEditModel>(await Api.GetUserById(id));
2020-04-17 15:32:33 +02:00
}
/// <summary>
/// Get all users
/// </summary>
public async Task<IActionResult> GetAll([FromQuery] ListQuery<User> query)
{
2020-04-24 12:46:25 +02:00
return As<User, UserListModel>(await Api.GetByQuery(query, "zero.applications.1-A"));
2020-04-17 15:32:33 +02:00
}
/// <summary>
/// Get all permissions for selection
/// </summary>
public IActionResult GetAllPermissions()
{
return Json(Options.Authorization.Permissions);
}
2020-04-17 15:32:33 +02:00
}
}