Initial ...
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using xCommons.Attributes;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityHelper;
|
||||
using xModels.Dtos;
|
||||
using static IdentityServer4.IdentityServerConstants;
|
||||
|
||||
namespace xIds.Controllers
|
||||
{
|
||||
public partial class AccountController
|
||||
{
|
||||
/// <summary>
|
||||
/// Query Users
|
||||
/// for specifiy users role for query user 'role: string' and 'forceRole: boolean' in header
|
||||
/// </summary>
|
||||
/// <param name="query">how to filter results based on <see>XQuery</see> structure</param>
|
||||
/// <param name="role">an string which represent user role</param>
|
||||
/// <param name="forceRole">if it's true the user must has exact role, otherwise top level users also listed</param>
|
||||
/// <returns>an instance of <see>XQueryResult</see> of <see>XUserProfileDto</see></returns>
|
||||
[RequireXPowered]
|
||||
[HttpGet("Users/Query")]
|
||||
[Authorize(Policy = LocalApi.PolicyName)]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public async Task<ActionResult<XQueryResult<string>>> QueryUsers(
|
||||
[FromQuery] XQuery query,
|
||||
[FromHeader] string role,
|
||||
[FromHeader] bool forceRole = false
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do Actions ...
|
||||
try
|
||||
{
|
||||
//
|
||||
// Retrieve User Info ...
|
||||
var userInfo = await GetUserInfo();
|
||||
|
||||
//
|
||||
// Retrieve Result Based on Provided Query ...
|
||||
var result = await IdentityManager.QueryUsers(
|
||||
role: role,
|
||||
query: query,
|
||||
forceRole: forceRole,
|
||||
requestedUserSelectByParam: userInfo.UserId
|
||||
);
|
||||
|
||||
//
|
||||
// Return result ...
|
||||
return Ok(result
|
||||
.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var exception = GetExceptionActionResult(ex);
|
||||
return exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user