2024-07-04 11:02:45 +05:00
|
|
|
|
using System;
|
2024-03-13 16:49:28 +05:00
|
|
|
|
using System.Collections.Concurrent;
|
2021-12-11 16:47:28 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudWebApi;
|
|
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
|
|
|
|
public class PermissionAttribute : Attribute
|
2021-12-11 16:47:28 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
public static ConcurrentBag<string> Registered { get; } = new();
|
2021-12-11 16:47:28 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
public string Name { get; set; } = null!;
|
2021-12-11 16:47:28 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Проверка наличия у пользователя разрешения с именем "{ControllerName}.{http_method}".
|
|
|
|
|
/// Пример автоматической генерации имени: "Message.get", где "Message" - имя контроллера MessageController.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public PermissionAttribute() { }
|
2022-01-13 17:08:07 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Проверка наличия у пользователя указанного разрешения.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">Имя разрешения (default = ControllerName.http_method)</param>
|
|
|
|
|
public PermissionAttribute(string name)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Registered.Add(name);
|
2021-12-11 16:47:28 +05:00
|
|
|
|
}
|
|
|
|
|
}
|