using AsbCloudApp.Data; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Routing; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace AsbCloudWebApi.Controllers { [Route("api/admin/permission")] [ApiController] [Authorize] public class AdminPermissionController : CrudController> { public AdminPermissionController(ICrudService service) :base(service) {} [HttpGet("Autogenerated")] public IActionResult GetAutogenerated() { var controllers = Assembly.GetExecutingAssembly().GetTypes(). Where(type => typeof(ControllerBase).IsAssignableFrom(type) && !type.IsAbstract) .ToList(); var permissions = new SortedSet(); foreach (var controller in controllers) { var methods = controller.GetMethods().Where(m => m.IsPublic); var controllerName = controller.Name.Replace("Controller", ""); foreach (var method in methods) { var httpMethod = method.GetCustomAttribute()?.HttpMethods?.First(); if (string.IsNullOrEmpty(httpMethod)) continue; permissions.Add($"{controllerName}.{httpMethod.ToLower()}"); } } return Ok(permissions); } } }