DD.WellWorkover.Cloud/AsbCloudWebApi/PermissionAttribute.cs
2024-08-19 10:01:07 +05:00

29 lines
1.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Concurrent;
namespace AsbCloudWebApi;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class PermissionAttribute : Attribute
{
public static ConcurrentBag<string> Registered { get; } = new();
public string Name { get; set; } = null!;
/// <summary>
/// Проверка наличия у пользователя разрешения с именем "{ControllerName}.{http_method}".
/// Пример автоматической генерации имени: "Message.get", где "Message" - имя контроллера MessageController.
/// </summary>
public PermissionAttribute() { }
/// <summary>
/// Проверка наличия у пользователя указанного разрешения.
/// </summary>
/// <param name="name">Имя разрешения (default = ControllerName.http_method)</param>
public PermissionAttribute(string name)
{
Name = name;
Registered.Add(name);
}
}